elenanereiss commited on
Commit
52f6479
1 Parent(s): 16ad7e1

Update german-ler.py

Browse files
Files changed (1) hide show
  1. german-ler.py +30 -32
german-ler.py CHANGED
@@ -143,37 +143,20 @@ class German_LER(datasets.GeneratorBasedBuilder):
143
 
144
  def _generate_examples(self, datapath, split):
145
  sentence_counter = 0
146
- for filepath in self.config.filepaths:
147
- filepath = os.path.join(datapath, filepath)
148
- with open(filepath, encoding="utf-8") as f:
149
- current_words = []
150
- current_labels = []
151
- for row in f:
152
- row = row.rstrip()
153
- row_split = row.split()
154
- if len(row_split) == 2:
155
- token, label = row_split
156
- current_words.append(token)
157
- current_labels.append(label)
158
- else:
159
- if not current_words:
160
- continue
161
- assert len(current_words) == len(current_labels), "word len doesnt match label length"
162
- sentence = (
163
- sentence_counter,
164
- {
165
- "id": str(sentence_counter),
166
- "tokens": current_words,
167
- "ner_tags": current_labels,
168
- },
169
- )
170
- sentence_counter += 1
171
- current_words = []
172
- current_labels = []
173
- yield sentence
174
-
175
- # if something remains:
176
- if current_words:
177
  sentence = (
178
  sentence_counter,
179
  {
@@ -182,4 +165,19 @@ class German_LER(datasets.GeneratorBasedBuilder):
182
  "ner_tags": current_labels,
183
  },
184
  )
185
- yield sentence
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
 
144
  def _generate_examples(self, datapath, split):
145
  sentence_counter = 0
146
+ with open(datapath, encoding="utf-8") as f:
147
+ current_words = []
148
+ current_labels = []
149
+ for row in f:
150
+ row = row.rstrip()
151
+ row_split = row.split()
152
+ if len(row_split) == 2:
153
+ token, label = row_split
154
+ current_words.append(token)
155
+ current_labels.append(label)
156
+ else:
157
+ if not current_words:
158
+ continue
159
+ assert len(current_words) == len(current_labels), "word len doesnt match label length"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
  sentence = (
161
  sentence_counter,
162
  {
 
165
  "ner_tags": current_labels,
166
  },
167
  )
168
+ sentence_counter += 1
169
+ current_words = []
170
+ current_labels = []
171
+ yield sentence
172
+
173
+ # if something remains:
174
+ if current_words:
175
+ sentence = (
176
+ sentence_counter,
177
+ {
178
+ "id": str(sentence_counter),
179
+ "tokens": current_words,
180
+ "ner_tags": current_labels,
181
+ },
182
+ )
183
+ yield sentence