ramybaly
commited on
Commit
·
0f10ef1
1
Parent(s):
95e4d02
fixed fine-grained ner labels format
Browse files- prepare_data.py +5 -5
prepare_data.py
CHANGED
|
@@ -4,7 +4,7 @@ import pickle
|
|
| 4 |
|
| 5 |
|
| 6 |
def main():
|
| 7 |
-
|
| 8 |
id2label_fine = {int(i): tag for i, tag in json.load(open('./id2fine_tags.json', 'r')).items()}
|
| 9 |
|
| 10 |
files = glob.glob('./*json')
|
|
@@ -19,16 +19,16 @@ def main():
|
|
| 19 |
with open(file.replace('.json', '.txt'), 'w') as f:
|
| 20 |
for sentence in sentences:
|
| 21 |
sentence = json.loads(sentence)
|
|
|
|
| 22 |
tokens = sentence['tokens']
|
| 23 |
ner_tags_ids = sentence['coarse_tags']
|
| 24 |
ner_tags_fine_ids = sentence['fine_tags']
|
| 25 |
|
| 26 |
-
|
| 27 |
ner_tags_fine = [id2label_fine[t] for t in ner_tags_fine_ids]
|
| 28 |
|
| 29 |
-
for
|
| 30 |
-
f.write(f'{
|
| 31 |
-
|
| 32 |
f.write('\n')
|
| 33 |
|
| 34 |
|
|
|
|
| 4 |
|
| 5 |
|
| 6 |
def main():
|
| 7 |
+
id2label_coarse = {int(i): tag for i, tag in json.load(open('./id2coarse_tags.json', 'r')).items()}
|
| 8 |
id2label_fine = {int(i): tag for i, tag in json.load(open('./id2fine_tags.json', 'r')).items()}
|
| 9 |
|
| 10 |
files = glob.glob('./*json')
|
|
|
|
| 19 |
with open(file.replace('.json', '.txt'), 'w') as f:
|
| 20 |
for sentence in sentences:
|
| 21 |
sentence = json.loads(sentence)
|
| 22 |
+
|
| 23 |
tokens = sentence['tokens']
|
| 24 |
ner_tags_ids = sentence['coarse_tags']
|
| 25 |
ner_tags_fine_ids = sentence['fine_tags']
|
| 26 |
|
| 27 |
+
ner_tags_coarse = [id2label_coarse[t] for t in ner_tags_ids]
|
| 28 |
ner_tags_fine = [id2label_fine[t] for t in ner_tags_fine_ids]
|
| 29 |
|
| 30 |
+
for tok, tc, tf in zip(tokens, ner_tags_coarse, ner_tags_fine):
|
| 31 |
+
f.write(f'{tok}\t{tc}\t{tf}\n')
|
|
|
|
| 32 |
f.write('\n')
|
| 33 |
|
| 34 |
|