Upload encyclopaedia_britannica.py

#2
by davanstrien HF Staff - opened
Files changed (1) hide show
  1. encyclopaedia_britannica.py +76 -0
encyclopaedia_britannica.py ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ """TODO"""
15
+
16
+ import os
17
+ import pandas as pd
18
+ import datasets
19
+ from PIL import Image
20
+
21
+ # TODO: Add BibTeX citation
22
+ # Find for instance the citation on arxiv or on the dataset repo/website
23
+ _CITATION = """TODO"""
24
+
25
+
26
+ _DESCRIPTION = """\
27
+ TODO"""
28
+
29
+ _HOMEPAGE = "TODO"
30
+
31
+ _LICENSE = "Public Domain"
32
+
33
+
34
+ class EncyclopaediaBritannica(datasets.GeneratorBasedBuilder):
35
+ """TODO: Short description of my dataset."""
36
+
37
+ VERSION = datasets.Version("1.1.0")
38
+
39
+ def _info(self):
40
+
41
+ features = datasets.Features(
42
+ {
43
+ "metadata": datasets.Value("string"),
44
+ "image": datasets.Image(),
45
+ "label": datasets.ClassLabel(names=["text-only", "illustrated"]),
46
+ }
47
+ )
48
+
49
+ return datasets.DatasetInfo(
50
+ description=_DESCRIPTION,
51
+ features=features,
52
+ homepage=_HOMEPAGE,
53
+ license=_LICENSE,
54
+ citation=_CITATION,
55
+ )
56
+
57
+ def _split_generators(self, dl_manager):
58
+ df = pd.read_csv("annotations.csv", low_memory=False)
59
+ df = df[df["choice"].notna()]
60
+ df = df[["meta", "choice", "image"]]
61
+ annotations = df.to_dict(orient="records")
62
+ return [
63
+ datasets.SplitGenerator(
64
+ name=datasets.Split.TRAIN,
65
+ gen_kwargs={
66
+ "annotations": annotations,
67
+ },
68
+ ),
69
+ ]
70
+
71
+ def _generate_examples(self, annotations):
72
+ for id_, row in enumerate(annotations):
73
+ row["image"] = row.pop("image")
74
+ row["metadata"] = row.pop("meta")
75
+ row["label"] = row.pop("choice")
76
+ yield id_, row