Deeppavlov markup as a python dictionary

80 Views Asked by At

I would like to get the deeppavlov NER markup. Now I have this code:

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])

But the markup looks this:

[[['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']]]

I would like to have a kind of python dictionary. So I tried this:

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

With error TypeError: 'zip' object is not subscriptable

And this:

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

With error ValueError: dictionary update sequence element #0 has length 1; 2 is required

Is there a way to save the deeppavlov markup as python dictionary?

UPDATE. I would like to see such output:

{['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']}
0

There are 0 best solutions below