Datasets:

Modalities:
Tabular
Text
Formats:
parquet
Languages:
English
Libraries:
Datasets
pandas
License:
on_the_books / on_the_books.py
davanstrien's picture
davanstrien HF staff
Update on_the_books.py
67b651c
raw
history blame
2.61 kB
# coding=utf-8
# Copyright 2021 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.
"""On the Books Dataset"""
import csv
import datasets
_CITATION = """TODO"""
_DESCRIPTION = """\
This file is the training set that was used to train an algorithm to identify Jim Crow laws.
It contains laws that are labeled as "Jim Crow" (jim_crow=1) or "Not Jim Crow" (jim_crow=0).
The source of the determination is also provided.
"""
_HOMEPAGE = "https://onthebooks.lib.unc.edu/"
_LICENSE = "CC BY 3.0"
_URL = "https://cdr.lib.unc.edu/downloads/76537b20b?locale=en"
class OnTheBooks(datasets.GeneratorBasedBuilder):
VERSION = datasets.Version("1.1.0")
def _info(self):
features = datasets.Features(
{
"id": datasets.Value("string"),
"source": datasets.Value("string"),
"jim_crow": datasets.ClassLabel(names=["no_jim_crow", "jim_crow"]),
"type": datasets.Value("string"),
"chapter_num": datasets.Value("int32"),
"section_num": datasets.Value("int32"),
"chapter_text": datasets.Value("string"),
"section_text": datasets.Value("string"),
}
)
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=features,
supervised_keys=None,
homepage=_HOMEPAGE,
license=_LICENSE,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
"""Returns SplitGenerators."""
data_file = dl_manager.download(_URL)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"filepath": data_file,
},
),
]
def _generate_examples(self, filepath):
"""Yields examples as (key, example) tuples."""
with open(filepath, encoding="utf-8") as f:
reader = csv.DictReader(f)
yield from enumerate(reader)