-
Notifications
You must be signed in to change notification settings - Fork 26.7k
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
Fix LayoutLMv3 documentation #17932
Merged
Merged
Fix LayoutLMv3 documentation #17932
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3df9cb0
fix typos
c6778c8
fix sequence_length docs of LayoutLMv3Model
5ce3536
delete trailing white spaces
3a2ab3a
fix layoutlmv3 docs more
74b9886
apply make fixup & quality
pocca2048 d605858
change to two versions of input docstring
0c90b28
apply make fixup & quality
pocca2048 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -61,10 +61,10 @@ | |||||
|
||||||
LAYOUTLMV3_INPUTS_DOCSTRING = r""" | ||||||
Args: | ||||||
input_ids (`torch.LongTensor` of shape `{0}`): | ||||||
input_ids (`torch.LongTensor` of shape `({0})`): | ||||||
Indices of input sequence tokens in the vocabulary. | ||||||
|
||||||
Indices can be obtained using [`LayoutLMv2Tokenizer`]. See [`PreTrainedTokenizer.encode`] and | ||||||
{1} | ||||||
Indices can be obtained using [`LayoutLMv3Tokenizer`]. See [`PreTrainedTokenizer.encode`] and | ||||||
[`PreTrainedTokenizer.__call__`] for details. | ||||||
|
||||||
[What are input IDs?](../glossary#input-ids) | ||||||
|
@@ -74,37 +74,39 @@ | |||||
config.max_2d_position_embeddings-1]`. Each bounding box should be a normalized version in (x0, y0, x1, y1) | ||||||
format, where (x0, y0) corresponds to the position of the upper left corner in the bounding box, and (x1, | ||||||
y1) represents the position of the lower right corner. | ||||||
|
||||||
{1} | ||||||
pixel_values (`torch.FloatTensor` of shape `(batch_size, num_channels, height, width)`): | ||||||
Batch of document images. | ||||||
Batch of document images. Each Image is divided into patches of shape `(num_channels, config.patch_size, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
config.patch_size)` and the total number of patches (=`patch_sequence_length`) equals to | ||||||
`((height / config.patch_size) * (width / config.patch_size))`. | ||||||
|
||||||
attention_mask (`torch.FloatTensor` of shape `{0}`, *optional*): | ||||||
attention_mask (`torch.FloatTensor` of shape `({0})`, *optional*): | ||||||
Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`: | ||||||
|
||||||
- 1 for tokens that are **not masked**, | ||||||
- 0 for tokens that are **masked**. | ||||||
|
||||||
{1} | ||||||
[What are attention masks?](../glossary#attention-mask) | ||||||
token_type_ids (`torch.LongTensor` of shape `{0}`, *optional*): | ||||||
token_type_ids (`torch.LongTensor` of shape `({0})`, *optional*): | ||||||
Segment token indices to indicate first and second portions of the inputs. Indices are selected in `[0, | ||||||
1]`: | ||||||
|
||||||
- 0 corresponds to a *sentence A* token, | ||||||
- 1 corresponds to a *sentence B* token. | ||||||
|
||||||
{1} | ||||||
[What are token type IDs?](../glossary#token-type-ids) | ||||||
position_ids (`torch.LongTensor` of shape `{0}`, *optional*): | ||||||
position_ids (`torch.LongTensor` of shape `({0})`, *optional*): | ||||||
Indices of positions of each input sequence tokens in the position embeddings. Selected in the range `[0, | ||||||
config.max_position_embeddings - 1]`. | ||||||
|
||||||
{1} | ||||||
[What are position IDs?](../glossary#position-ids) | ||||||
head_mask (`torch.FloatTensor` of shape `(num_heads,)` or `(num_layers, num_heads)`, *optional*): | ||||||
Mask to nullify selected heads of the self-attention modules. Mask values selected in `[0, 1]`: | ||||||
|
||||||
- 1 indicates the head is **not masked**, | ||||||
- 0 indicates the head is **masked**. | ||||||
|
||||||
inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*): | ||||||
inputs_embeds (`torch.FloatTensor` of shape `({0}, hidden_size)`, *optional*): | ||||||
Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation. This | ||||||
is useful if you want more control over how to convert *input_ids* indices into associated vectors than the | ||||||
model's internal embedding lookup matrix. | ||||||
|
@@ -118,6 +120,11 @@ | |||||
Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple. | ||||||
""" | ||||||
|
||||||
LAYOUTLMV3MODEL_INPUTS_DOCSTRING = r""" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Maybe this could be a better name :D |
||||||
Note that `sequence_length = token_sequence_length + patch_sequence_length + 1` where `1` is for | ||||||
[CLS] token. See `pixel_values` for `patch_sequence_length`. | ||||||
""" | ||||||
|
||||||
|
||||||
class LayoutLMv3PatchEmbeddings(nn.Module): | ||||||
"""LayoutLMv3 image (patch) embeddings. This class also automatically interpolates the position embeddings for varying | ||||||
|
@@ -763,7 +770,9 @@ def forward_image(self, pixel_values): | |||||
|
||||||
return embeddings | ||||||
|
||||||
@add_start_docstrings_to_model_forward(LAYOUTLMV3_INPUTS_DOCSTRING.format("(batch_size, sequence_length)")) | ||||||
@add_start_docstrings_to_model_forward( | ||||||
LAYOUTLMV3_INPUTS_DOCSTRING.format("batch_size, token_sequence_length", LAYOUTLMV3MODEL_INPUTS_DOCSTRING) | ||||||
) | ||||||
@replace_return_docstrings(output_type=BaseModelOutput, config_class=_CONFIG_FOR_DOC) | ||||||
def forward( | ||||||
self, | ||||||
|
@@ -975,7 +984,7 @@ def __init__(self, config): | |||||
|
||||||
self.init_weights() | ||||||
|
||||||
@add_start_docstrings_to_model_forward(LAYOUTLMV3_INPUTS_DOCSTRING.format("batch_size, sequence_length")) | ||||||
@add_start_docstrings_to_model_forward(LAYOUTLMV3_INPUTS_DOCSTRING.format("batch_size, sequence_length", "")) | ||||||
@replace_return_docstrings(output_type=TokenClassifierOutput, config_class=_CONFIG_FOR_DOC) | ||||||
def forward( | ||||||
self, | ||||||
|
@@ -1084,7 +1093,7 @@ def __init__(self, config): | |||||
|
||||||
self.init_weights() | ||||||
|
||||||
@add_start_docstrings_to_model_forward(LAYOUTLMV3_INPUTS_DOCSTRING.format("batch_size, sequence_length")) | ||||||
@add_start_docstrings_to_model_forward(LAYOUTLMV3_INPUTS_DOCSTRING.format("batch_size, sequence_length", "")) | ||||||
@replace_return_docstrings(output_type=QuestionAnsweringModelOutput, config_class=_CONFIG_FOR_DOC) | ||||||
def forward( | ||||||
self, | ||||||
|
@@ -1214,7 +1223,7 @@ def __init__(self, config): | |||||
|
||||||
self.init_weights() | ||||||
|
||||||
@add_start_docstrings_to_model_forward(LAYOUTLMV3_INPUTS_DOCSTRING.format("batch_size, sequence_length")) | ||||||
@add_start_docstrings_to_model_forward(LAYOUTLMV3_INPUTS_DOCSTRING.format("batch_size, sequence_length", "")) | ||||||
@replace_return_docstrings(output_type=SequenceClassifierOutput, config_class=_CONFIG_FOR_DOC) | ||||||
def forward( | ||||||
self, | ||||||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing this! Could you also replace LayoutLMv2Config by LayoutLMv3Config on line 57? Can't comment there.