w-nicole
commited on
Commit
•
cb86611
1
Parent(s):
78636f9
loading files
Browse files- childes_data.py +112 -0
childes_data.py
ADDED
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# The majority of this file was taken and adapted from this file, on 6/3/21: https://github.com/huggingface/datasets/blob/master/datasets/snli/snli.py
|
2 |
+
|
3 |
+
|
4 |
+
# License reproduced from the original code:
|
5 |
+
|
6 |
+
# coding=utf-8
|
7 |
+
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
8 |
+
#
|
9 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
10 |
+
# you may not use this file except in compliance with the License.
|
11 |
+
# You may obtain a copy of the License at
|
12 |
+
#
|
13 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
14 |
+
#
|
15 |
+
# Unless required by applicable law or agreed to in writing, software
|
16 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
17 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
18 |
+
# See the License for the specific language governing permissions and
|
19 |
+
# limitations under the License.
|
20 |
+
|
21 |
+
|
22 |
+
# The changes to the file include:
|
23 |
+
# Changing all of the parameters to reflect childes data and information
|
24 |
+
# Changing the dl_manager to be essentially unused in split_generators and loading from text files instead
|
25 |
+
# Changing generate_examples to load directly from text files and clean the lines of text.
|
26 |
+
|
27 |
+
|
28 |
+
import datasets
|
29 |
+
import os
|
30 |
+
|
31 |
+
class Childes(datasets.GeneratorBasedBuilder):
|
32 |
+
|
33 |
+
BUILDER_CONFIGS = [
|
34 |
+
datasets.BuilderConfig(
|
35 |
+
name="childes_data",
|
36 |
+
version=datasets.Version("1.0.0", ""),
|
37 |
+
description="Childes language modeling dataset",
|
38 |
+
)
|
39 |
+
]
|
40 |
+
|
41 |
+
|
42 |
+
|
43 |
+
def _info(self):
|
44 |
+
|
45 |
+
citation_text = """\\
|
46 |
+
@article{sanchez2019childes,
|
47 |
+
title={childes-db: A flexible and reproducible interface to the child language data exchange system},
|
48 |
+
author={Sanchez, Alessandro and Meylan, Stephan C and Braginsky, Mika and MacDonald, Kyle E and Yurovsky, Daniel and Frank, Michael C},
|
49 |
+
journal={Behavior research methods},
|
50 |
+
volume={51},
|
51 |
+
number={4},
|
52 |
+
pages={1928--1941},
|
53 |
+
year={2019},
|
54 |
+
publisher={Springer}}
|
55 |
+
"""
|
56 |
+
|
57 |
+
|
58 |
+
return datasets.DatasetInfo(
|
59 |
+
description = "CHILDES data for language modeling",
|
60 |
+
citation = citation_text,
|
61 |
+
# 6/3 Citation info is directly taken from Google Scholar
|
62 |
+
features=datasets.Features(
|
63 |
+
{
|
64 |
+
"text": datasets.Value("string"),
|
65 |
+
}
|
66 |
+
),
|
67 |
+
# No default supervised_keys (as we have to pass both premise
|
68 |
+
# and hypothesis as input).
|
69 |
+
homepage="https://childes-db.stanford.edu/",
|
70 |
+
)
|
71 |
+
|
72 |
+
|
73 |
+
def _split_generators(self, download_helper):
|
74 |
+
|
75 |
+
paths = {
|
76 |
+
'train' : 'https://www.dropbox.com/s/dl/i282barrzlari08/train.txt?dl=1',
|
77 |
+
'val' : 'https://www.dropbox.com/s/gx0rngo3v5mvlcf/validation.txt?dl=1',
|
78 |
+
}
|
79 |
+
|
80 |
+
list_datasets = []
|
81 |
+
|
82 |
+
phases = ['train', 'val']
|
83 |
+
dataset_names = [
|
84 |
+
datasets.Split.TRAIN,
|
85 |
+
datasets.Split.VALIDATION,
|
86 |
+
]
|
87 |
+
|
88 |
+
for phase, phase_name in zip(phases, dataset_names):
|
89 |
+
|
90 |
+
path = paths[phase]
|
91 |
+
this_true_path = download_helper.download_and_extract(path)
|
92 |
+
|
93 |
+
this_dataset = datasets.SplitGenerator(
|
94 |
+
name=phase_name, gen_kwargs={"file_path": this_true_path}
|
95 |
+
)
|
96 |
+
|
97 |
+
list_datasets.append(this_dataset)
|
98 |
+
|
99 |
+
|
100 |
+
return list_datasets
|
101 |
+
|
102 |
+
def _generate_examples(self, file_path):
|
103 |
+
|
104 |
+
clean_text = lambda s : s.strip('\
|
105 |
+
').strip('[CHI] ')
|
106 |
+
|
107 |
+
with open(file_path, 'r') as f:
|
108 |
+
for idx, line in enumerate(map(clean_text, f.readlines())):
|
109 |
+
yield idx, {"text" : line}
|
110 |
+
|
111 |
+
|
112 |
+
|