Datasets:
Tasks:
Token Classification
Sub-tasks:
named-entity-recognition
Languages:
German
Size:
1M<n<10M
ArXiv:
DOI:
License:
elenanereiss
commited on
Commit
•
52f6479
1
Parent(s):
16ad7e1
Update german-ler.py
Browse files- 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 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|