b2w-reviews01 / b2w-reviews01.py
ruanchaves's picture
b2w-reviews
0d9e574
"""B2W-Reviews01 dataset"""
import datasets
import pandas as pd
_CITATION = """
@inproceedings{real2019b2w,
title={B2W-reviews01: an open product reviews corpus},
author={Real, Livy and Oshiro, Marcio and Mafra, Alexandre},
booktitle={STIL-Symposium in Information and Human Language Technology},
year={2019}
}
"""
_DESCRIPTION = """
B2W-Reviews01 is an open corpus of product reviews. It contains more than 130k e-commerce customer reviews, collected from the Americanas.com website between January and May, 2018. B2W-Reviews01 offers rich information about the reviewer profile, such as gender, age, and geographical location. The corpus also has two different review rates"""
_URLS = {
"train": "https://raw.githubusercontent.com/americanas-tech/b2w-reviews01/4639429ec698d7821fc99a0bc665fa213d9fcd5a/B2W-Reviews01.csv"
}
class Reviews(datasets.GeneratorBasedBuilder):
VERSION = datasets.Version("1.0.0")
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
dict(
submission_date=datasets.Value("string"),
reviewer_id=datasets.Value("string"),
product_id=datasets.Value("string"),
product_name=datasets.Value("string"),
product_brand=datasets.Value("string"),
site_category_lv1=datasets.Value("string"),
site_category_lv2=datasets.Value("string"),
review_title=datasets.Value("string"),
overall_rating=datasets.Value("int32"),
recommend_to_a_friend=datasets.Value("string"),
review_text=datasets.Value("string"),
reviewer_birth_year=datasets.Value("int32"),
reviewer_gender=datasets.Value("string"),
reviewer_state=datasets.Value("string"))),
supervised_keys=None,
homepage="https://github.com/americanas-tech/b2w-reviews01",
citation=_CITATION,
)
def _split_generators(self, dl_manager):
downloaded_files = dl_manager.download(_URLS)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"filepath": downloaded_files["train"],
}
)
]
def _generate_examples(self, filepath):
def process_row(row):
row["overall_rating"] = int(row["overall_rating"])
try:
row["reviewer_birth_year"] = int(float(row["reviewer_birth_year"]))
except ValueError:
row["reviewer_birth_year"] = None
return row
records = pd.read_csv(filepath).to_dict("records")
for idx, row in enumerate(records):
yield idx, process_row(row)