imvladikon
commited on
Commit
•
7570a7e
1
Parent(s):
4eda534
Update nemo_corpus.py
Browse files- nemo_corpus.py +6 -0
nemo_corpus.py
CHANGED
@@ -133,6 +133,7 @@ class NemoCorpusConfig(datasets.BuilderConfig):
|
|
133 |
"id": datasets.Value("string"),
|
134 |
"tokens": datasets.Sequence(datasets.Value("string")),
|
135 |
"sentence": datasets.Value("string"),
|
|
|
136 |
"ner_tags": datasets.Sequence(
|
137 |
datasets.features.ClassLabel(
|
138 |
names=['S-ANG', 'B-ANG', 'I-ANG', 'E-ANG',
|
@@ -253,6 +254,7 @@ class NemoCorpus(datasets.GeneratorBasedBuilder):
|
|
253 |
guid = 0
|
254 |
tokens = []
|
255 |
ner_tags = []
|
|
|
256 |
for line in f:
|
257 |
if line.startswith("-DOCSTART-") or line == "" or line == "\n":
|
258 |
if tokens:
|
@@ -260,21 +262,25 @@ class NemoCorpus(datasets.GeneratorBasedBuilder):
|
|
260 |
"id": str(guid),
|
261 |
"sentence": " ".join(tokens),
|
262 |
"tokens": tokens,
|
|
|
263 |
"ner_tags": ner_tags,
|
264 |
"spans": tokens_with_tags_to_spans(ner_tags, tokens)
|
265 |
}
|
266 |
guid += 1
|
267 |
tokens = []
|
268 |
ner_tags = []
|
|
|
269 |
else:
|
270 |
splits = line.split(sep)
|
271 |
tokens.append(splits[0])
|
|
|
272 |
ner_tags.append(splits[1].rstrip())
|
273 |
# last example
|
274 |
yield guid, {
|
275 |
"id": str(guid),
|
276 |
"sentence": " ".join(tokens),
|
277 |
"tokens": tokens,
|
|
|
278 |
"ner_tags": ner_tags,
|
279 |
"spans": tokens_with_tags_to_spans(ner_tags, tokens)
|
280 |
}
|
|
|
133 |
"id": datasets.Value("string"),
|
134 |
"tokens": datasets.Sequence(datasets.Value("string")),
|
135 |
"sentence": datasets.Value("string"),
|
136 |
+
"raw_tags": datasets.Sequence(datasets.Value("string")),
|
137 |
"ner_tags": datasets.Sequence(
|
138 |
datasets.features.ClassLabel(
|
139 |
names=['S-ANG', 'B-ANG', 'I-ANG', 'E-ANG',
|
|
|
254 |
guid = 0
|
255 |
tokens = []
|
256 |
ner_tags = []
|
257 |
+
raw_tags = []
|
258 |
for line in f:
|
259 |
if line.startswith("-DOCSTART-") or line == "" or line == "\n":
|
260 |
if tokens:
|
|
|
262 |
"id": str(guid),
|
263 |
"sentence": " ".join(tokens),
|
264 |
"tokens": tokens,
|
265 |
+
"raw_tags": raw_tags,
|
266 |
"ner_tags": ner_tags,
|
267 |
"spans": tokens_with_tags_to_spans(ner_tags, tokens)
|
268 |
}
|
269 |
guid += 1
|
270 |
tokens = []
|
271 |
ner_tags = []
|
272 |
+
raw_tags = []
|
273 |
else:
|
274 |
splits = line.split(sep)
|
275 |
tokens.append(splits[0])
|
276 |
+
raw_tags.append(splits[1].rstrip())
|
277 |
ner_tags.append(splits[1].rstrip())
|
278 |
# last example
|
279 |
yield guid, {
|
280 |
"id": str(guid),
|
281 |
"sentence": " ".join(tokens),
|
282 |
"tokens": tokens,
|
283 |
+
"raw_tags": raw_tags,
|
284 |
"ner_tags": ner_tags,
|
285 |
"spans": tokens_with_tags_to_spans(ner_tags, tokens)
|
286 |
}
|