Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Fix division by zero when there are zero-length spans in MismatchedEmbedder. #4615

Merged
merged 6 commits into from
Sep 1, 2020

Conversation

dwadden
Copy link

@dwadden dwadden commented Aug 30, 2020

Fixes #4612 and adds a unit test to confirm that missing or exotic tokens to not lead to nan gradients in BERT-style embedder.

Fix `clamp_min` on embeddings.

Implment MattG's fix for NaN gradients in MismatchedEmbedder.
@matt-gardner matt-gardner changed the title Implment MattG's fix for NaN gradients in MismatchedEmbedder. Fix division by zero when there are zero-length spans in MismatchedEmbedder. Aug 31, 2020
Copy link
Contributor

@matt-gardner matt-gardner left a comment

Choose a reason for hiding this comment

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

Thanks for doing this, this looks great! There are a couple of minor things to clean up in the test, and can you add a simple note to the changelog saying something like "Fixed division by zero error when there are zero-length spans in the input to a mismatched embedder."

Comment on lines 156 to 166
params = Params(
{
"token_embedders": {
"bert": {
"type": "pretrained_transformer_mismatched",
"model_name": "bert-base-uncased",
}
}
}
)
token_embedder = BasicTextFieldEmbedder.from_params(vocab=vocab, params=params)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you just make this:

Suggested change
params = Params(
{
"token_embedders": {
"bert": {
"type": "pretrained_transformer_mismatched",
"model_name": "bert-base-uncased",
}
}
}
)
token_embedder = BasicTextFieldEmbedder.from_params(vocab=vocab, params=params)
token_embedder = BasicTextFieldEmbedder({"bert": PretrainedTransformerMismatchedEmbedder("bert-base-uncased")})

No need to use Params here. (be sure to run black on that line, it might be too long, and this might require adding some imports above)

Copy link
Author

Choose a reason for hiding this comment

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

Changed.

Fixed division by zero error when there are zero-length spans in the input to a
mismatched embedder.
@dwadden
Copy link
Author

dwadden commented Aug 31, 2020

Changes have been made. There are two transformer parameters that have None gradients. Not sure if this is a bug or not. Let me know.

@matt-gardner
Copy link
Contributor

Thanks @dwadden! I tried pushing a couple of small final fixes to get this to pass CI, but for some reason it didn't let me (maybe because this is from your master branch). I was able to do one of them from the web UI, but I can't add the changelog statement that I mentioned in my comment above. Can you do that? Then I'll merge this.

@dwadden
Copy link
Author

dwadden commented Sep 1, 2020

OK, I added a message to the changelog. I also got confused and did git push --force on my fork, which clobbered your formatting changes. I ran black to get them back, so now the linter and type checker pass.

@matt-gardner matt-gardner merged commit 711afaa into allenai:master Sep 1, 2020
@matt-gardner
Copy link
Contributor

Thanks again!

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

Successfully merging this pull request may close these issues.

PretrainedTransformerMismatchedIndexer fails silently when given empty strings as input.
2 participants