holylovenia commited on
Commit
1729058
1 Parent(s): 6110502

Upload indoner_tourism.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. indoner_tourism.py +183 -0
indoner_tourism.py ADDED
@@ -0,0 +1,183 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ """\
17
+ This dataset is designed for named entity recognition (NER) tasks in the Bahasa Indonesia tourism domain. It contains labeled sequences of named entities, including locations, facilities, and tourism-related entities. The dataset is annotated with the following entity types:
18
+
19
+ O (0) : Non-entity or other words not falling into the specified categories.
20
+ B-WIS (1): Beginning of a tourism-related entity.
21
+ I-WIS (2): Continuation of a tourism-related entity.
22
+ B-LOC (3): Beginning of a location entity.
23
+ I-LOC (4): Continuation of a location entity.
24
+ B-FAS (5): Beginning of a facility entity.
25
+ I-FAS (6): Continuation of a facility entity.
26
+ """
27
+ import os
28
+ import pandas as pd
29
+ from pathlib import Path
30
+ from typing import Dict, List, Tuple
31
+
32
+ import datasets
33
+
34
+ from seacrowd.utils import schemas
35
+ from seacrowd.utils.configs import SEACrowdConfig
36
+ from seacrowd.utils.constants import Tasks, Licenses
37
+
38
+ _CITATION = """\
39
+ @article{JLK,
40
+ author = {Ahmad Hidayatullah and Muhammad Fakhri Despawida Aulia Putra and Adityo Permana Wibowo and Kartika Rizqi Nastiti},
41
+ title = { Named Entity Recognition on Tourist Destinations Reviews in the Indonesian Language},
42
+ journal = {Jurnal Linguistik Komputasional},
43
+ volume = {6},
44
+ number = {1},
45
+ year = {2023},
46
+ keywords = {},
47
+ abstract = {To find information about tourist destinations, tourists usually search the reviews about the destinations they want to visit. However, many studies made it hard for them to see the desired information. Named Entity Recognition (NER) is one of the techniques to detect entities in a text. The objective of this research was to make a NER model using BiLSTM to detect and evaluate entities on tourism destination reviews. This research used 2010 reviews of several tourism destinations in Indonesia and chunked them into 116.564 tokens of words. Those tokens were labeled according to their categories: the name of the tourism destination, locations, and facilities. If the tokens could not be classified according to the existing categories, the tokens would be labeled as O (outside). The model has been tested and gives 94,3% as the maximum average of F1-Score.},
48
+ issn = {2621-9336}, pages = {30--35}, doi = {10.26418/jlk.v6i1.89},
49
+ url = {https://inacl.id/journal/index.php/jlk/article/view/89}
50
+ }
51
+ """
52
+
53
+ _DATASETNAME = "indoner_tourism"
54
+
55
+ _DESCRIPTION = """\
56
+ This dataset is designed for named entity recognition (NER) tasks in the Bahasa Indonesia tourism domain. It contains labeled sequences of named entities, including locations, facilities, and tourism-related entities. The dataset is annotated with the following entity types:
57
+
58
+ O (0) : Non-entity or other words not falling into the specified categories.
59
+ B-WIS (1): Beginning of a tourism-related entity.
60
+ I-WIS (2): Continuation of a tourism-related entity.
61
+ B-LOC (3): Beginning of a location entity.
62
+ I-LOC (4): Continuation of a location entity.
63
+ B-FAS (5): Beginning of a facility entity.
64
+ I-FAS (6): Continuation of a facility entity.
65
+ """
66
+
67
+ _HOMEPAGE = "https://github.com/fathanick/IndoNER-Tourism/tree/main"
68
+
69
+ _LANGUAGES = ['ind'] # We follow ISO639-3 language code (https://iso639-3.sil.org/code_tables/639/data)
70
+
71
+ _LICENSE = Licenses.AFL_3_0.value
72
+
73
+ _LOCAL = False
74
+
75
+ _URL = "https://raw.githubusercontent.com/fathanick/IndoNER-Tourism/main/ner_data.tsv"
76
+
77
+ _SUPPORTED_TASKS = [Tasks.NAMED_ENTITY_RECOGNITION]
78
+
79
+ _SOURCE_VERSION = "1.0.0"
80
+
81
+ _SEACROWD_VERSION = "2024.06.20"
82
+
83
+
84
+ class IndoNERTourismDataset(datasets.GeneratorBasedBuilder):
85
+ """\
86
+ This dataset is designed for named entity recognition (NER) tasks in the Bahasa Indonesia tourism domain. It contains labeled sequences of named entities, including locations, facilities, and tourism-related entities. The dataset is annotated with the following entity types:
87
+
88
+ O (0) : Non-entity or other words not falling into the specified categories.
89
+ B-WIS (1): Beginning of a tourism-related entity.
90
+ I-WIS (2): Continuation of a tourism-related entity.
91
+ B-LOC (3): Beginning of a location entity.
92
+ I-LOC (4): Continuation of a location entity.
93
+ B-FAS (5): Beginning of a facility entity.
94
+ I-FAS (6): Continuation of a facility entity.
95
+ """
96
+
97
+ SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
98
+ SEACROWD_VERSION = datasets.Version(_SEACROWD_VERSION)
99
+
100
+ BUILDER_CONFIGS = [
101
+ SEACrowdConfig(
102
+ name=f"{_DATASETNAME}_source",
103
+ version=SOURCE_VERSION,
104
+ description="indoner_tourism source schema",
105
+ schema="source",
106
+ subset_id=_DATASETNAME,
107
+ ),
108
+ SEACrowdConfig(
109
+ name=f"{_DATASETNAME}_seacrowd_seq_label",
110
+ version=SEACROWD_VERSION,
111
+ description="indoner_tourism SEACrowd schema",
112
+ schema="seacrowd_seq_label",
113
+ subset_id=_DATASETNAME,
114
+ ),
115
+ ]
116
+
117
+ DEFAULT_CONFIG_NAME = f"{_DATASETNAME}_source"
118
+
119
+ def _info(self) -> datasets.DatasetInfo:
120
+ if self.config.schema == "source":
121
+ features = datasets.Features(
122
+ {
123
+ 'tokens' : datasets.Sequence(datasets.Value("string")),
124
+ 'ner_tags': datasets.Sequence(
125
+ datasets.ClassLabel(names=["O", "B-WIS", "I-WIS", "B-LOC", "I-LOC", "B-FAS", "I-FAS"])
126
+ ),
127
+ }
128
+ )
129
+ elif self.config.schema == "seacrowd_seq_label":
130
+ features = schemas.seq_label.features(["O", "B-WIS", "I-WIS", "B-LOC", "I-LOC", "B-FAS", "I-FAS"])
131
+
132
+ return datasets.DatasetInfo(
133
+ description=_DESCRIPTION,
134
+ features=features,
135
+ homepage=_HOMEPAGE,
136
+ license=_LICENSE,
137
+ citation=_CITATION,
138
+ )
139
+
140
+ def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
141
+ """Returns SplitGenerators."""
142
+ urls = _URL
143
+ path = dl_manager.download_and_extract(urls)
144
+
145
+ return [
146
+ datasets.SplitGenerator(
147
+ name=datasets.Split.TRAIN,
148
+ gen_kwargs={
149
+ "filepath": path,
150
+ "split": "train",
151
+ },
152
+ ),
153
+ ]
154
+
155
+ def _generate_examples(self, filepath: Path, split: str) -> Tuple[int, Dict]:
156
+ """Yields examples as (key, example) tuples."""
157
+ tokens = []
158
+ ner_tags = []
159
+ counter = 0
160
+ with open(filepath, encoding="utf-8") as file:
161
+ for line in file:
162
+ # End of Sentence met
163
+ if line.strip() == "":
164
+ if self.config.schema == "source":
165
+ yield counter, {'tokens': tokens, 'ner_tags': ner_tags}
166
+ counter += 1
167
+ tokens = []
168
+ ner_tags = []
169
+ elif self.config.schema == "seacrowd_seq_label":
170
+ yield counter, {'id': counter, 'tokens': tokens, 'labels': ner_tags}
171
+ counter += 1
172
+ tokens = []
173
+ ner_tags = []
174
+ # Process until End of Sentence met
175
+ elif len(line.split('\t')) == 2:
176
+ token, ner_tag = line.split('\t')
177
+ tokens.append(token.strip())
178
+ if ner_tag not in ["O", "B-WIS", "I-WIS", "B-LOC", "I-LOC", "B-FAS", "I-FAS"]:
179
+ if ner_tag[0] in ["B", "I"]:
180
+ if any(tag in ner_tag for tag in ["WIS", "LOC", "FAS"]):
181
+ if '_' in ner_tag:
182
+ ner_tag = '-'.join(ner_tag.split('_'))
183
+ ner_tags.append(ner_tag.strip())