File size: 2,389 Bytes
b261299
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
74
75
76
77
"""STAN small dataset by Bansal et al.."""

import datasets
import pandas as pd
import pickle

_CITATION = """

@misc{bansal2015deep,

      title={Towards Deep Semantic Analysis Of Hashtags}, 

      author={Piyush Bansal and Romil Bansal and Vasudeva Varma},

      year={2015},

      eprint={1501.03210},

      archivePrefix={arXiv},

      primaryClass={cs.IR}

}

"""

_DESCRIPTION = """

Manually Annotated Stanford Sentiment Analysis Dataset by Bansal et al..

"""
_URLS = {
    "test": "https://github.com/prashantkodali/HashSet/raw/master/datasets/stan-small-bansal_et_al.pkl"
}

class StanSmall(datasets.GeneratorBasedBuilder):

    VERSION = datasets.Version("1.0.0")

    def _info(self):
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=datasets.Features(
                {
                    "index": datasets.Value("int32"),
                    "hashtag": datasets.Value("string"),
                    "segmentation": datasets.Value("string"),
                    "alternatives": datasets.Sequence(
                        {
                            "segmentation": datasets.Value("string")
                        }
                    )
                }
            ),
            supervised_keys=None,
            homepage="https://github.com/mounicam/hashtag_master",
            citation=_CITATION,
        )

    def _split_generators(self, dl_manager):
        downloaded_files = dl_manager.download(_URLS)
        return [
            datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"] }),
        ]

    def _generate_examples(self, filepath):

        def get_segmentation(row):
            return row["goldtruths"][0]
        
        def get_alternatives(row):
            segmentations = [{
                "segmentation": x
            } for x in row["goldtruths"]]

            return segmentations[1:]

        with open(filepath, 'rb') as f:
            records = pickle.load(f)
        records = records.to_dict("records")
        for idx, row in enumerate(records):
            yield idx, {
                "index": idx,
                "hashtag": row["hashtags"],
                "segmentation": get_segmentation(row),
                "alternatives": get_alternatives(row)
            }