Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
9947dd07
Unverified
Commit
9947dd07
authored
Apr 01, 2022
by
Gunjan Chhablani
Committed by
GitHub
Apr 01, 2022
Browse files
Add VisualBert type hints (#16544)
parent
59a9c83e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
92 additions
and
92 deletions
+92
-92
src/transformers/models/visual_bert/modeling_visual_bert.py
src/transformers/models/visual_bert/modeling_visual_bert.py
+92
-92
No files found.
src/transformers/models/visual_bert/modeling_visual_bert.py
View file @
9947dd07
...
@@ -17,7 +17,7 @@
...
@@ -17,7 +17,7 @@
import
math
import
math
from
dataclasses
import
dataclass
from
dataclasses
import
dataclass
from
typing
import
Optional
,
Tuple
from
typing
import
Optional
,
Tuple
,
Union
import
torch
import
torch
import
torch.utils.checkpoint
import
torch.utils.checkpoint
...
@@ -720,20 +720,20 @@ class VisualBertModel(VisualBertPreTrainedModel):
...
@@ -720,20 +720,20 @@ class VisualBertModel(VisualBertPreTrainedModel):
@
replace_return_docstrings
(
output_type
=
BaseModelOutputWithPooling
,
config_class
=
_CONFIG_FOR_DOC
)
@
replace_return_docstrings
(
output_type
=
BaseModelOutputWithPooling
,
config_class
=
_CONFIG_FOR_DOC
)
def
forward
(
def
forward
(
self
,
self
,
input_ids
=
None
,
input_ids
:
Optional
[
torch
.
LongTensor
]
=
None
,
attention_mask
=
None
,
attention_mask
:
Optional
[
torch
.
LongTensor
]
=
None
,
token_type_ids
=
None
,
token_type_ids
:
Optional
[
torch
.
LongTensor
]
=
None
,
position_ids
=
None
,
position_ids
:
Optional
[
torch
.
LongTensor
]
=
None
,
head_mask
=
None
,
head_mask
:
Optional
[
torch
.
LongTensor
]
=
None
,
inputs_embeds
=
None
,
inputs_embeds
:
Optional
[
torch
.
FloatTensor
]
=
None
,
visual_embeds
=
None
,
visual_embeds
:
Optional
[
torch
.
FloatTensor
]
=
None
,
visual_attention_mask
=
None
,
visual_attention_mask
:
Optional
[
torch
.
LongTensor
]
=
None
,
visual_token_type_ids
=
None
,
visual_token_type_ids
:
Optional
[
torch
.
LongTensor
]
=
None
,
image_text_alignment
=
None
,
image_text_alignment
:
Optional
[
torch
.
LongTensor
]
=
None
,
output_attentions
=
None
,
output_attentions
:
Optional
[
bool
]
=
None
,
output_hidden_states
=
None
,
output_hidden_states
:
Optional
[
bool
]
=
None
,
return_dict
=
None
,
return_dict
:
Optional
[
bool
]
=
None
,
):
)
->
Union
[
Tuple
[
torch
.
Tensor
],
BaseModelOutputWithPooling
]
:
r
"""
r
"""
Returns:
Returns:
...
@@ -893,22 +893,22 @@ class VisualBertForPreTraining(VisualBertPreTrainedModel):
...
@@ -893,22 +893,22 @@ class VisualBertForPreTraining(VisualBertPreTrainedModel):
@
replace_return_docstrings
(
output_type
=
VisualBertForPreTrainingOutput
,
config_class
=
_CONFIG_FOR_DOC
)
@
replace_return_docstrings
(
output_type
=
VisualBertForPreTrainingOutput
,
config_class
=
_CONFIG_FOR_DOC
)
def
forward
(
def
forward
(
self
,
self
,
input_ids
=
None
,
input_ids
:
Optional
[
torch
.
LongTensor
]
=
None
,
attention_mask
=
None
,
attention_mask
:
Optional
[
torch
.
LongTensor
]
=
None
,
token_type_ids
=
None
,
token_type_ids
:
Optional
[
torch
.
LongTensor
]
=
None
,
position_ids
=
None
,
position_ids
:
Optional
[
torch
.
LongTensor
]
=
None
,
head_mask
=
None
,
head_mask
:
Optional
[
torch
.
LongTensor
]
=
None
,
inputs_embeds
=
None
,
inputs_embeds
:
Optional
[
torch
.
FloatTensor
]
=
None
,
visual_embeds
=
None
,
visual_embeds
:
Optional
[
torch
.
FloatTensor
]
=
None
,
visual_attention_mask
=
None
,
visual_attention_mask
:
Optional
[
torch
.
LongTensor
]
=
None
,
visual_token_type_ids
=
None
,
visual_token_type_ids
:
Optional
[
torch
.
LongTensor
]
=
None
,
image_text_alignment
=
None
,
image_text_alignment
:
Optional
[
torch
.
LongTensor
]
=
None
,
output_attentions
=
None
,
output_attentions
:
Optional
[
bool
]
=
None
,
output_hidden_states
=
None
,
output_hidden_states
:
Optional
[
bool
]
=
None
,
return_dict
=
None
,
return_dict
:
Optional
[
bool
]
=
None
,
labels
=
None
,
labels
:
Optional
[
torch
.
LongTensor
]
=
None
,
sentence_image_labels
=
None
,
sentence_image_labels
:
Optional
[
torch
.
LongTensor
]
=
None
,
):
)
->
Union
[
Tuple
[
torch
.
Tensor
],
VisualBertForPreTrainingOutput
]
:
r
"""
r
"""
labels (`torch.LongTensor` of shape `(batch_size, total_sequence_length)`, *optional*):
labels (`torch.LongTensor` of shape `(batch_size, total_sequence_length)`, *optional*):
Labels for computing the masked language modeling loss. Indices should be in `[-100, 0, ...,
Labels for computing the masked language modeling loss. Indices should be in `[-100, 0, ...,
...
@@ -1039,21 +1039,21 @@ class VisualBertForMultipleChoice(VisualBertPreTrainedModel):
...
@@ -1039,21 +1039,21 @@ class VisualBertForMultipleChoice(VisualBertPreTrainedModel):
@
replace_return_docstrings
(
output_type
=
MultipleChoiceModelOutput
,
config_class
=
_CONFIG_FOR_DOC
)
@
replace_return_docstrings
(
output_type
=
MultipleChoiceModelOutput
,
config_class
=
_CONFIG_FOR_DOC
)
def
forward
(
def
forward
(
self
,
self
,
input_ids
=
None
,
input_ids
:
Optional
[
torch
.
LongTensor
]
=
None
,
attention_mask
=
None
,
attention_mask
:
Optional
[
torch
.
LongTensor
]
=
None
,
token_type_ids
=
None
,
token_type_ids
:
Optional
[
torch
.
LongTensor
]
=
None
,
position_ids
=
None
,
position_ids
:
Optional
[
torch
.
LongTensor
]
=
None
,
head_mask
=
None
,
head_mask
:
Optional
[
torch
.
LongTensor
]
=
None
,
inputs_embeds
=
None
,
inputs_embeds
:
Optional
[
torch
.
FloatTensor
]
=
None
,
visual_embeds
=
None
,
visual_embeds
:
Optional
[
torch
.
FloatTensor
]
=
None
,
visual_attention_mask
=
None
,
visual_attention_mask
:
Optional
[
torch
.
LongTensor
]
=
None
,
visual_token_type_ids
=
None
,
visual_token_type_ids
:
Optional
[
torch
.
LongTensor
]
=
None
,
image_text_alignment
=
None
,
image_text_alignment
:
Optional
[
torch
.
LongTensor
]
=
None
,
output_attentions
=
None
,
output_attentions
:
Optional
[
bool
]
=
None
,
output_hidden_states
=
None
,
output_hidden_states
:
Optional
[
bool
]
=
None
,
return_dict
=
None
,
return_dict
:
Optional
[
bool
]
=
None
,
labels
=
None
,
labels
:
Optional
[
torch
.
LongTensor
]
=
None
,
):
)
->
Union
[
Tuple
[
torch
.
Tensor
],
MultipleChoiceModelOutput
]
:
r
"""
r
"""
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
Labels for computing the multiple choice classification loss. Indices should be in `[0, ...,
Labels for computing the multiple choice classification loss. Indices should be in `[0, ...,
...
@@ -1191,21 +1191,21 @@ class VisualBertForQuestionAnswering(VisualBertPreTrainedModel):
...
@@ -1191,21 +1191,21 @@ class VisualBertForQuestionAnswering(VisualBertPreTrainedModel):
@
replace_return_docstrings
(
output_type
=
SequenceClassifierOutput
,
config_class
=
_CONFIG_FOR_DOC
)
@
replace_return_docstrings
(
output_type
=
SequenceClassifierOutput
,
config_class
=
_CONFIG_FOR_DOC
)
def
forward
(
def
forward
(
self
,
self
,
input_ids
=
None
,
input_ids
:
Optional
[
torch
.
LongTensor
]
=
None
,
attention_mask
=
None
,
attention_mask
:
Optional
[
torch
.
LongTensor
]
=
None
,
token_type_ids
=
None
,
token_type_ids
:
Optional
[
torch
.
LongTensor
]
=
None
,
position_ids
=
None
,
position_ids
:
Optional
[
torch
.
LongTensor
]
=
None
,
head_mask
=
None
,
head_mask
:
Optional
[
torch
.
LongTensor
]
=
None
,
inputs_embeds
=
None
,
inputs_embeds
:
Optional
[
torch
.
FloatTensor
]
=
None
,
visual_embeds
=
None
,
visual_embeds
:
Optional
[
torch
.
FloatTensor
]
=
None
,
visual_attention_mask
=
None
,
visual_attention_mask
:
Optional
[
torch
.
LongTensor
]
=
None
,
visual_token_type_ids
=
None
,
visual_token_type_ids
:
Optional
[
torch
.
LongTensor
]
=
None
,
image_text_alignment
=
None
,
image_text_alignment
:
Optional
[
torch
.
LongTensor
]
=
None
,
output_attentions
=
None
,
output_attentions
:
Optional
[
bool
]
=
None
,
output_hidden_states
=
None
,
output_hidden_states
:
Optional
[
bool
]
=
None
,
return_dict
=
None
,
return_dict
:
Optional
[
bool
]
=
None
,
labels
=
None
,
labels
:
Optional
[
torch
.
LongTensor
]
=
None
,
):
)
->
Union
[
Tuple
[
torch
.
Tensor
],
SequenceClassifierOutput
]
:
r
"""
r
"""
labels (`torch.LongTensor` of shape `(batch_size, total_sequence_length)`, *optional*):
labels (`torch.LongTensor` of shape `(batch_size, total_sequence_length)`, *optional*):
Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,
Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,
...
@@ -1317,21 +1317,21 @@ class VisualBertForVisualReasoning(VisualBertPreTrainedModel):
...
@@ -1317,21 +1317,21 @@ class VisualBertForVisualReasoning(VisualBertPreTrainedModel):
@
replace_return_docstrings
(
output_type
=
SequenceClassifierOutput
,
config_class
=
_CONFIG_FOR_DOC
)
@
replace_return_docstrings
(
output_type
=
SequenceClassifierOutput
,
config_class
=
_CONFIG_FOR_DOC
)
def
forward
(
def
forward
(
self
,
self
,
input_ids
=
None
,
input_ids
:
Optional
[
torch
.
LongTensor
]
=
None
,
attention_mask
=
None
,
attention_mask
:
Optional
[
torch
.
LongTensor
]
=
None
,
token_type_ids
=
None
,
token_type_ids
:
Optional
[
torch
.
LongTensor
]
=
None
,
position_ids
=
None
,
position_ids
:
Optional
[
torch
.
LongTensor
]
=
None
,
head_mask
=
None
,
head_mask
:
Optional
[
torch
.
LongTensor
]
=
None
,
inputs_embeds
=
None
,
inputs_embeds
:
Optional
[
torch
.
FloatTensor
]
=
None
,
visual_embeds
=
None
,
visual_embeds
:
Optional
[
torch
.
FloatTensor
]
=
None
,
visual_attention_mask
=
None
,
visual_attention_mask
:
Optional
[
torch
.
LongTensor
]
=
None
,
visual_token_type_ids
=
None
,
visual_token_type_ids
:
Optional
[
torch
.
LongTensor
]
=
None
,
image_text_alignment
=
None
,
image_text_alignment
:
Optional
[
torch
.
LongTensor
]
=
None
,
output_attentions
=
None
,
output_attentions
:
Optional
[
bool
]
=
None
,
output_hidden_states
=
None
,
output_hidden_states
:
Optional
[
bool
]
=
None
,
return_dict
=
None
,
return_dict
:
Optional
[
bool
]
=
None
,
labels
=
None
,
labels
:
Optional
[
torch
.
LongTensor
]
=
None
,
):
)
->
Union
[
Tuple
[
torch
.
Tensor
],
SequenceClassifierOutput
]
:
r
"""
r
"""
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,
Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,
...
@@ -1477,22 +1477,22 @@ class VisualBertForRegionToPhraseAlignment(VisualBertPreTrainedModel):
...
@@ -1477,22 +1477,22 @@ class VisualBertForRegionToPhraseAlignment(VisualBertPreTrainedModel):
@
replace_return_docstrings
(
output_type
=
SequenceClassifierOutput
,
config_class
=
_CONFIG_FOR_DOC
)
@
replace_return_docstrings
(
output_type
=
SequenceClassifierOutput
,
config_class
=
_CONFIG_FOR_DOC
)
def
forward
(
def
forward
(
self
,
self
,
input_ids
=
None
,
input_ids
:
Optional
[
torch
.
LongTensor
]
=
None
,
attention_mask
=
None
,
attention_mask
:
Optional
[
torch
.
LongTensor
]
=
None
,
token_type_ids
=
None
,
token_type_ids
:
Optional
[
torch
.
LongTensor
]
=
None
,
position_ids
=
None
,
position_ids
:
Optional
[
torch
.
LongTensor
]
=
None
,
head_mask
=
None
,
head_mask
:
Optional
[
torch
.
LongTensor
]
=
None
,
inputs_embeds
=
None
,
inputs_embeds
:
Optional
[
torch
.
FloatTensor
]
=
None
,
visual_embeds
=
None
,
visual_embeds
:
Optional
[
torch
.
FloatTensor
]
=
None
,
visual_attention_mask
=
None
,
visual_attention_mask
:
Optional
[
torch
.
LongTensor
]
=
None
,
visual_token_type_ids
=
None
,
visual_token_type_ids
:
Optional
[
torch
.
LongTensor
]
=
None
,
image_text_alignment
=
None
,
image_text_alignment
:
Optional
[
torch
.
LongTensor
]
=
None
,
output_attentions
=
None
,
output_attentions
:
Optional
[
bool
]
=
None
,
output_hidden_states
=
None
,
output_hidden_states
:
Optional
[
bool
]
=
None
,
return_dict
=
None
,
return_dict
:
Optional
[
bool
]
=
None
,
region_to_phrase_position
=
None
,
region_to_phrase_position
:
Optional
[
torch
.
LongTensor
]
=
None
,
labels
=
None
,
labels
:
Optional
[
torch
.
LongTensor
]
=
None
,
):
)
->
Union
[
Tuple
[
torch
.
Tensor
],
SequenceClassifierOutput
]
:
r
"""
r
"""
region_to_phrase_position (`torch.LongTensor` of shape `(batch_size, total_sequence_length)`, *optional*):
region_to_phrase_position (`torch.LongTensor` of shape `(batch_size, total_sequence_length)`, *optional*):
The positions depicting the position of the image embedding corresponding to the textual tokens.
The positions depicting the position of the image embedding corresponding to the textual tokens.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment