BillGeate parquet-converter commited on
Commit
3509189
·
0 Parent(s):

Duplicate from lst-nectec/lst20

Browse files

Co-authored-by: Parquet-converter (BOT) <parquet-converter@users.noreply.huggingface.co>

Files changed (3) hide show
  1. .gitattributes +27 -0
  2. README.md +301 -0
  3. lst20.py +197 -0
.gitattributes ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bin.* filter=lfs diff=lfs merge=lfs -text
5
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.model filter=lfs diff=lfs merge=lfs -text
12
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
13
+ *.onnx filter=lfs diff=lfs merge=lfs -text
14
+ *.ot filter=lfs diff=lfs merge=lfs -text
15
+ *.parquet filter=lfs diff=lfs merge=lfs -text
16
+ *.pb filter=lfs diff=lfs merge=lfs -text
17
+ *.pt filter=lfs diff=lfs merge=lfs -text
18
+ *.pth filter=lfs diff=lfs merge=lfs -text
19
+ *.rar filter=lfs diff=lfs merge=lfs -text
20
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
21
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
22
+ *.tflite filter=lfs diff=lfs merge=lfs -text
23
+ *.tgz filter=lfs diff=lfs merge=lfs -text
24
+ *.xz filter=lfs diff=lfs merge=lfs -text
25
+ *.zip filter=lfs diff=lfs merge=lfs -text
26
+ *.zstandard filter=lfs diff=lfs merge=lfs -text
27
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,301 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ annotations_creators:
3
+ - expert-generated
4
+ language_creators:
5
+ - found
6
+ language:
7
+ - th
8
+ license:
9
+ - other
10
+ multilinguality:
11
+ - monolingual
12
+ size_categories:
13
+ - 10K<n<100K
14
+ source_datasets:
15
+ - original
16
+ task_categories:
17
+ - token-classification
18
+ task_ids:
19
+ - named-entity-recognition
20
+ - part-of-speech
21
+ pretty_name: LST20
22
+ tags:
23
+ - word-segmentation
24
+ - clause-segmentation
25
+ - sentence-segmentation
26
+ dataset_info:
27
+ features:
28
+ - name: id
29
+ dtype: string
30
+ - name: fname
31
+ dtype: string
32
+ - name: tokens
33
+ sequence: string
34
+ - name: pos_tags
35
+ sequence:
36
+ class_label:
37
+ names:
38
+ '0': NN
39
+ '1': VV
40
+ '2': PU
41
+ '3': CC
42
+ '4': PS
43
+ '5': AX
44
+ '6': AV
45
+ '7': FX
46
+ '8': NU
47
+ '9': AJ
48
+ '10': CL
49
+ '11': PR
50
+ '12': NG
51
+ '13': PA
52
+ '14': XX
53
+ '15': IJ
54
+ - name: ner_tags
55
+ sequence:
56
+ class_label:
57
+ names:
58
+ '0': O
59
+ '1': B_BRN
60
+ '2': B_DES
61
+ '3': B_DTM
62
+ '4': B_LOC
63
+ '5': B_MEA
64
+ '6': B_NUM
65
+ '7': B_ORG
66
+ '8': B_PER
67
+ '9': B_TRM
68
+ '10': B_TTL
69
+ '11': I_BRN
70
+ '12': I_DES
71
+ '13': I_DTM
72
+ '14': I_LOC
73
+ '15': I_MEA
74
+ '16': I_NUM
75
+ '17': I_ORG
76
+ '18': I_PER
77
+ '19': I_TRM
78
+ '20': I_TTL
79
+ '21': E_BRN
80
+ '22': E_DES
81
+ '23': E_DTM
82
+ '24': E_LOC
83
+ '25': E_MEA
84
+ '26': E_NUM
85
+ '27': E_ORG
86
+ '28': E_PER
87
+ '29': E_TRM
88
+ '30': E_TTL
89
+ - name: clause_tags
90
+ sequence:
91
+ class_label:
92
+ names:
93
+ '0': O
94
+ '1': B_CLS
95
+ '2': I_CLS
96
+ '3': E_CLS
97
+ config_name: lst20
98
+ splits:
99
+ - name: train
100
+ num_bytes: 107725145
101
+ num_examples: 63310
102
+ - name: validation
103
+ num_bytes: 9646167
104
+ num_examples: 5620
105
+ - name: test
106
+ num_bytes: 8217425
107
+ num_examples: 5250
108
+ download_size: 0
109
+ dataset_size: 125588737
110
+ ---
111
+
112
+ # Dataset Card for LST20
113
+
114
+ ## Table of Contents
115
+ - [Dataset Description](#dataset-description)
116
+ - [Dataset Summary](#dataset-summary)
117
+ - [Supported Tasks and Leaderboards](#supported-tasks-and-leaderboards)
118
+ - [Languages](#languages)
119
+ - [Dataset Structure](#dataset-structure)
120
+ - [Data Instances](#data-instances)
121
+ - [Data Fields](#data-fields)
122
+ - [Data Splits](#data-splits)
123
+ - [Dataset Creation](#dataset-creation)
124
+ - [Curation Rationale](#curation-rationale)
125
+ - [Source Data](#source-data)
126
+ - [Annotations](#annotations)
127
+ - [Personal and Sensitive Information](#personal-and-sensitive-information)
128
+ - [Considerations for Using the Data](#considerations-for-using-the-data)
129
+ - [Social Impact of Dataset](#social-impact-of-dataset)
130
+ - [Discussion of Biases](#discussion-of-biases)
131
+ - [Other Known Limitations](#other-known-limitations)
132
+ - [Additional Information](#additional-information)
133
+ - [Dataset Curators](#dataset-curators)
134
+ - [Licensing Information](#licensing-information)
135
+ - [Citation Information](#citation-information)
136
+ - [Contributions](#contributions)
137
+
138
+ ## Dataset Description
139
+
140
+ - **Homepage:** https://aiforthai.in.th/
141
+ - **Repository:**
142
+ - **Paper:**
143
+ - **Leaderboard:**
144
+ - **Point of Contact:** [email](thepchai@nectec.or.th)
145
+
146
+ ### Dataset Summary
147
+
148
+ LST20 Corpus is a dataset for Thai language processing developed by National Electronics and Computer Technology Center (NECTEC), Thailand.
149
+ It offers five layers of linguistic annotation: word boundaries, POS tagging, named entities, clause boundaries, and sentence boundaries.
150
+ At a large scale, it consists of 3,164,002 words, 288,020 named entities, 248,181 clauses, and 74,180 sentences, while it is annotated with
151
+ 16 distinct POS tags. All 3,745 documents are also annotated with one of 15 news genres. Regarding its sheer size, this dataset is
152
+ considered large enough for developing joint neural models for NLP.
153
+ Manually download at https://aiforthai.in.th/corpus.php
154
+ See `LST20 Annotation Guideline.pdf` and `LST20 Brief Specification.pdf` within the downloaded `AIFORTHAI-LST20Corpus.tar.gz` for more details.
155
+
156
+ ### Supported Tasks and Leaderboards
157
+
158
+ - POS tagging
159
+ - NER tagging
160
+ - clause segmentation
161
+ - sentence segmentation
162
+ - word tokenization
163
+
164
+ ### Languages
165
+
166
+ Thai
167
+
168
+ ## Dataset Structure
169
+
170
+ ### Data Instances
171
+
172
+ ```
173
+ {'clause_tags': [1, 2, 2, 2, 2, 2, 2, 2, 3], 'fname': 'T11964.txt', 'id': '0', 'ner_tags': [8, 0, 0, 0, 0, 0, 0, 0, 25], 'pos_tags': [0, 0, 0, 1, 0, 8, 8, 8, 0], 'tokens': ['ธรรมนูญ', 'แชมป์', 'สิงห์คลาสสิก', 'กวาด', 'รางวัล', 'แสน', 'สี่', 'หมื่น', 'บาท']}
174
+ {'clause_tags': [1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3], 'fname': 'T11964.txt', 'id': '1', 'ner_tags': [8, 18, 28, 0, 0, 0, 0, 6, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 15, 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 6], 'pos_tags': [0, 2, 0, 2, 1, 1, 2, 8, 2, 10, 2, 8, 2, 1, 0, 1, 0, 4, 7, 1, 0, 2, 8, 2, 10, 1, 10, 4, 2, 8, 2, 4, 0, 4, 0, 2, 8, 2, 10, 2, 8], 'tokens': ['ธรรมนูญ', '_', 'ศรีโรจน์', '_', 'เก็บ', 'เพิ่ม', '_', '4', '_', 'อันเดอร์พาร์', '_', '68', '_', 'เข้า', 'ป้าย', 'รับ', 'แชมป์', 'ใน', 'การ', 'เล่น', 'อาชีพ', '_', '19', '_', 'ปี', 'เป็น', 'ครั้ง', 'ที่', '_', '8', '_', 'ใน', 'ชีวิต', 'ด้วย', 'สกอร์', '_', '18', '_', 'อันเดอร์พาร์', '_', '270']}
175
+ ```
176
+
177
+ ### Data Fields
178
+
179
+ - `id`: nth sentence in each set, starting at 0
180
+ - `fname`: text file from which the sentence comes from
181
+ - `tokens`: word tokens
182
+ - `pos_tags`: POS tags
183
+ - `ner_tags`: NER tags
184
+ - `clause_tags`: clause tags
185
+
186
+ ### Data Splits
187
+
188
+ | | train | eval | test | all |
189
+ |----------------------|-----------|-------------|-------------|-----------|
190
+ | words | 2,714,848 | 240,891 | 207,295 | 3,163,034 |
191
+ | named entities | 246,529 | 23,176 | 18,315 | 288,020 |
192
+ | clauses | 214,645 | 17,486 | 16,050 | 246,181 |
193
+ | sentences | 63,310 | 5,620 | 5,250 | 74,180 |
194
+ | distinct words | 42,091 | (oov) 2,595 | (oov) 2,006 | 46,692 |
195
+ | breaking spaces※ | 63,310 | 5,620 | 5,250 | 74,180 |
196
+ | non-breaking spaces※※| 402,380 | 39,920 | 32,204 | 475,504 |
197
+
198
+ ※ Breaking space = space that is used as a sentence boundary marker
199
+ ※※ Non-breaking space = space that is not used as a sentence boundary marker
200
+
201
+ ## Dataset Creation
202
+
203
+ ### Curation Rationale
204
+
205
+ [More Information Needed]
206
+
207
+ ### Source Data
208
+
209
+ #### Initial Data Collection and Normalization
210
+
211
+ [More Information Needed]
212
+
213
+ #### Who are the source language producers?
214
+
215
+ Respective authors of the news articles
216
+
217
+ ### Annotations
218
+
219
+ #### Annotation process
220
+
221
+ Detailed annotation guideline can be found in `LST20 Annotation Guideline.pdf`.
222
+
223
+ #### Who are the annotators?
224
+
225
+ [More Information Needed]
226
+
227
+ ### Personal and Sensitive Information
228
+
229
+ All texts are from public news. No personal and sensitive information is expected to be included.
230
+
231
+ ## Considerations for Using the Data
232
+
233
+ ### Social Impact of Dataset
234
+
235
+ - Large-scale Thai NER & POS tagging, clause & sentence segmentatation, word tokenization
236
+
237
+ ### Discussion of Biases
238
+
239
+ - All 3,745 texts are from news domain:
240
+ - politics: 841
241
+ - crime and accident: 592
242
+ - economics: 512
243
+ - entertainment: 472
244
+ - sports: 402
245
+ - international: 279
246
+ - science, technology and education: 216
247
+ - health: 92
248
+ - general: 75
249
+ - royal: 54
250
+ - disaster: 52
251
+ - development: 45
252
+ - environment: 40
253
+ - culture: 40
254
+ - weather forecast: 33
255
+ - Word tokenization is done accoding to Inter­BEST 2009 Guideline.
256
+
257
+
258
+ ### Other Known Limitations
259
+
260
+ - Some NER tags do not correspond with given labels (`B`, `I`, and so on)
261
+
262
+ ## Additional Information
263
+
264
+ ### Dataset Curators
265
+
266
+ [NECTEC](https://www.nectec.or.th/en/)
267
+
268
+ ### Licensing Information
269
+
270
+ 1. Non-commercial use, research, and open source
271
+
272
+ Any non-commercial use of the dataset for research and open-sourced projects is encouraged and free of charge. Please cite our technical report for reference.
273
+
274
+ If you want to perpetuate your models trained on our dataset and share them to the research community in Thailand, please send your models, code, and APIs to the AI for Thai Project. Please contact Dr. Thepchai Supnithi via thepchai@nectec.or.th for more information.
275
+
276
+ Note that modification and redistribution of the dataset by any means are strictly prohibited unless authorized by the corpus authors.
277
+
278
+ 2. Commercial use
279
+
280
+ In any commercial use of the dataset, there are two options.
281
+
282
+ - Option 1 (in kind): Contributing a dataset of 50,000 words completely annotated with our annotation scheme within 1 year. Your data will also be shared and recognized as a dataset co-creator in the research community in Thailand.
283
+
284
+ - Option 2 (in cash): Purchasing a lifetime license for the entire dataset is required. The purchased rights of use cover only this dataset.
285
+
286
+ In both options, please contact Dr. Thepchai Supnithi via thepchai@nectec.or.th for more information.
287
+
288
+ ### Citation Information
289
+
290
+ ```
291
+ @article{boonkwan2020annotation,
292
+ title={The Annotation Guideline of LST20 Corpus},
293
+ author={Boonkwan, Prachya and Luantangsrisuk, Vorapon and Phaholphinyo, Sitthaa and Kriengket, Kanyanat and Leenoi, Dhanon and Phrombut, Charun and Boriboon, Monthika and Kosawat, Krit and Supnithi, Thepchai},
294
+ journal={arXiv preprint arXiv:2008.05055},
295
+ year={2020}
296
+ }
297
+ ```
298
+
299
+ ### Contributions
300
+
301
+ Thanks to [@cstorm125](https://github.com/cstorm125) for adding this dataset.
lst20.py ADDED
@@ -0,0 +1,197 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import glob
2
+ import os
3
+ from pathlib import Path
4
+
5
+ import datasets
6
+
7
+
8
+ _CITATION = """\
9
+ @article{boonkwan2020annotation,
10
+ title={The Annotation Guideline of LST20 Corpus},
11
+ author={Boonkwan, Prachya and Luantangsrisuk, Vorapon and Phaholphinyo, Sitthaa and Kriengket, Kanyanat and Leenoi, Dhanon and Phrombut, Charun and Boriboon, Monthika and Kosawat, Krit and Supnithi, Thepchai},
12
+ journal={arXiv preprint arXiv:2008.05055},
13
+ year={2020}
14
+ }
15
+ """
16
+
17
+ _DESCRIPTION = """\
18
+ LST20 Corpus is a dataset for Thai language processing developed by National Electronics and Computer Technology Center (NECTEC), Thailand.
19
+ It offers five layers of linguistic annotation: word boundaries, POS tagging, named entities, clause boundaries, and sentence boundaries.
20
+ At a large scale, it consists of 3,164,002 words, 288,020 named entities, 248,181 clauses, and 74,180 sentences, while it is annotated with
21
+ 16 distinct POS tags. All 3,745 documents are also annotated with one of 15 news genres. Regarding its sheer size, this dataset is
22
+ considered large enough for developing joint neural models for NLP.
23
+ Manually download at https://aiforthai.in.th/corpus.php
24
+ """
25
+
26
+
27
+ class Lst20Config(datasets.BuilderConfig):
28
+ """BuilderConfig for Lst20"""
29
+
30
+ def __init__(self, **kwargs):
31
+ """BuilderConfig for Lst20.
32
+
33
+ Args:
34
+ **kwargs: keyword arguments forwarded to super.
35
+ """
36
+ super(Lst20Config, self).__init__(**kwargs)
37
+
38
+
39
+ class Lst20(datasets.GeneratorBasedBuilder):
40
+ """Lst20 dataset."""
41
+
42
+ _SENTENCE_SPLITTERS = ["", " ", "\n"]
43
+ _TRAINING_FOLDER = "train"
44
+ _VALID_FOLDER = "eval"
45
+ _TEST_FOLDER = "test"
46
+ _POS_TAGS = ["NN", "VV", "PU", "CC", "PS", "AX", "AV", "FX", "NU", "AJ", "CL", "PR", "NG", "PA", "XX", "IJ"]
47
+ _NER_TAGS = [
48
+ "O",
49
+ "B_BRN",
50
+ "B_DES",
51
+ "B_DTM",
52
+ "B_LOC",
53
+ "B_MEA",
54
+ "B_NUM",
55
+ "B_ORG",
56
+ "B_PER",
57
+ "B_TRM",
58
+ "B_TTL",
59
+ "I_BRN",
60
+ "I_DES",
61
+ "I_DTM",
62
+ "I_LOC",
63
+ "I_MEA",
64
+ "I_NUM",
65
+ "I_ORG",
66
+ "I_PER",
67
+ "I_TRM",
68
+ "I_TTL",
69
+ "E_BRN",
70
+ "E_DES",
71
+ "E_DTM",
72
+ "E_LOC",
73
+ "E_MEA",
74
+ "E_NUM",
75
+ "E_ORG",
76
+ "E_PER",
77
+ "E_TRM",
78
+ "E_TTL",
79
+ ]
80
+ _CLAUSE_TAGS = ["O", "B_CLS", "I_CLS", "E_CLS"]
81
+
82
+ BUILDER_CONFIGS = [
83
+ Lst20Config(name="lst20", version=datasets.Version("1.0.0"), description="LST20 dataset"),
84
+ ]
85
+
86
+ @property
87
+ def manual_download_instructions(self):
88
+ return """\
89
+ You need to
90
+ 1. Manually download `AIFORTHAI-LST20Corpus.tar.gz` from https://aiforthai.in.th/corpus.php (login required; website mostly in Thai)
91
+ 2. Extract the .tar.gz; this will result in folder `LST20Corpus`
92
+ The <path/to/folder> can e.g. be `~/Downloads/LST20Corpus`.
93
+ lst20 can then be loaded using the following command `datasets.load_dataset("lst20", data_dir="<path/to/folder>")`.
94
+ """
95
+
96
+ def _info(self):
97
+ return datasets.DatasetInfo(
98
+ description=_DESCRIPTION,
99
+ features=datasets.Features(
100
+ {
101
+ "id": datasets.Value("string"),
102
+ "fname": datasets.Value("string"),
103
+ "tokens": datasets.Sequence(datasets.Value("string")),
104
+ "pos_tags": datasets.Sequence(datasets.features.ClassLabel(names=self._POS_TAGS)),
105
+ "ner_tags": datasets.Sequence(datasets.features.ClassLabel(names=self._NER_TAGS)),
106
+ "clause_tags": datasets.Sequence(datasets.features.ClassLabel(names=self._CLAUSE_TAGS)),
107
+ }
108
+ ),
109
+ supervised_keys=None,
110
+ homepage="https://aiforthai.in.th/",
111
+ citation=_CITATION,
112
+ )
113
+
114
+ def _split_generators(self, dl_manager):
115
+ """Returns SplitGenerators."""
116
+
117
+ data_dir = os.path.abspath(os.path.expanduser(dl_manager.manual_dir))
118
+
119
+ # check if manual folder exists
120
+ if not os.path.exists(data_dir):
121
+ raise FileNotFoundError(
122
+ f"{data_dir} does not exist. Make sure you insert a manual dir via `datasetts.load_dataset('lst20', data_dir=...)`. Manual download instructions: {self.manual_download_instructions})"
123
+ )
124
+
125
+ # check number of .txt files
126
+ nb_train = len(glob.glob(os.path.join(data_dir, "train", "*.txt")))
127
+ nb_valid = len(glob.glob(os.path.join(data_dir, "eval", "*.txt")))
128
+ nb_test = len(glob.glob(os.path.join(data_dir, "test", "*.txt")))
129
+ assert (
130
+ nb_train > 0
131
+ ), f"No files found in train/*.txt.\nManual download instructions:{self.manual_download_instructions})"
132
+ assert (
133
+ nb_valid > 0
134
+ ), f"No files found in eval/*.txt.\nManual download instructions:{self.manual_download_instructions})"
135
+ assert (
136
+ nb_test > 0
137
+ ), f"No files found in test/*.txt.\nManual download instructions:{self.manual_download_instructions})"
138
+
139
+ return [
140
+ datasets.SplitGenerator(
141
+ name=datasets.Split.TRAIN,
142
+ gen_kwargs={"filepath": os.path.join(data_dir, self._TRAINING_FOLDER)},
143
+ ),
144
+ datasets.SplitGenerator(
145
+ name=datasets.Split.VALIDATION,
146
+ gen_kwargs={"filepath": os.path.join(data_dir, self._VALID_FOLDER)},
147
+ ),
148
+ datasets.SplitGenerator(
149
+ name=datasets.Split.TEST,
150
+ gen_kwargs={"filepath": os.path.join(data_dir, self._TEST_FOLDER)},
151
+ ),
152
+ ]
153
+
154
+ def _generate_examples(self, filepath):
155
+ for file_idx, fname in enumerate(sorted(glob.glob(os.path.join(filepath, "*.txt")))):
156
+ with open(fname, encoding="utf-8") as f:
157
+ guid = 0
158
+ tokens = []
159
+ pos_tags = []
160
+ ner_tags = []
161
+ clause_tags = []
162
+
163
+ for line in f:
164
+ if line in self._SENTENCE_SPLITTERS:
165
+ if tokens:
166
+ yield f"{file_idx}_{guid}", {
167
+ "id": str(guid),
168
+ "fname": Path(fname).name,
169
+ "tokens": tokens,
170
+ "pos_tags": pos_tags,
171
+ "ner_tags": ner_tags,
172
+ "clause_tags": clause_tags,
173
+ }
174
+ guid += 1
175
+ tokens = []
176
+ pos_tags = []
177
+ ner_tags = []
178
+ clause_tags = []
179
+ else:
180
+ # LST20 tokens are tab separated
181
+ splits = line.split("\t")
182
+ # replace junk ner tags
183
+ ner_tag = splits[2] if splits[2] in self._NER_TAGS else "O"
184
+ tokens.append(splits[0])
185
+ pos_tags.append(splits[1])
186
+ ner_tags.append(ner_tag)
187
+ clause_tags.append(splits[3].rstrip())
188
+ # last example
189
+ if tokens:
190
+ yield f"{file_idx}_{guid}", {
191
+ "id": str(guid),
192
+ "fname": Path(fname).name,
193
+ "tokens": tokens,
194
+ "pos_tags": pos_tags,
195
+ "ner_tags": ner_tags,
196
+ "clause_tags": clause_tags,
197
+ }