Datasets:

Languages:
Khmer
ArXiv:
License:
holylovenia commited on
Commit
ca8164c
1 Parent(s): 7407de8

Upload khmer_alt_pos.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. khmer_alt_pos.py +165 -0
khmer_alt_pos.py ADDED
@@ -0,0 +1,165 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2022 The HuggingFace Datasets Authors and the current dataset script contributor.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ from pathlib import Path
17
+ from typing import Dict, List, Tuple
18
+
19
+ import datasets
20
+
21
+ from seacrowd.utils import schemas
22
+ from seacrowd.utils.configs import SEACrowdConfig
23
+ from seacrowd.utils.constants import Tasks, Licenses
24
+
25
+ _CITATION = """\
26
+ @article{10.1145/3464378,
27
+ author = {Kaing, Hour and Ding, Chenchen and Utiyama, Masao and Sumita, Eiichiro and Sam, Sethserey and Seng, Sopheap and Sudoh, Katsuhito and Nakamura, Satoshi},
28
+ title = {Towards Tokenization and Part-of-Speech Tagging for Khmer: Data and Discussion},
29
+ year = {2021},
30
+ issue_date = {November 2021},
31
+ publisher = {Association for Computing Machinery},
32
+ address = {New York, NY, USA},
33
+ volume = {20},
34
+ number = {6},
35
+ issn = {2375-4699},
36
+ url = {https://doi.org/10.1145/3464378},
37
+ doi = {10.1145/3464378},
38
+ abstract = {As a highly analytic language, Khmer has considerable ambiguities in tokenization and part-of-speech (POS) tagging processing. This topic is investigated in this study. Specifically, a 20,000-sentence Khmer corpus with manual tokenization and POS-tagging annotation is released after a series of work over the last 4 years. This is the largest morphologically annotated Khmer dataset as of 2020, when this article was prepared. Based on the annotated data, experiments were conducted to establish a comprehensive benchmark on the automatic processing of tokenization and POS-tagging for Khmer. Specifically, a support vector machine, a conditional random field (CRF), a long short-term memory (LSTM)-based recurrent neural network, and an integrated LSTM-CRF model have been investigated and discussed. As a primary conclusion, processing at morpheme-level is satisfactory for the provided data. However, it is intrinsically difficult to identify further grammatical constituents of compounds or phrases because of the complex analytic features of the language. Syntactic annotation and automatic parsing for Khmer will be scheduled in the near future.},
39
+ journal = {ACM Trans. Asian Low-Resour. Lang. Inf. Process.},
40
+ month = {sep},
41
+ articleno = {104},
42
+ numpages = {16},
43
+ keywords = {annotated data, tokenization, POS-tagging, Khmer, machine learning}
44
+ }
45
+ """
46
+
47
+ _LANGUAGES = ["khm"] # We follow ISO639-3 language code (https://iso639-3.sil.org/code_tables/639/data)
48
+ _LOCAL = False
49
+
50
+ _DATASETNAME = "khmer_alt_pos"
51
+
52
+ _DESCRIPTION = """\
53
+ The data contains 20,000-sentence Khmer corpus with manual tokenization and POS-tagging annotation.
54
+ """
55
+
56
+ _HOMEPAGE = "https://www2.nict.go.jp/astrec-att/member/mutiyama/ALT/km-nova-181101/README.txt"
57
+
58
+ _LICENSE = Licenses.CC_BY_NC_SA_4_0.value
59
+
60
+ _URL = "https://www2.nict.go.jp/astrec-att/member/mutiyama/ALT/km-nova-181101.zip"
61
+
62
+ _SUPPORTED_TASKS = [Tasks.POS_TAGGING]
63
+
64
+ _SOURCE_VERSION = "1.1.0"
65
+
66
+ _SEACROWD_VERSION = "2024.06.20"
67
+
68
+
69
+ class KhmerAltPOS(datasets.GeneratorBasedBuilder):
70
+ """The data contains 20,000-sentence Khmer corpus with manual tokenization and POS-tagging annotation."""
71
+
72
+ SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
73
+ SEACROWD_VERSION = datasets.Version(_SEACROWD_VERSION)
74
+
75
+ POS_TAGS = ['n', 'v-', 'v', 'o', 'n[n', 'n]n', 'v]n', '1]n', '.', 'a[n', '1]a', 'a', 'a[v', 'n]a', 'v[a', 'v]v', 'o[o', 'o]o', 'o-', 'a[1', 'v[v', 'a[o', '1', 'a]a', 'n-[n', 'n-]n-', 'a-', 'n]v', 'a]n', 'o]a', 'v]o', 'n-]o', 'a[a', 'n-', 'n[1', 'n]o', '1[1', '1]1', 'n[o', 'n[v', 'a]o', '.]a', 'o-[o-', 'o]o-', 'o[v', 'n[a', 'v-]n', 'v]a', 'o[a', 'o[n', 'o[n-', 'o-]o', 'a-]n', 'n[.', 'o]v', 'o]n', '.]o', 'a-]a', 'a-]o', 'v-[v-', 'o]v-', 'o-]o-', 'v-]o', 'a]v', 'v[n', '.]n', 'n-]a', 'v]o-', 'o[o-', 'n-]n', '+', 'v[o', '.]1', 'v[1', 'n]1', '.]v', 'o]1', 'o[1', '1]o', 'v]1', 'n-[n-', '1]v', '1[n', 'a[.', '.[n', '.].', '+[n', 'n]+', '1[.', '+]o', 'n]o-', 'o-]a', 'v-[v', '.]v-', '.[1', 'v-[o']
76
+
77
+ BUILDER_CONFIGS = [
78
+ SEACrowdConfig(
79
+ name=f"{_DATASETNAME}_source",
80
+ version=SOURCE_VERSION,
81
+ description=f"{_DATASETNAME} source schema",
82
+ schema="source",
83
+ subset_id=f"{_DATASETNAME}",
84
+ ),
85
+ SEACrowdConfig(
86
+ name=f"{_DATASETNAME}_seacrowd_seq_label",
87
+ version=SEACROWD_VERSION,
88
+ description=f"{_DATASETNAME} SEACrowd Seq Label schema",
89
+ schema="seacrowd_seq_label",
90
+ subset_id=f"{_DATASETNAME}",
91
+ ),
92
+ ]
93
+
94
+ DEFAULT_CONFIG_NAME = f"{_DATASETNAME}_source"
95
+
96
+ def _info(self) -> datasets.DatasetInfo:
97
+
98
+ if self.config.schema == "source":
99
+ features = datasets.Features({
100
+ "id": datasets.Value("string"),
101
+ "tokens": [datasets.Value("string")],
102
+ "labels": [datasets.Value("string")],
103
+ })
104
+ elif self.config.schema == "seacrowd_seq_label":
105
+ features = schemas.seq_label_features(self.POS_TAGS)
106
+
107
+ else:
108
+ raise NotImplementedError(f"Schema '{self.config.schema}' is not defined.")
109
+
110
+ return datasets.DatasetInfo(
111
+ description=_DESCRIPTION,
112
+ features=features,
113
+ homepage=_HOMEPAGE,
114
+ license=_LICENSE,
115
+ citation=_CITATION,
116
+ )
117
+
118
+ def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
119
+ """Returns SplitGenerators."""
120
+ data_path = dl_manager.download_and_extract(_URL)
121
+
122
+ return [
123
+ datasets.SplitGenerator(
124
+ name=datasets.Split.TRAIN,
125
+ gen_kwargs={
126
+ "filepath": data_path,
127
+ },
128
+ ),
129
+ ]
130
+
131
+ def _generate_examples(self, filepath: Path) -> Tuple[int, Dict]:
132
+ data_labels = open(f"{filepath}/km-nova-181101/data_km.km-tag.nova", "r").readlines()
133
+
134
+ data_tokens = open(f"{filepath}/km-nova-181101/data_km.km-tok.nova", "r").readlines()
135
+
136
+ mapping_sentences = {}
137
+
138
+ for line in data_tokens:
139
+ id, tokens = line.split("\t")
140
+ tokens, _ = tokens.split("\n")
141
+
142
+ if id not in mapping_sentences:
143
+ mapping_sentences[id] = {}
144
+
145
+ mapping_sentences[id]["tokens"] = tokens.split(" ")
146
+
147
+ for line in data_labels:
148
+ id, labels = line.split("\t")
149
+ labels, _ = labels.split("\n")
150
+
151
+ if id not in mapping_sentences:
152
+ mapping_sentences[id] = {}
153
+
154
+ mapping_sentences[id]["labels"] = labels.split(" ")
155
+
156
+ if self.config.schema == "source" or self.config.schema == "seacrowd_seq_label":
157
+ for num, key in enumerate(mapping_sentences):
158
+ yield num, {
159
+ "id": key,
160
+ "tokens": mapping_sentences[key]["tokens"],
161
+ "labels": mapping_sentences[key]["labels"]
162
+ }
163
+
164
+ else:
165
+ raise NotImplementedError(f"Schema '{self.config.schema}' is not defined.")