Datasets:
Convert to Parquet format and remove loading script
Browse filesDataset loading scripts are no longer supported by the `datasets` library (v3+).
This PR:
- Converts all splits (train, test, validation) to Parquet format
- Removes the `ptb_text_only.py` loading script
After this change, the dataset can be loaded with:
```python
from datasets import load_dataset
ds = load_dataset('ptb-text-only/ptb_text_only')
```
No `trust_remote_code=True` needed.
data/test-00000-of-00001.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5078fcc161548ad940c63610099ebfc9af25eca7bf7ec274900d0aa153484cc1
|
| 3 |
+
size 257503
|
data/train-00000-of-00001.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a86b8f1cdd524640b97b71da4a1ebdae60aaeb61132dc4c457db5f868d8e5db6
|
| 3 |
+
size 2915174
|
data/validation-00000-of-00001.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4373b0c0cafc169366b8f76e96a9c9917b9b1cd003fecdc82326c7da14c88b8f
|
| 3 |
+
size 232009
|
ptb_text_only.py
DELETED
|
@@ -1,146 +0,0 @@
|
|
| 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 |
-
"""
|
| 16 |
-
Load the Penn Treebank dataset.
|
| 17 |
-
|
| 18 |
-
This is the Penn Treebank Project: Release 2 CDROM, featuring a million words of 1989 Wall
|
| 19 |
-
Street Journal material.
|
| 20 |
-
"""
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
import datasets
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
# TODO: Add BibTeX citation
|
| 27 |
-
# Find for instance the citation on arxiv or on the dataset repo/website
|
| 28 |
-
_CITATION = """\
|
| 29 |
-
@article{marcus-etal-1993-building,
|
| 30 |
-
title = "Building a Large Annotated Corpus of {E}nglish: The {P}enn {T}reebank",
|
| 31 |
-
author = "Marcus, Mitchell P. and
|
| 32 |
-
Santorini, Beatrice and
|
| 33 |
-
Marcinkiewicz, Mary Ann",
|
| 34 |
-
journal = "Computational Linguistics",
|
| 35 |
-
volume = "19",
|
| 36 |
-
number = "2",
|
| 37 |
-
year = "1993",
|
| 38 |
-
url = "https://www.aclweb.org/anthology/J93-2004",
|
| 39 |
-
pages = "313--330",
|
| 40 |
-
}
|
| 41 |
-
"""
|
| 42 |
-
|
| 43 |
-
# TODO: Add description of the dataset here
|
| 44 |
-
# You can copy an official description
|
| 45 |
-
_DESCRIPTION = """\
|
| 46 |
-
This is the Penn Treebank Project: Release 2 CDROM, featuring a million words of 1989 Wall Street Journal material. This corpus has been annotated for part-of-speech (POS) information. In addition, over half of it has been annotated for skeletal syntactic structure.
|
| 47 |
-
"""
|
| 48 |
-
|
| 49 |
-
# TODO: Add a link to an official homepage for the dataset here
|
| 50 |
-
_HOMEPAGE = "https://catalog.ldc.upenn.edu/LDC99T42"
|
| 51 |
-
|
| 52 |
-
# TODO: Add the licence for the dataset here if you can find it
|
| 53 |
-
_LICENSE = "LDC User Agreement for Non-Members"
|
| 54 |
-
|
| 55 |
-
# TODO: Add link to the official dataset URLs here
|
| 56 |
-
# The HuggingFace dataset library don't host the datasets but only point to the original files
|
| 57 |
-
# This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
|
| 58 |
-
_URL = "https://raw.githubusercontent.com/wojzaremba/lstm/master/data/"
|
| 59 |
-
_TRAINING_FILE = "ptb.train.txt"
|
| 60 |
-
_DEV_FILE = "ptb.valid.txt"
|
| 61 |
-
_TEST_FILE = "ptb.test.txt"
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
class PtbTextOnlyConfig(datasets.BuilderConfig):
|
| 65 |
-
"""BuilderConfig for PtbTextOnly"""
|
| 66 |
-
|
| 67 |
-
def __init__(self, **kwargs):
|
| 68 |
-
"""BuilderConfig PtbTextOnly.
|
| 69 |
-
Args:
|
| 70 |
-
**kwargs: keyword arguments forwarded to super.
|
| 71 |
-
"""
|
| 72 |
-
super(PtbTextOnlyConfig, self).__init__(**kwargs)
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
class PtbTextOnly(datasets.GeneratorBasedBuilder):
|
| 76 |
-
"""Load the Penn Treebank dataset."""
|
| 77 |
-
|
| 78 |
-
VERSION = datasets.Version("1.1.0")
|
| 79 |
-
|
| 80 |
-
# This is an example of a dataset with multiple configurations.
|
| 81 |
-
# If you don't want/need to define several sub-sets in your dataset,
|
| 82 |
-
# just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
|
| 83 |
-
|
| 84 |
-
# If you need to make complex sub-parts in the datasets with configurable options
|
| 85 |
-
# You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
|
| 86 |
-
# BUILDER_CONFIG_CLASS = MyBuilderConfig
|
| 87 |
-
|
| 88 |
-
# You will be able to load one or the other configurations in the following list with
|
| 89 |
-
# data = datasets.load_dataset('my_dataset', 'first_domain')
|
| 90 |
-
# data = datasets.load_dataset('my_dataset', 'second_domain')
|
| 91 |
-
BUILDER_CONFIGS = [
|
| 92 |
-
PtbTextOnlyConfig(
|
| 93 |
-
name="penn_treebank",
|
| 94 |
-
version=VERSION,
|
| 95 |
-
description="Load the Penn Treebank dataset",
|
| 96 |
-
),
|
| 97 |
-
]
|
| 98 |
-
|
| 99 |
-
def _info(self):
|
| 100 |
-
features = datasets.Features({"sentence": datasets.Value("string")})
|
| 101 |
-
return datasets.DatasetInfo(
|
| 102 |
-
# This is the description that will appear on the datasets page.
|
| 103 |
-
description=_DESCRIPTION,
|
| 104 |
-
# This defines the different columns of the dataset and their types
|
| 105 |
-
features=features, # Here we define them above because they are different between the two configurations
|
| 106 |
-
# If there's a common (input, target) tuple from the features,
|
| 107 |
-
# specify them here. They'll be used if as_supervised=True in
|
| 108 |
-
# builder.as_dataset.
|
| 109 |
-
supervised_keys=None,
|
| 110 |
-
# Homepage of the dataset for documentation
|
| 111 |
-
homepage=_HOMEPAGE,
|
| 112 |
-
# License for the dataset if available
|
| 113 |
-
license=_LICENSE,
|
| 114 |
-
# Citation for the dataset
|
| 115 |
-
citation=_CITATION,
|
| 116 |
-
)
|
| 117 |
-
|
| 118 |
-
def _split_generators(self, dl_manager):
|
| 119 |
-
"""Returns SplitGenerators."""
|
| 120 |
-
# TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
|
| 121 |
-
# If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
|
| 122 |
-
|
| 123 |
-
# dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLs
|
| 124 |
-
# It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
|
| 125 |
-
# By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
|
| 126 |
-
my_urls = {
|
| 127 |
-
"train": f"{_URL}{_TRAINING_FILE}",
|
| 128 |
-
"dev": f"{_URL}{_DEV_FILE}",
|
| 129 |
-
"test": f"{_URL}{_TEST_FILE}",
|
| 130 |
-
}
|
| 131 |
-
data_dir = dl_manager.download_and_extract(my_urls)
|
| 132 |
-
return [
|
| 133 |
-
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": data_dir["train"]}),
|
| 134 |
-
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": data_dir["test"]}),
|
| 135 |
-
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": data_dir["dev"]}),
|
| 136 |
-
]
|
| 137 |
-
|
| 138 |
-
def _generate_examples(self, filepath):
|
| 139 |
-
"""Yields examples."""
|
| 140 |
-
# TODO: This method will receive as arguments the `gen_kwargs` defined in the previous `_split_generators` method.
|
| 141 |
-
# It is in charge of opening the given file and yielding (key, example) tuples from the dataset
|
| 142 |
-
# The key is not important, it's more here for legacy reason (legacy from tfds)
|
| 143 |
-
with open(filepath, encoding="utf-8") as f:
|
| 144 |
-
for id_, line in enumerate(f):
|
| 145 |
-
line = line.strip()
|
| 146 |
-
yield id_, {"sentence": line}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|