Practical_NLP_in_PyTorch icon indicating copy to clipboard operation
Practical_NLP_in_PyTorch copied to clipboard

ImportError: cannot import name 'PretrainedBertIndexer'

Open Mayar2009 opened this issue 3 years ago • 0 comments

when trying to understand bert_text_classification.ipynb

this part of notebook

from allennlp.data.token_indexers import PretrainedBertIndexer

token_indexer = PretrainedBertIndexer( pretrained_model="bert-base-uncased", max_pieces=config.max_seq_len, do_lowercase=True, )

apparently we need to truncate the sequence here, which is a stupid design decision

def tokenizer(s: str): return token_indexer.wordpiece_tokenizer(s)[:config.max_seq_len - 2]

gives this error

ImportError Traceback (most recent call last) in () ----> 1 from allennlp.data.token_indexers import PretrainedBertIndexer 2 3 token_indexer = PretrainedBertIndexer( 4 pretrained_model="bert-base-uncased", 5 max_pieces=config.max_seq_len,

ImportError: cannot import name 'PretrainedBertIndexer'


NOTE: If your import is failing due to a missing package, you can manually install dependencies using either !pip or !apt.

To view examples of installing some common dependencies, click the "Open Examples" button below.

allennlp version used is 1.0.0

seems version differ , I could not find the solution what should I do?

Mayar2009 avatar Aug 15 '20 18:08 Mayar2009