|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
""" STS Benchmark """ |
|
|
|
import os |
|
|
|
import datasets |
|
|
|
_DESCRIPTION = """STS Benchmark comprises a selection of the English datasets used in the STS tasks organized in the context of SemEval between 2012 and 2017. The selection of datasets include text from image captions, news headlines and user forums.""" |
|
|
|
_HOMEPAGE = "http://ixa2.si.ehu.eus/stswiki/index.php/STSbenchmark" |
|
|
|
_URL = "http://ixa2.si.ehu.es/stswiki/images/4/48/Stsbenchmark.tar.gz" |
|
|
|
|
|
class STSBenchmark(datasets.GeneratorBasedBuilder): |
|
""" STS Benchmark """ |
|
|
|
VERSION = datasets.Version("1.0.0") |
|
|
|
BUILDER_CONFIGS = [ |
|
datasets.BuilderConfig(name="all", version=VERSION), |
|
datasets.BuilderConfig(name="news", version=VERSION), |
|
datasets.BuilderConfig(name="captions", version=VERSION), |
|
datasets.BuilderConfig(name="forums", version=VERSION), |
|
] |
|
|
|
DEFAULT_CONFIG_NAME = "all" |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=datasets.Features({ |
|
"id": datasets.Value("int32"), |
|
"sentence1": datasets.Value("string"), |
|
"sentence2": datasets.Value("string"), |
|
"score": datasets.Value("float") |
|
}), |
|
homepage=_HOMEPAGE, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
data_dir = dl_manager.download_and_extract(_URL) |
|
return [ |
|
datasets.SplitGenerator( |
|
name=str(datasets.Split.TRAIN), |
|
gen_kwargs={ |
|
"filepath": os.path.join(data_dir, "stsbenchmark/sts-train.csv"), |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=str(datasets.Split.VALIDATION), |
|
gen_kwargs={ |
|
"filepath": os.path.join(data_dir, "stsbenchmark/sts-dev.csv"), |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=str(datasets.Split.TEST), |
|
gen_kwargs={ |
|
"filepath": os.path.join(data_dir, "stsbenchmark/sts-test.csv"), |
|
}, |
|
), |
|
] |
|
|
|
def _generate_examples(self, filepath: str): |
|
with open(filepath, encoding="utf-8") as f: |
|
for i, row in enumerate(f): |
|
genre, filename, year, id_, score, sent1, sent2, *_ = row.rstrip().split("\t") |
|
genre = genre.split("-")[-1] |
|
if self.config.name == "all" or genre == self.config.name: |
|
yield i, { |
|
"id": i, |
|
"sentence1": sent1, |
|
"sentence2": sent2, |
|
"score": float(score), |
|
} |
|
|