0

我想获得 deeppavlov NER 标记。现在我有这个代码:

from deeppavlov import configs, build_model
ner_model = build_model(configs.ner.ner_ontonotes_bert_mult, download=True)
data_list = ["New Zealand's Prime Minister Jacinda Ardern has announced a nationwide lockdown after the country confirmed one coronavirus case -- the first locally transmitted Covid-19 case in the community since February.", 
             "Finmark is now a remote-only company, with 33 employees across the United States, England and Pakistan.", 
             "As he slipped through the kelp forest to the bottom of the Atlantic Ocean, Kamau Sadiki's eyes hooked onto something resembling the item he and fellow divers had been searching for."]
for d in data_list:
  ner_model([d])

但是标记看起来是这样的:

[[['New', "Zealand's", 'Prime', 'Minister', 'Jacinda', 'Ardern', 'has', 'announced', 'a', 'nationwide', 'lockdown', 'after', 'the', 'country', 'confirmed', 'one', 'coronavirus', 'case', '-', '-', 'the', 'first', 'locally', 'transmitted', 'Covid', '-', '19', 'case', 'in', 'the', 'community', 'since', 'February', '.']], [['B-GPE', 'I-GPE', 'O', 'O', 'B-PERSON', 'I-PERSON', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'B-CARDINAL', 'O', 'O', 'O', 'O', 'O', 'B-ORDINAL', 'O', 'O', 'B-PRODUCT', 'I-PRODUCT', 'I-PRODUCT', 'O', 'O', 'O', 'O', 'O', 'B-DATE', 'O']]]
[[['Finmark', 'is', 'now', 'a', 'remote', '-', 'only', 'company', ',', 'with', '33', 'employees', 'across', 'the', 'United', 'States', ',', 'England', 'and', 'Pakistan', '.']], [['B-ORG', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'B-CARDINAL', 'O', 'O', 'B-GPE', 'I-GPE', 'I-GPE', 'O', 'B-GPE', 'O', 'B-GPE', 'O']]]
[[['As', 'he', 'slipped', 'through', 'the', 'kelp', 'forest', 'to', 'the', 'bottom', 'of', 'the', 'Atlantic', 'Ocean', ',', 'Kamau', "Sadiki's", 'eyes', 'hooked', 'onto', 'something', 'resembling', 'the', 'item', 'he', 'and', 'fellow', 'divers', 'had', 'been', 'searching', 'for', '.']], [['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'B-LOC', 'I-LOC', 'I-LOC', 'O', 'B-PERSON', 'I-PERSON', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O']]]

我想要一种python字典。所以我尝试了这个:

for d in data_list:
  ner_model(zip(d))

有错误TypeError: 'zip' object is not subscriptable

和这个:

for d in data_list:
  ner_model(dict(d))

有错误ValueError: dictionary update sequence element #0 has length 1; 2 is required

有没有办法将 deeppavlov 标记保存为 python 字典?

更新。我想看到这样的输出:

{['Finmark', 'is', 'now', 'a', 'remote', '-', 'only', 'company', ',', 'with', '33', 'employees', 'across', 'the', 'United', 'States', ',', 'England', 'and', 'Pakistan', '.'] : ['B-ORG', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'B-CARDINAL', 'O', 'O', 'B-GPE', 'I-GPE', 'I-GPE', 'O', 'B-GPE', 'O', 'B-GPE', 'O']}
4

0 回答 0