Zeb
commited on
Commit
·
6ee996c
1
Parent(s):
af95aac
Add option to load in original files
Browse files
BabyLM.py
CHANGED
|
@@ -26,14 +26,24 @@ filenames = [
|
|
| 26 |
class BabyLM(datasets.GeneratorBasedBuilder):
|
| 27 |
|
| 28 |
BUILDER_CONFIGS = [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
datasets.BuilderConfig(
|
| 30 |
name="strict_small",
|
| 31 |
-
description="Small version of the dataset with 10M words",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
version="1.0.0",
|
| 33 |
),
|
| 34 |
datasets.BuilderConfig(
|
| 35 |
name="strict",
|
| 36 |
-
description="Full version of the dataset with 100M words",
|
| 37 |
version="1.0.0",
|
| 38 |
),
|
| 39 |
datasets.BuilderConfig(
|
|
@@ -71,12 +81,14 @@ class BabyLM(datasets.GeneratorBasedBuilder):
|
|
| 71 |
Returns data for different splits
|
| 72 |
"""
|
| 73 |
|
| 74 |
-
if self.config.name
|
| 75 |
train_data_dir = "10M"
|
| 76 |
else:
|
| 77 |
train_data_dir = "100M"
|
| 78 |
if 'gold' in self.config.name:
|
| 79 |
folder = 'tagged_gold'
|
|
|
|
|
|
|
| 80 |
else:
|
| 81 |
folder = 'tagged'
|
| 82 |
|
|
@@ -120,20 +132,28 @@ class BabyLM(datasets.GeneratorBasedBuilder):
|
|
| 120 |
|
| 121 |
global_idx = 0
|
| 122 |
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
class BabyLM(datasets.GeneratorBasedBuilder):
|
| 27 |
|
| 28 |
BUILDER_CONFIGS = [
|
| 29 |
+
datasets.BuilderConfig(
|
| 30 |
+
name="original_strict_small",
|
| 31 |
+
description="Small version of the dataset with 10M words, not cleaned",
|
| 32 |
+
version="1.0.0",
|
| 33 |
+
),
|
| 34 |
datasets.BuilderConfig(
|
| 35 |
name="strict_small",
|
| 36 |
+
description="Small version of the dataset with 10M words, cleaned",
|
| 37 |
+
version="1.0.0",
|
| 38 |
+
),
|
| 39 |
+
datasets.BuilderConfig(
|
| 40 |
+
name="original_strict",
|
| 41 |
+
description="Full version of the dataset with 10M words, not cleaned",
|
| 42 |
version="1.0.0",
|
| 43 |
),
|
| 44 |
datasets.BuilderConfig(
|
| 45 |
name="strict",
|
| 46 |
+
description="Full version of the dataset with 100M words, cleaned",
|
| 47 |
version="1.0.0",
|
| 48 |
),
|
| 49 |
datasets.BuilderConfig(
|
|
|
|
| 81 |
Returns data for different splits
|
| 82 |
"""
|
| 83 |
|
| 84 |
+
if "strict_small" in self.config.name:
|
| 85 |
train_data_dir = "10M"
|
| 86 |
else:
|
| 87 |
train_data_dir = "100M"
|
| 88 |
if 'gold' in self.config.name:
|
| 89 |
folder = 'tagged_gold'
|
| 90 |
+
elif 'original' in self.config.name:
|
| 91 |
+
folder = 'original'
|
| 92 |
else:
|
| 93 |
folder = 'tagged'
|
| 94 |
|
|
|
|
| 132 |
|
| 133 |
global_idx = 0
|
| 134 |
|
| 135 |
+
if 'original' in self.config.name:
|
| 136 |
+
for filepath in filepaths:
|
| 137 |
+
with open(filepath, encoding="utf-8") as f:
|
| 138 |
+
for line in f:
|
| 139 |
+
yield global_idx, {"text": line.strip(), "filename": '', 'tagged_text': line.strip()}
|
| 140 |
+
global_idx += 1
|
| 141 |
+
|
| 142 |
+
else:
|
| 143 |
+
for filepath in filepaths:
|
| 144 |
+
with open(filepath, encoding="utf-8") as f:
|
| 145 |
+
is_tags = False
|
| 146 |
+
text = ""
|
| 147 |
+
filename = ""
|
| 148 |
+
# Every other row contains POS tags. First row is the filename (we can't use filepath since the file path changes upon caching)
|
| 149 |
+
for row in f:
|
| 150 |
+
if filename == "":
|
| 151 |
+
filename = row.strip()
|
| 152 |
+
continue
|
| 153 |
+
if is_tags:
|
| 154 |
+
yield global_idx, {"text": text.strip(), "tagged_text": row.strip(), "filename": filename}
|
| 155 |
+
global_idx += 1
|
| 156 |
+
is_tags = False
|
| 157 |
+
else:
|
| 158 |
+
text = row
|
| 159 |
+
is_tags = True
|