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

biobert for keras version of huggingface transformers #98

Closed
dmollaaliod opened this issue Mar 5, 2020 · 1 comment
Closed

biobert for keras version of huggingface transformers #98

dmollaaliod opened this issue Mar 5, 2020 · 1 comment

Comments

@dmollaaliod
Copy link

Hi, are there any instructions/hints about how to load biobert as a keras layer using the huggingface transformers? I tried several possibilities but none of these worked. All that I found out is how to use the pytorch version but I am interested in the keras layer version. Below are two of my attempts (I saved the biobert files into folder "biobert_v1.1_pubmed").

Attempt 1:

biobert_model = TFBertModel.from_pretrained('bert-base-uncased')
biobert_model.load_weights('biobert_v1.1_pubmed/model.ckpt-1000000')

Error message:

AssertionError: Some objects had attributes which were not restored:
    : ['tf_bert_model_4/bert/embeddings/word_embeddings/weight']
    : ['tf_bert_model_4/bert/embeddings/position_embeddings/embeddings']
   (and many more lines like above...)

Attempt 2:

biobert_model = TFBertModel.from_pretrained("biobert_v1.1_pubmed/model.ckpt-1000000", config='biobert_v1.1_pubmed/bert_config.json')

Error message:

NotImplementedError: Weights may only be loaded based on topology into Models when loading TensorFlow-formatted weights (got by_name=True to load_weights).

Any help appreciated! My experience with huggingface's transformers library is almost zero.

@dmollaaliod
Copy link
Author

Someone answered in stackoverflow, it worked for me :)

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

1 participant