Zeb commited on
Commit
6ee996c
1 Parent(s): af95aac

Add option to load in original files

Browse files
Files changed (1) hide show
  1. BabyLM.py +40 -20
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 == "strict_small":
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
- for filepath in filepaths:
124
- with open(filepath, encoding="utf-8") as f:
125
- is_tags = False
126
- text = ""
127
- filename = ""
128
- # Every other row contains POS tags. First row is the filename (we can't use filepath since the file path changes upon caching)
129
- for row in f:
130
- if filename == "":
131
- filename = row.strip()
132
- continue
133
- if is_tags:
134
- yield global_idx, {"text": text.strip(), "tagged_text": row.strip(), "filename": filename}
135
- global_idx += 1
136
- is_tags = False
137
- else:
138
- text = row
139
- is_tags = True
 
 
 
 
 
 
 
 
 
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