mnemlaghi commited on
Commit
107e4e0
1 Parent(s): fc6aba1

add loading script

Browse files
Files changed (1) hide show
  1. widdd.py +96 -0
widdd.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ """Wikidata descriptions as triplets for Named Entity Disambiguation"""
16
+
17
+ import json
18
+ import datasets
19
+
20
+
21
+ _CITATION = """\
22
+ """
23
+
24
+ _DESCRIPTION = """\
25
+ WiDDD stands for WIkiData Disambig with Descriptions. The former dataset comes from [Cetoli & al](https://arxiv.org/pdf/1810.09164.pdf) paper, and is aimed at solving Named Entity Disambiguation. This datasets tries to extract relevant information from entities descriptions only, instead of working with graphs. In order to do so, we mapped every Wikidata id (correct id and wrong id) in the original paper with its WikiData description. If not found, row is discarded for this version.
26
+ """
27
+
28
+ _HOMEPAGE = ""
29
+
30
+ _LICENSE = "Apache License 2.0"
31
+
32
+ _URLs = {
33
+ "train": "wikidatadescs_train.jsonl",
34
+ "dev": "wikidatadescs_dev.jsonl",
35
+ "test": "wikidatadescs_test.jsonl"
36
+ }
37
+
38
+
39
+ class WidddConfig(datasets.BuilderConfig):
40
+ """BuilderConfig for Widdd."""
41
+
42
+ def __init__(self, **kwargs):
43
+ """BuilderConfig for Widdd.
44
+ Args:
45
+ **kwargs: keyword arguments forwarded to super.
46
+ """
47
+ super(WidddConfig, self).__init__(**kwargs)
48
+
49
+
50
+ class Widdd(datasets.GeneratorBasedBuilder):
51
+ """Wikidata Disamb with Descriptions Dataset."""
52
+
53
+ VERSION = datasets.Version("1.0.0")
54
+
55
+ BUILDER_CONFIGS = [
56
+ WidddConfig(
57
+ name="widdd", version=VERSION, description="Wikidata Disamb with Descriptions Dataset, as triplets."
58
+ ),
59
+ ]
60
+
61
+ def _info(self):
62
+ features = datasets.Features(
63
+ {
64
+ "exmple_id": datasets.Value("int32"),
65
+ "string": datasets.Value("string"),
66
+ "text": datasets.Value("string"),
67
+ "correct_id": datasets.Value("string"),
68
+ "wrong_id": datasets.Value("string"),
69
+ "correct_description": datasets.Value("string"),
70
+ "wrong_description": datasets.Value("string")
71
+ }
72
+ )
73
+ return datasets.DatasetInfo(
74
+ description=_DESCRIPTION,
75
+ features=features,
76
+ supervised_keys=None,
77
+ homepage=_HOMEPAGE,
78
+ license=_LICENSE,
79
+ citation=_CITATION,
80
+ )
81
+
82
+ def _split_generators(self, dl_manager):
83
+ """Returns SplitGenerators."""
84
+ downloaded_files = dl_manager.download(my_urls)
85
+ return [
86
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath":downloaded_files["train"]},),
87
+ datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath":downloaded_files["test"]},),
88
+ datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath":downloaded_files["dev"]},)
89
+ ]
90
+
91
+ def _generate_examples(self, filepath, files):
92
+ """Yields examples."""
93
+ with open(filepath, encoding = "utf8") as fp:
94
+ for l in fp:
95
+ d = json.loads(l.decode('utf8')
96
+ yield d