|
"""The Stanford Sentiment Treebank translated to Portuguese.""" |
|
|
|
import csv |
|
|
|
import datasets |
|
from datasets.tasks import TextClassification |
|
|
|
_DESCRIPTION = """\ |
|
The Stanford Sentiment Treebank consists of sentences from movie reviews and |
|
human annotations of their sentiment. The task is to predict the sentiment of a |
|
given sentence. We use the two-way (positive/negative) class split, and use only |
|
sentence-level labels. |
|
""" |
|
|
|
_CITATION = """\ |
|
@inproceedings{socher2013recursive, |
|
title={Recursive deep models for semantic compositionality over a sentiment treebank}, |
|
author={Socher, Richard and Perelygin, Alex and Wu, Jean and Chuang, Jason and Manning, Christopher D and Ng, Andrew and Potts, Christopher}, |
|
booktitle={Proceedings of the 2013 conference on empirical methods in natural language processing}, |
|
pages={1631--1642}, |
|
year={2013} |
|
} |
|
""" |
|
|
|
_HOMEPAGE = "https://nlp.stanford.edu/sentiment/" |
|
|
|
_DOWNLOAD_URL = "https://huggingface.co/datasets/maritaca-ai/sst2_pt/resolve/main" |
|
|
|
class SST2(datasets.GeneratorBasedBuilder): |
|
"""The Stanford Sentiment Treebank translated to Portuguese.""" |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=datasets.Features( |
|
{"text": datasets.Value("string"), "label": datasets.features.ClassLabel(names=["negativo", "positivo"])} |
|
), |
|
supervised_keys=None, |
|
homepage=_HOMEPAGE, |
|
citation=_CITATION, |
|
task_templates=[TextClassification(text_column="text", label_column="label")], |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
train_path = dl_manager.download_and_extract(f"{_DOWNLOAD_URL}/train.csv") |
|
validation_path = dl_manager.download_and_extract(f"{_DOWNLOAD_URL}/validation.csv") |
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, gen_kwargs={"filepath": train_path, "split": "train"} |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.VALIDATION, gen_kwargs={"filepath": validation_path, "split": "validation"} |
|
), |
|
] |
|
|
|
def _generate_examples(self, filepath, split): |
|
with open(filepath, encoding="utf-8") as csv_file: |
|
csv_reader = csv.reader( |
|
csv_file, quotechar='"', delimiter=",", quoting=csv.QUOTE_ALL, skipinitialspace=True |
|
) |
|
next(csv_reader) |
|
for row in csv_reader: |
|
idx, text, label = row |
|
yield idx, {"text": text, "label": label} |
|
|