Closed mohammedkhalilia closed 5 years ago
Thanks for reporting this issue @mohammedkhalilia.
I think the problem is that get_model
expects a gluonnlp.Vocab
object for it's vocab
parameter. However, you passed the filename to the json file from which the gluonnlp.Vocab
object can be constructed. The correct usage would be to run
with open(vocab, 'r') as fh:
vocab = gluonnlp.Vocab.from_json(fh.read())
params = {
'dataset_name': None,
'vocab': vocab,
'pretrained': False,
'ctx': ctx,
'use_pooler': False,
'use_decoder': False,
'use_classifier': False,
'dropout': 0.1,
'embed_dropout': 0.1
}
bert_model, text_vocab = gluonnlp.model.get_model('bert_12_768_12', **params)
Does that work for you? Closing the issue, but please reopen in case of any problems.
Also note gluonnlp.Vocab.from_json(fh.read())
instead of gluonnlp.Vocab().from_json(fh.read())
Description
When calling get_model(name, **kwargs), we can specify either the
--dataset_name
, which will load the vocab for that dataset, or we can pass the--vocab
for custom BERT vocabulary. An error occurs when calling a BERT model such asbert_12_768_12
with--vocab
and without passing--dataset_name
.Error Message
Note that I did make minor modification to finetune_ner.py script, but that is irrelevant. The correct vocabulary size in this example is 28996 and the 98 is the length of the filename passed in the vocab argument in the function _load_vocab(dataset_name, vocab, root, cls=None)
To Reproduce
To reproduce, you need to convert a BERT to Gluon. In my case I convereted Clinical BERT TensorFlow model to Gluon using convert_tf_model.py. Then try loading a model using get_model(name, **kwargs). See instructions below.
Steps to reproduce
--dataset_name
and pass the converted vocabulary using--vocab
argument.What have you tried to solve it?
_load_vocab(dataset_name, vocab, root, cls=None) returns the vocab variable (str) if
--dataset_name
is not set, hence the vocab length 98 you see in the error message above. To resolve the issue, I modified the function _load_vocab(dataset_name, vocab, root, cls=None) and added the following lines after line 273Environment