DLTBryan commited on
Commit ·
5444d36
1
Parent(s): 8ee3731
Initial loader created
Browse files- tropical.py +109 -0
tropical.py
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import datasets, json
|
| 2 |
+
from datasets.info import DatasetInfo
|
| 3 |
+
|
| 4 |
+
_DESCRIPTION_ORIGINAL = """ """
|
| 5 |
+
_DESCRIPTION_OVERLAPPING = """ """
|
| 6 |
+
_DESCRIPTION_NO_OVERLAPPING = """ """
|
| 7 |
+
|
| 8 |
+
_CITATION = """ """
|
| 9 |
+
|
| 10 |
+
_URL = "https://github.com/GePaSud/TROPICAL/blob/main/"
|
| 11 |
+
_URL_NO_OVERLAPPING = _URL + "no_overlapping_dataset/"
|
| 12 |
+
_URL_OVERLAPPING = _URL + "overlapping_dataset/"
|
| 13 |
+
_URL_ORIGINAL = _URL + "original_dataset/"
|
| 14 |
+
|
| 15 |
+
_URLS_ORIGINAL = {
|
| 16 |
+
"train" : _URL_ORIGINAL + "train.jsonl",
|
| 17 |
+
"test" : _URL_ORIGINAL + "test.jsonl",
|
| 18 |
+
"val" :_URL_ORIGINAL + "val.jsonl",
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
_URLS_NO_OVERLAPPING = {
|
| 22 |
+
"train" : _URL_NO_OVERLAPPING + "train.jsonl",
|
| 23 |
+
"test" : _URL_NO_OVERLAPPING + "test.jsonl",
|
| 24 |
+
"val" : _URL_NO_OVERLAPPING + "val.jsonl",
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
_URLS_OVERLAPPING = {
|
| 28 |
+
"train" : _URL_OVERLAPPING + "train.jsonl",
|
| 29 |
+
"test" : _URL_OVERLAPPING + "test.jsonl",
|
| 30 |
+
"val" : _URL_OVERLAPPING + "val.jsonl",
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
class TROPICALConfig(datasets.BuilderConfig):
|
| 36 |
+
def __init__(self, data_url, version, **kwargs):
|
| 37 |
+
super(TROPICALConfig, self).__init__(version=datasets.version(version), **kwargs)
|
| 38 |
+
self.data_url = data_url
|
| 39 |
+
|
| 40 |
+
class TROPICALDataset(datasets.GeneratorBasedBuilder):
|
| 41 |
+
"""TROPICAL: TRiplet Opinion Polynesian Information for Cultural and Local Tourism"""
|
| 42 |
+
|
| 43 |
+
VERSION = "1.0.0"
|
| 44 |
+
|
| 45 |
+
BUILDER_CONFIGS = [
|
| 46 |
+
TROPICALConfig(name="original", data_url = _URL_NO_OVERLAPPING, version = VERSION),
|
| 47 |
+
TROPICALConfig(name="no_overlapping", data_url = _URL_NO_OVERLAPPING, version = VERSION),
|
| 48 |
+
TROPICALConfig(name="overlapping", data_url = _URL_OVERLAPPING, version = VERSION),
|
| 49 |
+
]
|
| 50 |
+
|
| 51 |
+
def _info(self) -> DatasetInfo:
|
| 52 |
+
description = ""
|
| 53 |
+
if self.config.name == "original":
|
| 54 |
+
description = _DESCRIPTION_ORIGINAL
|
| 55 |
+
elif self.config.name == "no_overlapping":
|
| 56 |
+
description = _DESCRIPTION_NO_OVERLAPPING
|
| 57 |
+
elif self.config.name == "overlapping":
|
| 58 |
+
description = _DESCRIPTION_OVERLAPPING
|
| 59 |
+
|
| 60 |
+
return datasets.DatasetInfo(
|
| 61 |
+
description=description,
|
| 62 |
+
features=datasets.Features(
|
| 63 |
+
{
|
| 64 |
+
"id": datasets.Value("string"),
|
| 65 |
+
"words" : datasets.features.Sequence(datasets.Value("string")),
|
| 66 |
+
"triplets" : datasets.features.Sequence(
|
| 67 |
+
{
|
| 68 |
+
"aspect_term" : datasets.features.Sequence(datasets.Value("string")),
|
| 69 |
+
"opinion_term" : datasets.features.Sequence(datasets.Value("string")),
|
| 70 |
+
"aspect_position" : datasets.features.Sequence(datasets.Value("int32")),
|
| 71 |
+
"opinion_position" : datasets.features.Sequence(datasets.Value("int32")),
|
| 72 |
+
"polarity" : datasets.ClassLabel(names=["POS", "NEG", "NEU"]),
|
| 73 |
+
}
|
| 74 |
+
),
|
| 75 |
+
"general_polarity": datasets.ClassLabel(names=["POS", "NEG", "NEU"]),
|
| 76 |
+
}
|
| 77 |
+
),
|
| 78 |
+
homepage="https://github.com/GePaSud/TROPICAL",
|
| 79 |
+
citation=_CITATION,
|
| 80 |
+
)
|
| 81 |
+
|
| 82 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager):
|
| 83 |
+
|
| 84 |
+
if self.config.name == "original":
|
| 85 |
+
data_urls = _URLS_ORIGINAL
|
| 86 |
+
elif self.config.name == "no_overlapping":
|
| 87 |
+
data_urls = _URLS_NO_OVERLAPPING
|
| 88 |
+
elif self.config.name == "overlapping":
|
| 89 |
+
data_urls = _URLS_OVERLAPPING
|
| 90 |
+
|
| 91 |
+
downloaded_files = dl_manager.download_and_extract(data_urls)
|
| 92 |
+
|
| 93 |
+
return [
|
| 94 |
+
datasets.SplitGenerator(datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
|
| 95 |
+
datasets.SplitGenerator(datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}),
|
| 96 |
+
datasets.SplitGenerator(datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["val"]}),
|
| 97 |
+
]
|
| 98 |
+
|
| 99 |
+
def _generate_examples(self, filepath):
|
| 100 |
+
with open(filepath) as f:
|
| 101 |
+
for id_, row in enumerate(f):
|
| 102 |
+
data = json.loads(row)
|
| 103 |
+
yield id_, {
|
| 104 |
+
"id": data["id"],
|
| 105 |
+
"words" : data["words"],
|
| 106 |
+
"triplets" : data["triplets"],
|
| 107 |
+
"general_polarity": data["general_polarity"],
|
| 108 |
+
}
|
| 109 |
+
|