anishka commited on
Commit
7267d3c
·
verified ·
1 Parent(s): 7351468

Upload UD_Treebank_Te_Transliterate.py

Browse files
Files changed (1) hide show
  1. UD_Treebank_Te_Transliterate.py +125 -0
UD_Treebank_Te_Transliterate.py ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Loading script for the Ancora NER dataset.
2
+ import datasets
3
+
4
+ logger = datasets.logging.get_logger(__name__)
5
+
6
+ _CITATION = """ """
7
+
8
+ _DESCRIPTION = """TELUGU dataset converted to Transliterate
9
+ """
10
+
11
+ _HOMEPAGE = """"""
12
+
13
+ _URL = "https://huggingface.co/datasets/anishka/UD_Treebank_Te_Transliterate/resolve/main/"
14
+
15
+
16
+ _TRAINING_FILE = "te_tr_mtg-ud-train.conllu"
17
+ _DEV_FILE = "te_tr_mtg-ud-dev.conllu"
18
+ _TEST_FILE = "te_tr_mtg-ud-test.conllu"
19
+
20
+ class AncoraCaNerConfig(datasets.BuilderConfig):
21
+ """ Builder config for the Ancora Ca NER dataset """
22
+
23
+ def __init__(self, **kwargs):
24
+ """BuilderConfig for AncoraCaNer.
25
+ Args:
26
+ **kwargs: keyword arguments forwarded to super.
27
+ """
28
+ super(AncoraCaNerConfig, self).__init__(**kwargs)
29
+
30
+
31
+ class AncoraCaNer(datasets.GeneratorBasedBuilder):
32
+ """ AncoraCaNer dataset."""
33
+
34
+ BUILDER_CONFIGS = [
35
+ AncoraCaNerConfig(
36
+ name="AncoraCaNer",
37
+ version=datasets.Version("2.0.0"),
38
+ description="AncoraCaNer dataset"
39
+ ),
40
+ ]
41
+
42
+ def _info(self):
43
+ return datasets.DatasetInfo(
44
+ description=_DESCRIPTION,
45
+ features=datasets.Features(
46
+ {
47
+ "idx": datasets.Value("string"),
48
+ "text": datasets.Sequence(datasets.Value("string")),
49
+ "upos": datasets.Sequence(
50
+ datasets.features.ClassLabel(
51
+ names=[
52
+ "NOUN",
53
+ "PUNCT",
54
+ "ADP",
55
+ "NUM",
56
+ "SYM",
57
+ "SCONJ",
58
+ "ADJ",
59
+ "PART",
60
+ "DET",
61
+ "CCONJ",
62
+ "PROPN",
63
+ "PRON",
64
+ "X",
65
+ "_",
66
+ "ADV",
67
+ "INTJ",
68
+ "VERB",
69
+ "AUX",
70
+ ]
71
+ )
72
+ ),
73
+ "xpos": datasets.Sequence(datasets.Value("string")),
74
+ }
75
+ ),
76
+ supervised_keys=None,
77
+ homepage=_HOMEPAGE,
78
+ citation=_CITATION,
79
+ )
80
+
81
+ def _split_generators(self, dl_manager):
82
+ """Returns SplitGenerators."""
83
+ urls_to_download = {
84
+ "train": f"{_URL}{_TRAINING_FILE}",
85
+ "dev": f"{_URL}{_DEV_FILE}",
86
+ "test": f"{_URL}{_TEST_FILE}",
87
+ }
88
+ downloaded_files = dl_manager.download_and_extract(urls_to_download)
89
+
90
+ return [
91
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
92
+ datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"]}),
93
+ datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}),
94
+ ]
95
+
96
+ def _generate_examples(self, filepath):
97
+ logger.info("⏳ Generating examples from = %s", filepath)
98
+ with open(filepath, encoding="utf-8") as f:
99
+ guid = 0
100
+ tokens = []
101
+ pos_tags = []
102
+ for line in f:
103
+ if line.startswith("-DOCSTART-") or line == "" or line == "\n" or line.startswith("#"):
104
+ if tokens:
105
+ yield guid, {
106
+ "idx": str(guid),
107
+ "text": tokens,
108
+ "upos": pos_tags,
109
+ "xpos": pos_tags,
110
+ }
111
+ guid += 1
112
+ tokens = []
113
+ pos_tags = []
114
+ else:
115
+ # AncoraCaNer tokens are space separated
116
+ splits = line.split('\t')
117
+ tokens.append(splits[1])
118
+ pos_tags.append(splits[3].rstrip())
119
+ # last example
120
+ yield guid, {
121
+ "idx": str(guid),
122
+ "text": tokens,
123
+ "upos": pos_tags,
124
+ "xpos": pos_tags,
125
+ }