Aakanksha Naik
commited on
Commit
•
81bd2e2
1
Parent(s):
40a3a16
Adding dataset loading script
Browse files
README.md
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
POS tagging on the Universal Dependencies dataset
|
udpos.py
ADDED
@@ -0,0 +1,160 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
|
2 |
+
#
|
3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
+
# you may not use this file except in compliance with the License.
|
5 |
+
# You may obtain a copy of the License at
|
6 |
+
#
|
7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
#
|
9 |
+
# Unless required by applicable law or agreed to in writing, software
|
10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
+
# See the License for the specific language governing permissions and
|
13 |
+
# limitations under the License.
|
14 |
+
# TODO: Address all TODOs and remove all explanatory comments
|
15 |
+
"""Script to load the Universal Dependencies dataset for POS tagging in prompting format"""
|
16 |
+
|
17 |
+
|
18 |
+
import csv
|
19 |
+
import json
|
20 |
+
import os
|
21 |
+
|
22 |
+
import datasets
|
23 |
+
|
24 |
+
# Find for instance the citation on arxiv or on the dataset repo/website
|
25 |
+
_CITATION = """\
|
26 |
+
@inproceedings{nivre-etal-2020-universal,
|
27 |
+
title = "{U}niversal {D}ependencies v2: An Evergrowing Multilingual Treebank Collection",
|
28 |
+
author = "Nivre, Joakim and
|
29 |
+
de Marneffe, Marie-Catherine and
|
30 |
+
Ginter, Filip and
|
31 |
+
Haji{\v{c}}, Jan and
|
32 |
+
Manning, Christopher D. and
|
33 |
+
Pyysalo, Sampo and
|
34 |
+
Schuster, Sebastian and
|
35 |
+
Tyers, Francis and
|
36 |
+
Zeman, Daniel",
|
37 |
+
booktitle = "Proceedings of the 12th Language Resources and Evaluation Conference",
|
38 |
+
month = may,
|
39 |
+
year = "2020",
|
40 |
+
address = "Marseille, France",
|
41 |
+
publisher = "European Language Resources Association",
|
42 |
+
url = "https://aclanthology.org/2020.lrec-1.497",
|
43 |
+
pages = "4034--4043",
|
44 |
+
abstract = "Universal Dependencies is an open community effort to create cross-linguistically consistent treebank annotation for many languages within a dependency-based lexicalist framework. The annotation consists in a linguistically motivated word segmentation; a morphological layer comprising lemmas, universal part-of-speech tags, and standardized morphological features; and a syntactic layer focusing on syntactic relations between predicates, arguments and modifiers. In this paper, we describe version 2 of the universal guidelines (UD v2), discuss the major changes from UD v1 to UD v2, and give an overview of the currently available treebanks for 90 languages.",
|
45 |
+
language = "English",
|
46 |
+
ISBN = "979-10-95546-34-4",
|
47 |
+
}
|
48 |
+
"""
|
49 |
+
|
50 |
+
# You can copy an official description
|
51 |
+
_DESCRIPTION = """\
|
52 |
+
Universal Dependencies is an open community effort to create cross-linguistically consistent treebank annotation for many languages within a dependency-based lexicalist framework. The annotation consists in a linguistically motivated word segmentation; a morphological layer comprising lemmas, universal part-of-speech tags, and standardized morphological features; and a syntactic layer focusing on syntactic relations between predicates, arguments and modifiers.
|
53 |
+
"""
|
54 |
+
|
55 |
+
_HOMEPAGE = "https://universaldependencies.org"
|
56 |
+
|
57 |
+
_LICENSE = ""
|
58 |
+
|
59 |
+
# The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
|
60 |
+
# This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
|
61 |
+
_LANGS = ['pt-pud', 'de-gsd', 'zh-gsdsimp', 'hu-szeged', 'ko-gsd', 'af-afribooms', 'tr-imst', 'it-partut', 'it-vit', 'pl-pud', 'ar-pud', 'kk-ktb', 'fr-pud', 'it-postwita', 'ro-simonero', 'pl-pdb', 'en-partut', 'th-pud', 'ro-nonstandard', 'hi-hdtb', 'eu-bdt', 'te-mtg', 'en-pud', 'hi-pud', 'ja-pud', 'wo-wtb', 'fi-pud', 'nl-alpino', 'ru-gsd', 'fr-sequoia', 'fr-partut', 'fi-tdt', 'ro-rrt', 'ur-udtb', 'ko-kaist', 'pt-bosque', 'it-twittiro', 'ru-syntagrus', 'fa-seraji', 'it-isdt', 'he-htb', 'lt-alksnis', 'nl-lassysmall', 'de-pud', 'uk-iu', 'zh-pud', 'es-pud', 'fr-gsd', 'ja-gsd', 'tr-gb', 'bg-btb', 'ta-ttb', 'pl-lfg', 'en-lines', 'yo-ytb', 'lt-hse', 'tl-trg', 'id-gsd', 'en-gum', 'vi-vtb', 'ko-pud', 'de-lit', 'ar-padt', 'en-ewt', 'ru-pud', 'pt-gsd', 'es-ancora', 'mr-ufal', 'zh-hk', 'ru-taiga', 'de-hdt', 'id-pud', 'en-pronouns', 'it-pud', 'es-gsd', 'fi-ftb', 'tr-pud', 'fr-fqb', 'zh-gsd', 'el-gdt', 'et-edt', 'fr-spoken', 'zh-cfl', 'et-ewt', 'ja-modern']
|
62 |
+
_URL = "https://huggingface.co/udpos/"
|
63 |
+
_URLS = {}
|
64 |
+
for lang in _LANGS:
|
65 |
+
_URLS[lang] = {
|
66 |
+
'train': _URL + lang + '-train.tsv'
|
67 |
+
'valid': _URL + lang + '-valid.tsv'
|
68 |
+
'test': _URL + lang + '-test.tsv'
|
69 |
+
}
|
70 |
+
|
71 |
+
class Udpos(datasets.GeneratorBasedBuilder):
|
72 |
+
"""POS Tagging on the Universal Dependencies dataset"""
|
73 |
+
|
74 |
+
VERSION = datasets.Version("1.1.0")
|
75 |
+
|
76 |
+
# This is an example of a dataset with multiple configurations.
|
77 |
+
# If you don't want/need to define several sub-sets in your dataset,
|
78 |
+
# just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
|
79 |
+
|
80 |
+
# If you need to make complex sub-parts in the datasets with configurable options
|
81 |
+
# You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
|
82 |
+
# BUILDER_CONFIG_CLASS = MyBuilderConfig
|
83 |
+
|
84 |
+
# You will be able to load one or the other configurations in the following list with
|
85 |
+
# data = datasets.load_dataset('my_dataset', 'first_domain')
|
86 |
+
# data = datasets.load_dataset('my_dataset', 'second_domain')
|
87 |
+
BUILDER_CONFIGS = []
|
88 |
+
for lang in _LANGS:
|
89 |
+
datasets.BuilderConfig(name=lang, version=VERSION, description="Split corresponding to language "+lang)
|
90 |
+
|
91 |
+
# DEFAULT_CONFIG_NAME = "first_domain" # It's not mandatory to have a default configuration. Just use one if it make sense.
|
92 |
+
|
93 |
+
def _info(self):
|
94 |
+
features = datasets.Features(
|
95 |
+
{
|
96 |
+
"sentence": datasets.Value("string"),
|
97 |
+
"tags": datasets.Value("string"),
|
98 |
+
}
|
99 |
+
)
|
100 |
+
return datasets.DatasetInfo(
|
101 |
+
# This is the description that will appear on the datasets page.
|
102 |
+
description=_DESCRIPTION,
|
103 |
+
# This defines the different columns of the dataset and their types
|
104 |
+
features=features, # Here we define them above because they are different between the two configurations
|
105 |
+
# If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
|
106 |
+
# specify them. They'll be used if as_supervised=True in builder.as_dataset.
|
107 |
+
supervised_keys=("sentence", "tags"),
|
108 |
+
# Homepage of the dataset for documentation
|
109 |
+
homepage=_HOMEPAGE,
|
110 |
+
# License for the dataset if available
|
111 |
+
license=_LICENSE,
|
112 |
+
# Citation for the dataset
|
113 |
+
citation=_CITATION,
|
114 |
+
)
|
115 |
+
|
116 |
+
def _split_generators(self, dl_manager):
|
117 |
+
# If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
|
118 |
+
|
119 |
+
# dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
|
120 |
+
# It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
|
121 |
+
# By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
|
122 |
+
urls = _URLS
|
123 |
+
data_dir = dl_manager.download_and_extract(urls)
|
124 |
+
return [
|
125 |
+
datasets.SplitGenerator(
|
126 |
+
name=datasets.Split.TRAIN,
|
127 |
+
# These kwargs will be passed to _generate_examples
|
128 |
+
gen_kwargs={
|
129 |
+
"filepath": os.path.join(data_dir, self.config.name+"-train.tsv"),
|
130 |
+
"split": "train",
|
131 |
+
},
|
132 |
+
),
|
133 |
+
datasets.SplitGenerator(
|
134 |
+
name=datasets.Split.TEST,
|
135 |
+
# These kwargs will be passed to _generate_examples
|
136 |
+
gen_kwargs={
|
137 |
+
"filepath": os.path.join(data_dir, self.config.name+"-test.tsv"),
|
138 |
+
"split": "test"
|
139 |
+
},
|
140 |
+
),
|
141 |
+
datasets.SplitGenerator(
|
142 |
+
name=datasets.Split.VALIDATION,
|
143 |
+
# These kwargs will be passed to _generate_examples
|
144 |
+
gen_kwargs={
|
145 |
+
"filepath": os.path.join(data_dir, self.config.name+"-dev.tsv"),
|
146 |
+
"split": "dev",
|
147 |
+
},
|
148 |
+
),
|
149 |
+
]
|
150 |
+
|
151 |
+
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
152 |
+
def _generate_examples(self, filepath, split):
|
153 |
+
# TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
|
154 |
+
# The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
|
155 |
+
with csv.reader(open(filepath, encoding="utf-8"), delimiter='\t') as f:
|
156 |
+
for key, row in enumerate(f):
|
157 |
+
yield key, {
|
158 |
+
"sentence": row[0],
|
159 |
+
"tags": row[1],
|
160 |
+
}
|