|
import datasets |
|
|
|
from dataclasses import dataclass |
|
import csv |
|
|
|
_DESCRIPTION = '''WES: Learning Semantic Similarity from 6M Names for 1M Entities''' |
|
_CITE = '''\ |
|
@inproceedings{exr0n2022WES |
|
author={Exr0n}, |
|
title={WES: Learning Semantic Similarity from 6M Names for 1M Entities}, |
|
year={2022} |
|
} |
|
''' |
|
|
|
@dataclass |
|
class WikiEntitySimilarityConfig(datasets.BuilderConfig): |
|
"""BuilderConfig for CSV.""" |
|
threshhold: int = None |
|
path: str = None |
|
|
|
class WikiEntitySimilarity(datasets.GeneratorBasedBuilder): |
|
"""WES: Learning semantic similarity from 6M names for 1M entities""" |
|
BUILDER_CONFIG_CLASS = WikiEntitySimilarityConfig |
|
BUILDER_CONFIGS = [ |
|
WikiEntitySimilarityConfig( |
|
name='2008thresh5', |
|
description='min 5 inbound links, lowest quality', |
|
threshhold=5, |
|
path="https://huggingface.co/datasets/Exr0n/wiki-entity-similarity/resolve/main/link_synonyms-2018-thresh_5.csv" |
|
), |
|
WikiEntitySimilarityConfig( |
|
name='2008thresh10', |
|
description='min 10 inbound links, medium quality', |
|
threshhold=10, |
|
path="https://huggingface.co/datasets/Exr0n/wiki-entity-similarity/resolve/main/link_synonyms-2018-thresh_10.csv" |
|
), |
|
WikiEntitySimilarityConfig( |
|
name='2008thresh20', |
|
description='min 20 inbound links, high quality', |
|
threshhold=20, |
|
path="https://huggingface.co/datasets/Exr0n/wiki-entity-similarity/resolve/main/link_synonyms-2018-thresh_20.csv" |
|
), |
|
] |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=datasets.Features( |
|
{ |
|
'article': datasets.Value('string'), |
|
'link_text': datasets.Value('string'), |
|
} |
|
), |
|
citation=_CITE, |
|
homepage="https://github.com/Exr0nProjects/wiki-entity-similarity", |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
filepath = dl_manager.download(self.config.path) |
|
return [ datasets.SplitGenerator(name=datasets.Split.ALL, |
|
gen_kwargs={ 'filepath': filepath }) ] |
|
|
|
def _generate_examples(self, filepath): |
|
with open(filepath, 'r') as rf: |
|
reader = csv.DictReader(rf) |
|
for i, row in enumerate(reader): |
|
yield i, row |
|
|