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

Add JinaBert model #407

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/bumblebee.ex
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ defmodule Bumblebee do
"GPTNeoXForCausalLM" => {Bumblebee.Text.GptNeoX, :for_causal_language_modeling},
"GPTNeoXForSequenceClassification" => {Bumblebee.Text.GptNeoX, :for_sequence_classification},
"GPTNeoXForTokenClassification" => {Bumblebee.Text.GptNeoX, :for_token_classification},
"JinaBertForMaskedLM" => {Bumblebee.Text.JinaBert, :for_masked_language_modeling},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The config says it's JinaBertForMaskedLM. However, with this mapping there are missing and unused parameters:

11:51:58.408 [debug] the following parameters were missing:

  * language_modeling_head.dense.kernel
  * language_modeling_head.dense.bias
  * language_modeling_head.output.kernel
  * language_modeling_head.bias.bias
  * language_modeling_head.norm.gamma
  * language_modeling_head.norm.beta


11:51:58.408 [debug] the following PyTorch parameters were unused:

  * pooler.dense.bias
  * pooler.dense.weight

Looks to me like this is not in line with the previous :for_masked_language_modeling implementation of BERT.
So, we could map here to the :base architecture instead?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is JinaBertForMaskedLM implementation and it has the expected layers. I think the issue is that the model on the hub is actually JinaBertmodel and the config is wrong.

So the correct way to workaround this would be specifying architecture when loading:

Bumblebee.load_model({:hf, "..."}, architecture: :base)

It may be worth opening a PR on the HF repo, changing it to JinaBertmodel. Unfortunately, the same is the case for the other checkpoints of this model (small, etc).

"JinaBertModel" => {Bumblebee.Text.JinaBert, :base},
"LayoutLMForMaskedLM" => {Bumblebee.Multimodal.LayoutLm, :for_masked_language_modeling},
"LayoutLMForQuestionAnswering" => {Bumblebee.Multimodal.LayoutLm, :for_question_answering},
"LayoutLMForSequenceClassification" =>
Expand Down
Loading
Loading