aspect-based-sentiment-analysis-uzbek / aspect-based-sentiment-analysis-uzbek.py
Sanatbek's picture
Rename aspect-based-sentiment-analysis-uzbek1.py to aspect-based-sentiment-analysis-uzbek.py
3a1cf1a
raw
history blame
1.9 kB
import json
import datasets
from datasets import GeneratorBasedBuilder, DatasetInfo, Split, SplitGenerator, Features, Value, Sequence
_BASE_URL = "https://drive.google.com/uc?export=download&id=12J5C6knWWPebLsjdZt0zCU4GKzDO5kGa"
class UzABSA(GeneratorBasedBuilder):
VERSION = datasets.Version("1.0.0")
BUILDER_CONFIGS = [
datasets.BuilderConfig(name="uzabsa", version=VERSION,
description="UZABSA dataset for sentiment analysis in Uzbek"),
]
def _info(self):
return DatasetInfo(
features=Features({
"sentence_id": Value("string"),
"text": Value("string"),
"aspect_terms": Sequence({
"term": Value("string"),
"polarity": Value("string"),
"from": Value("int32"),
"to": Value("int32"),
}),
"aspect_categories": Sequence({
"category": Value("string"),
"polarity": Value("string"),
}),
})
)
def _split_generators(self, dl_manager):
# Use the dl_manager to download and cache the data
downloaded_file = dl_manager.download_and_extract(_BASE_URL)
return [
SplitGenerator(name=Split.TRAIN, gen_kwargs={"filepath": downloaded_file}),
]
def _generate_examples(self, filepath):
# Now we'll read the jsonl format
with open(filepath, 'r') as file:
for line in file:
record = json.loads(line.strip())
yield record["sentence_id"], {
"sentence_id": record["sentence_id"],
"text": record["text"],
"aspect_terms": record["aspect_terms"],
"aspect_categories": record["aspect_categories"],
}