File size: 2,916 Bytes
d91631b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48ef2cd
d91631b
 
 
 
 
 
 
30a0c9e
0d9e574
d91631b
0df8277
d91631b
15c6031
d91631b
 
 
15c6031
d91631b
 
 
 
 
 
 
 
 
 
 
 
 
 
30a0c9e
199d037
30a0c9e
6bbffc9
0df1404
6bbffc9
 
44ebf78
d91631b
44ebf78
d91631b
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""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)