Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while running Named Entity Recognition #97

Open
Sachit1137 opened this issue Jul 16, 2020 · 1 comment
Open

Error while running Named Entity Recognition #97

Sachit1137 opened this issue Jul 16, 2020 · 1 comment

Comments

@Sachit1137
Copy link

Sachit1137 commented Jul 16, 2020

I tried using SciBERT for NER using the following command-

from transformers import *

tokenizer = AutoTokenizer.from_pretrained('allenai/scibert_scivocab_uncased')
model = AutoModel.from_pretrained('allenai/scibert_scivocab_uncased')

nlp = pipeline('ner',model = model,tokenizer=tokenizer)
nlp('Clinical features of culture-proven Mycoplasma pneumoniae infections at King Abdulaziz University Hospital, Jeddah, Saudi Arabia')

While running it on a sample sentence, I get the following error-
Traceback (most recent call last):
File "", line 1, in
File "/python3.6/site-packages/transformers/pipelines.py", line 927, in call
for idx, label_idx in enumerate(labels_idx)
File "/python3.6/site-packages/transformers/pipelines.py", line 928, in
if self.model.config.id2label[label_idx] not in self.ignore_labels
KeyError: 422

@elkotito
Copy link

from transformers import BertTokenizer, BertForTokenClassification
tokenizer = BertTokenizer.from_pretrained('allenai/scibert_scivocab_uncased')
model = BertForTokenClassification.from_pretrained('allenai/scibert_scivocab_uncased')
nlp = pipeline('ner', model=model, tokenizer=tokenizer)

text = 'Clinical features of culture-proven Mycoplasma pneumoniae infections at King Abdulaziz University Hospital, Jeddah, Saudi Arabia'
print(nlp(text))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants