docs: add doctest for SqueezeBERT#42572
Open
arrdel wants to merge 1 commit into
Open
Conversation
Adds documentation test for SqueezeBertForMaskedLM as part of the Doc Tests Sprint (huggingface#16292). - Added example to forward() method showing masked language modeling - Used squeezebert-uncased checkpoint for testing - Added file to slow_documentation_tests.txt
Contributor
|
[For maintainers] Suggested jobs to run (before merge) run-slow: squeezebert |
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a doctest example to SqueezeBertForMaskedLM’s forward() docstring and includes the file in slow documentation tests. This helps validate masked language modeling usage in the docs.
- Adds a masked LM usage example with squeezebert-uncased.
- Registers the file in slow_documentation_tests.txt for doctest execution.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| utils/slow_documentation_tests.txt | Adds modeling_squeezebert.py to slow documentation tests to run doctest. |
| src/transformers/models/squeezebert/modeling_squeezebert.py | Adds a masked LM doctest example in the forward() docstring. |
| >>> # retrieve index of [MASK] | ||
| >>> mask_token_index = (inputs.input_ids == tokenizer.mask_token_id)[0].nonzero(as_tuple=True)[0] | ||
|
|
||
| >>> predicted_token_id = logits[0, mask_token_index].argmax(axis=-1) |
There was a problem hiding this comment.
In the doctest example, logits is a PyTorch tensor, but argmax(axis=-1) uses the NumPy keyword. In PyTorch, the correct keyword is dim. Using axis will raise an error. Suggest updating to argmax(dim=-1) to get the vocabulary index of the predicted token(s).
Suggested change
| >>> predicted_token_id = logits[0, mask_token_index].argmax(axis=-1) | |
| >>> predicted_token_id = logits[0, mask_token_index].argmax(dim=-1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds documentation test for SqueezeBertForMaskedLM as part of the Doc Tests Sprint (#16292).
What does this PR do?
Fixes #16292 (partial - adds SqueezeBERT)