ramybaly commited on
Commit
0f10ef1
·
1 Parent(s): 95e4d02

fixed fine-grained ner labels format

Browse files
Files changed (1) hide show
  1. prepare_data.py +5 -5
prepare_data.py CHANGED
@@ -4,7 +4,7 @@ import pickle
4
 
5
 
6
  def main():
7
- id2label = {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,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
- ner_tags = [id2label[t] for t in ner_tags_ids]
27
  ner_tags_fine = [id2label_fine[t] for t in ner_tags_fine_ids]
28
 
29
- for token, tag, tag_fine in zip(tokens, ner_tags, ner_tags_fine):
30
- f.write(f'{token}\t{tag}\t{tag_fine}\n')
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