encyclopedia_britannica / encyclopedia_britannica.py
davanstrien's picture
davanstrien HF Staff
Update encyclopedia_britannica.py
8548252
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""TODO"""
import os
import pandas as pd
import datasets
from PIL import Image
# TODO: Add BibTeX citation
# Find for instance the citation on arxiv or on the dataset repo/website
_CITATION = """TODO"""
_DESCRIPTION = """\
TODO"""
_HOMEPAGE = "TODO"
_LICENSE = "Public Domain"
class EncyclopaediaBritannica(datasets.GeneratorBasedBuilder):
"""TODO: Short description of my dataset."""
VERSION = datasets.Version("1.1.0")
def _info(self):
features = datasets.Features(
{
"metadata": datasets.Value("string"),
"image": datasets.Value("string"),
"label": datasets.ClassLabel(names=["text-only", "illustrated"]),
}
)
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=features,
homepage=_HOMEPAGE,
license=_LICENSE,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
csv = dl_manager.download("annotations.csv")
df = pd.read_csv(csv, low_memory=False)
df = df[df["choice"].notna()]
df = df[["meta", "choice", "image"]]
annotations = df.to_dict(orient="records")
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"annotations": annotations,
},
),
]
def _generate_examples(self, annotations):
for id_, row in enumerate(annotations):
row["image"] = row.pop("image")
row["metadata"] = row.pop("meta")
row["label"] = row.pop("choice")
yield id_, row