Datasets:

Languages:
Burmese
ArXiv:
License:
holylovenia commited on
Commit
68e1d58
1 Parent(s): 0e67472

Upload mysentence.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. mysentence.py +162 -0
mysentence.py ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ from pathlib import Path
3
+ from typing import Dict, List, Tuple
4
+
5
+ import datasets
6
+
7
+ from seacrowd.utils import schemas
8
+ from seacrowd.utils.configs import SEACrowdConfig
9
+ from seacrowd.utils.constants import Licenses, Tasks
10
+
11
+ _CITATION = """\
12
+ @article{Aung_Kyaw_Thu_Hlaing_2023,
13
+ title = {{mySentence: Sentence Segmentation for Myanmar Language using Neural Machine Translation Approach}},
14
+ author = {Aung, Thura and Kyaw Thu , Ye and Hlaing , Zar Zar},
15
+ year = 2023,
16
+ month = {Nov.},
17
+ journal = {Journal of Intelligent Informatics and Smart Technology},
18
+ volume = 9,
19
+ number = {October},
20
+ pages = {e001},
21
+ url = {https://ph05.tci-thaijo.org/index.php/JIIST/article/view/87},
22
+ place = {Nonthaburi, Thailand},
23
+ abstract = {In the informal Myanmar language, for which most NLP applications are used, there is no predefined rule to mark the end of the sentence. Therefore, in this paper, we contributed the first Myanmar sentence segmentation corpus and systemat ically experimented with twelve neural sequence labeling architectures trained and tested on both sentence and sentence+paragraph data. The word LSTM + Softmax achieved the highest accuracy of 99.95{\%} while trained and tested on sentence-only data and 97.40{\%} while trained and tested on sentence + paragraph data.}
24
+ }
25
+ @inproceedings{10.1007/978-3-031-36886-8_24,
26
+ title = {{Neural Sequence Labeling Based Sentence Segmentation for Myanmar Language}},
27
+ author = {Thu, Ye Kyaw and Aung, Thura and Supnithi, Thepchai},
28
+ year = 2023,
29
+ booktitle = {The 12th Conference on Information Technology and Its Applications},
30
+ publisher = {Springer Nature Switzerland},
31
+ address = {Cham},
32
+ pages = {285--296},
33
+ isbn = {978-3-031-36886-8},
34
+ editor = {Nguyen, Ngoc Thanh and Le-Minh, Hoa and Huynh, Cong-Phap and Nguyen, Quang-Vu},
35
+ abstract = {In the informal Myanmar language, for which most NLP applications are used, there is no predefined rule to mark the end of the sentence. Therefore, in this paper, we contributed the first Myanmar sentence segmentation corpus and systemat ically experimented with twelve neural sequence labeling architectures trained and tested on both sentence and sentence+paragraph data. The word LSTM + Softmax achieved the highest accuracy of 99.95{\%} while trained and tested on sentence-only data and 97.40{\%} while trained and tested on sentence + paragraph data.}
36
+ }
37
+ """
38
+
39
+ _DATASETNAME = "mysentence"
40
+ _DESCRIPTION = """\
41
+ mySentence is a corpus with a total size of around 55K for Myanmar sentence segmentation. In formal Burmese (Myanmar language), sentences are grammatically structured
42
+ and typically end with the "။" pote-ma symbol. However, informal language, more commonly used in daily conversations due to its natural flow, does not always follow predefined
43
+ rules for ending sentences, making it challenging for machines to identify sentence boundaries. In this corpus, each token of the sentences and paragraphs is tagged from start to finish.
44
+ """
45
+
46
+ _HOMEPAGE = "https://github.com/ye-kyaw-thu/mySentence"
47
+ _LANGUAGES = ["mya"]
48
+ _LICENSE = Licenses.CC_BY_NC_SA_4_0.value
49
+ _LOCAL = False
50
+ _URLS = {
51
+ "sent": {
52
+ "train": "https://raw.githubusercontent.com/ye-kyaw-thu/mySentence/main/ver1.0/data/data-sent/sent_tagged/train.tagged",
53
+ "valid": "https://raw.githubusercontent.com/ye-kyaw-thu/mySentence/main/ver1.0/data/data-sent/sent_tagged/valid.tagged",
54
+ "test": "https://raw.githubusercontent.com/ye-kyaw-thu/mySentence/main/ver1.0/data/data-sent/sent_tagged/test.tagged",
55
+ },
56
+ "sent+para": {
57
+ "train": "https://raw.githubusercontent.com/ye-kyaw-thu/mySentence/main/ver1.0/data/data-sent+para/sent+para_tagged/train.tagged",
58
+ "valid": "https://raw.githubusercontent.com/ye-kyaw-thu/mySentence/main/ver1.0/data/data-sent+para/sent+para_tagged/valid.tagged",
59
+ "test": "https://raw.githubusercontent.com/ye-kyaw-thu/mySentence/main/ver1.0/data/data-sent+para/sent+para_tagged/test.tagged",
60
+ },
61
+ }
62
+
63
+ _SUPPORTED_TASKS = [Tasks.POS_TAGGING]
64
+ _SOURCE_VERSION = "1.0.0"
65
+ _SEACROWD_VERSION = "2024.06.20"
66
+
67
+
68
+ class MysentenceDataset(datasets.GeneratorBasedBuilder):
69
+ SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
70
+ SEACROWD_VERSION = datasets.Version(_SEACROWD_VERSION)
71
+ BUILDER_CONFIGS = [
72
+ SEACrowdConfig(
73
+ name=f"{_DATASETNAME}_source",
74
+ version=SOURCE_VERSION,
75
+ description=_DESCRIPTION,
76
+ schema="source",
77
+ subset_id=f"{_DATASETNAME}",
78
+ ),
79
+ SEACrowdConfig(
80
+ name=f"{_DATASETNAME}_seacrowd_seq_label",
81
+ version=SEACROWD_VERSION,
82
+ description="sentences SEACrowd schema",
83
+ schema="seacrowd_seq_label",
84
+ subset_id=f"{_DATASETNAME}",
85
+ ),
86
+ SEACrowdConfig(
87
+ name=f"{_DATASETNAME}_and_paragraphs_source",
88
+ version=SOURCE_VERSION,
89
+ description="sentences para source schema",
90
+ schema="source",
91
+ subset_id=f"{_DATASETNAME}_and_paragraphs",
92
+ ),
93
+ SEACrowdConfig(
94
+ name=f"{_DATASETNAME}_and_paragraphs_seacrowd_seq_label",
95
+ version=SEACROWD_VERSION,
96
+ description="sentence para SEACrowd schema",
97
+ schema="seacrowd_seq_label",
98
+ subset_id=f"{_DATASETNAME}_and_paragraphs",
99
+ ),
100
+ ]
101
+
102
+ DEFAULT_CONFIG_NAME = f"{_DATASETNAME}_source"
103
+
104
+ def _info(self) -> datasets.DatasetInfo:
105
+ if self.config.schema == "source":
106
+ features = datasets.Features(
107
+ {
108
+ "id": datasets.Value("string"),
109
+ "tokens": datasets.Sequence(datasets.Value("string")),
110
+ "labels": datasets.Sequence(datasets.Value("string")),
111
+ }
112
+ )
113
+ else:
114
+ features = schemas.seq_label_features(["B", "O", "N", "E"])
115
+ return datasets.DatasetInfo(
116
+ description=_DESCRIPTION,
117
+ features=features, # B (Begin), O (Other), N (Next), and E (End)
118
+ homepage=_HOMEPAGE,
119
+ license=_LICENSE,
120
+ citation=_CITATION,
121
+ )
122
+
123
+ def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
124
+ """Returns SplitGenerators."""
125
+ if self.config.subset_id == f"{_DATASETNAME}":
126
+ DATA_URL_ = _URLS["sent"]
127
+ elif self.config.subset_id == f"{_DATASETNAME}_and_paragraphs":
128
+ DATA_URL_ = _URLS["sent+para"]
129
+ else:
130
+ raise ValueError(f"No related dataset id for {self.config.subset_id}")
131
+
132
+ data_dir = dl_manager.download_and_extract(DATA_URL_)
133
+
134
+ return [
135
+ datasets.SplitGenerator(
136
+ name=datasets.Split.TRAIN,
137
+ gen_kwargs={"filepath": data_dir["train"]},
138
+ ),
139
+ datasets.SplitGenerator(
140
+ name=datasets.Split.TEST,
141
+ gen_kwargs={"filepath": data_dir["test"]},
142
+ ),
143
+ datasets.SplitGenerator(
144
+ name=datasets.Split.VALIDATION,
145
+ gen_kwargs={
146
+ "filepath": data_dir["valid"],
147
+ },
148
+ ),
149
+ ]
150
+
151
+ def _generate_examples(self, filepath: Path) -> Tuple[int, Dict]:
152
+
153
+ with open(filepath, "r") as filein:
154
+ examples = [line.strip("\n").split(" ") for line in filein.readlines()]
155
+ for eid, exam in enumerate(examples):
156
+ tokens = []
157
+ pos = []
158
+ for tok_chunk in exam:
159
+ tok_ = tok_chunk.split("/")
160
+ tokens.append(tok_[0])
161
+ pos.append(tok_[1])
162
+ yield eid, {"id": str(eid), "tokens": tokens, "labels": pos}