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
65cf33e7
Unverified
Commit
65cf33e7
authored
Mar 12, 2022
by
James Barry
Committed by
GitHub
Mar 12, 2022
Browse files
Add type hints to XLM model (PyTorch) (#16108)
parent
84162068
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
103 additions
and
103 deletions
+103
-103
src/transformers/models/xlm/modeling_xlm.py
src/transformers/models/xlm/modeling_xlm.py
+103
-103
No files found.
src/transformers/models/xlm/modeling_xlm.py
View file @
65cf33e7
...
@@ -19,7 +19,7 @@
...
@@ -19,7 +19,7 @@
import
itertools
import
itertools
import
math
import
math
from
dataclasses
import
dataclass
from
dataclasses
import
dataclass
from
typing
import
Optional
,
Tuple
from
typing
import
Dict
,
Optional
,
Tuple
,
Union
import
numpy
as
np
import
numpy
as
np
import
torch
import
torch
...
@@ -494,19 +494,19 @@ class XLMModel(XLMPreTrainedModel):
...
@@ -494,19 +494,19 @@ class XLMModel(XLMPreTrainedModel):
)
)
def
forward
(
def
forward
(
self
,
self
,
input_ids
=
None
,
input_ids
:
Optional
[
torch
.
Tensor
]
=
None
,
attention_mask
=
None
,
attention_mask
:
Optional
[
torch
.
Tensor
]
=
None
,
langs
=
None
,
langs
:
Optional
[
torch
.
Tensor
]
=
None
,
token_type_ids
=
None
,
token_type_ids
:
Optional
[
torch
.
Tensor
]
=
None
,
position_ids
=
None
,
position_ids
:
Optional
[
torch
.
Tensor
]
=
None
,
lengths
=
None
,
lengths
:
Optional
[
torch
.
Tensor
]
=
None
,
cache
=
None
,
cache
:
Optional
[
Dict
[
str
,
torch
.
Tensor
]]
=
None
,
head_mask
=
None
,
head_mask
:
Optional
[
torch
.
Tensor
]
=
None
,
inputs_embeds
=
None
,
inputs_embeds
:
Optional
[
torch
.
Tensor
]
=
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
,
BaseModelOutput
]
:
output_attentions
=
output_attentions
if
output_attentions
is
not
None
else
self
.
config
.
output_attentions
output_attentions
=
output_attentions
if
output_attentions
is
not
None
else
self
.
config
.
output_attentions
output_hidden_states
=
(
output_hidden_states
=
(
output_hidden_states
if
output_hidden_states
is
not
None
else
self
.
config
.
output_hidden_states
output_hidden_states
if
output_hidden_states
is
not
None
else
self
.
config
.
output_hidden_states
...
@@ -716,20 +716,20 @@ class XLMWithLMHeadModel(XLMPreTrainedModel):
...
@@ -716,20 +716,20 @@ class XLMWithLMHeadModel(XLMPreTrainedModel):
)
)
def
forward
(
def
forward
(
self
,
self
,
input_ids
=
None
,
input_ids
:
Optional
[
torch
.
Tensor
]
=
None
,
attention_mask
=
None
,
attention_mask
:
Optional
[
torch
.
Tensor
]
=
None
,
langs
=
None
,
langs
:
Optional
[
torch
.
Tensor
]
=
None
,
token_type_ids
=
None
,
token_type_ids
:
Optional
[
torch
.
Tensor
]
=
None
,
position_ids
=
None
,
position_ids
:
Optional
[
torch
.
Tensor
]
=
None
,
lengths
=
None
,
lengths
:
Optional
[
torch
.
Tensor
]
=
None
,
cache
=
None
,
cache
:
Optional
[
Dict
[
str
,
torch
.
Tensor
]]
=
None
,
head_mask
=
None
,
head_mask
:
Optional
[
torch
.
Tensor
]
=
None
,
inputs_embeds
=
None
,
inputs_embeds
:
Optional
[
torch
.
Tensor
]
=
None
,
labels
=
None
,
labels
:
Optional
[
torch
.
Tensor
]
=
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
,
MaskedLMOutput
]
:
r
"""
r
"""
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
Labels for language modeling. Note that the labels **are shifted** inside the model, i.e. you can set
Labels for language modeling. Note that the labels **are shifted** inside the model, i.e. you can set
...
@@ -795,20 +795,20 @@ class XLMForSequenceClassification(XLMPreTrainedModel):
...
@@ -795,20 +795,20 @@ class XLMForSequenceClassification(XLMPreTrainedModel):
)
)
def
forward
(
def
forward
(
self
,
self
,
input_ids
=
None
,
input_ids
:
Optional
[
torch
.
Tensor
]
=
None
,
attention_mask
=
None
,
attention_mask
:
Optional
[
torch
.
Tensor
]
=
None
,
langs
=
None
,
langs
:
Optional
[
torch
.
Tensor
]
=
None
,
token_type_ids
=
None
,
token_type_ids
:
Optional
[
torch
.
Tensor
]
=
None
,
position_ids
=
None
,
position_ids
:
Optional
[
torch
.
Tensor
]
=
None
,
lengths
=
None
,
lengths
:
Optional
[
torch
.
Tensor
]
=
None
,
cache
=
None
,
cache
:
Optional
[
Dict
[
str
,
torch
.
Tensor
]]
=
None
,
head_mask
=
None
,
head_mask
:
Optional
[
torch
.
Tensor
]
=
None
,
inputs_embeds
=
None
,
inputs_embeds
:
Optional
[
torch
.
Tensor
]
=
None
,
labels
=
None
,
labels
:
Optional
[
torch
.
Tensor
]
=
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
,
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, ...,
...
@@ -896,21 +896,21 @@ class XLMForQuestionAnsweringSimple(XLMPreTrainedModel):
...
@@ -896,21 +896,21 @@ class XLMForQuestionAnsweringSimple(XLMPreTrainedModel):
)
)
def
forward
(
def
forward
(
self
,
self
,
input_ids
=
None
,
input_ids
:
Optional
[
torch
.
Tensor
]
=
None
,
attention_mask
=
None
,
attention_mask
:
Optional
[
torch
.
Tensor
]
=
None
,
langs
=
None
,
langs
:
Optional
[
torch
.
Tensor
]
=
None
,
token_type_ids
=
None
,
token_type_ids
:
Optional
[
torch
.
Tensor
]
=
None
,
position_ids
=
None
,
position_ids
:
Optional
[
torch
.
Tensor
]
=
None
,
lengths
=
None
,
lengths
:
Optional
[
torch
.
Tensor
]
=
None
,
cache
=
None
,
cache
:
Optional
[
Dict
[
str
,
torch
.
Tensor
]]
=
None
,
head_mask
=
None
,
head_mask
:
Optional
[
torch
.
Tensor
]
=
None
,
inputs_embeds
=
None
,
inputs_embeds
:
Optional
[
torch
.
Tensor
]
=
None
,
start_positions
=
None
,
start_positions
:
Optional
[
torch
.
Tensor
]
=
None
,
end_positions
=
None
,
end_positions
:
Optional
[
torch
.
Tensor
]
=
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
,
QuestionAnsweringModelOutput
]
:
r
"""
r
"""
start_positions (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
start_positions (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
Labels for position (index) of the start of the labelled span for computing the token classification loss.
Labels for position (index) of the start of the labelled span for computing the token classification loss.
...
@@ -996,24 +996,24 @@ class XLMForQuestionAnswering(XLMPreTrainedModel):
...
@@ -996,24 +996,24 @@ class XLMForQuestionAnswering(XLMPreTrainedModel):
@
replace_return_docstrings
(
output_type
=
XLMForQuestionAnsweringOutput
,
config_class
=
_CONFIG_FOR_DOC
)
@
replace_return_docstrings
(
output_type
=
XLMForQuestionAnsweringOutput
,
config_class
=
_CONFIG_FOR_DOC
)
def
forward
(
def
forward
(
self
,
self
,
input_ids
=
None
,
input_ids
:
Optional
[
torch
.
Tensor
]
=
None
,
attention_mask
=
None
,
attention_mask
:
Optional
[
torch
.
Tensor
]
=
None
,
langs
=
None
,
langs
:
Optional
[
torch
.
Tensor
]
=
None
,
token_type_ids
=
None
,
token_type_ids
:
Optional
[
torch
.
Tensor
]
=
None
,
position_ids
=
None
,
position_ids
:
Optional
[
torch
.
Tensor
]
=
None
,
lengths
=
None
,
lengths
:
Optional
[
torch
.
Tensor
]
=
None
,
cache
=
None
,
cache
:
Optional
[
Dict
[
str
,
torch
.
Tensor
]]
=
None
,
head_mask
=
None
,
head_mask
:
Optional
[
torch
.
Tensor
]
=
None
,
inputs_embeds
=
None
,
inputs_embeds
:
Optional
[
torch
.
Tensor
]
=
None
,
start_positions
=
None
,
start_positions
:
Optional
[
torch
.
Tensor
]
=
None
,
end_positions
=
None
,
end_positions
:
Optional
[
torch
.
Tensor
]
=
None
,
is_impossible
=
None
,
is_impossible
:
Optional
[
torch
.
Tensor
]
=
None
,
cls_index
=
None
,
cls_index
:
Optional
[
torch
.
Tensor
]
=
None
,
p_mask
=
None
,
p_mask
:
Optional
[
torch
.
Tensor
]
=
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
,
XLMForQuestionAnsweringOutput
]
:
r
"""
r
"""
start_positions (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
start_positions (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
Labels for position (index) of the start of the labelled span for computing the token classification loss.
Labels for position (index) of the start of the labelled span for computing the token classification loss.
...
@@ -1124,20 +1124,20 @@ class XLMForTokenClassification(XLMPreTrainedModel):
...
@@ -1124,20 +1124,20 @@ class XLMForTokenClassification(XLMPreTrainedModel):
)
)
def
forward
(
def
forward
(
self
,
self
,
input_ids
=
None
,
input_ids
:
Optional
[
torch
.
Tensor
]
=
None
,
attention_mask
=
None
,
attention_mask
:
Optional
[
torch
.
Tensor
]
=
None
,
langs
=
None
,
langs
:
Optional
[
torch
.
Tensor
]
=
None
,
token_type_ids
=
None
,
token_type_ids
:
Optional
[
torch
.
Tensor
]
=
None
,
position_ids
=
None
,
position_ids
:
Optional
[
torch
.
Tensor
]
=
None
,
lengths
=
None
,
lengths
:
Optional
[
torch
.
Tensor
]
=
None
,
cache
=
None
,
cache
:
Optional
[
Dict
[
str
,
torch
.
Tensor
]]
=
None
,
head_mask
=
None
,
head_mask
:
Optional
[
torch
.
Tensor
]
=
None
,
inputs_embeds
=
None
,
inputs_embeds
:
Optional
[
torch
.
Tensor
]
=
None
,
labels
=
None
,
labels
:
Optional
[
torch
.
Tensor
]
=
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
,
TokenClassifierOutput
]
:
r
"""
r
"""
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
Labels for computing the token classification loss. Indices should be in `[0, ..., config.num_labels - 1]`.
Labels for computing the token classification loss. Indices should be in `[0, ..., config.num_labels - 1]`.
...
@@ -1208,20 +1208,20 @@ class XLMForMultipleChoice(XLMPreTrainedModel):
...
@@ -1208,20 +1208,20 @@ class XLMForMultipleChoice(XLMPreTrainedModel):
)
)
def
forward
(
def
forward
(
self
,
self
,
input_ids
=
None
,
input_ids
:
Optional
[
torch
.
Tensor
]
=
None
,
attention_mask
=
None
,
attention_mask
:
Optional
[
torch
.
Tensor
]
=
None
,
langs
=
None
,
langs
:
Optional
[
torch
.
Tensor
]
=
None
,
token_type_ids
=
None
,
token_type_ids
:
Optional
[
torch
.
Tensor
]
=
None
,
position_ids
=
None
,
position_ids
:
Optional
[
torch
.
Tensor
]
=
None
,
lengths
=
None
,
lengths
:
Optional
[
torch
.
Tensor
]
=
None
,
cache
=
None
,
cache
:
Optional
[
Dict
[
str
,
torch
.
Tensor
]]
=
None
,
head_mask
=
None
,
head_mask
:
Optional
[
torch
.
Tensor
]
=
None
,
inputs_embeds
=
None
,
inputs_embeds
:
Optional
[
torch
.
Tensor
]
=
None
,
labels
=
None
,
labels
:
Optional
[
torch
.
Tensor
]
=
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
,
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, ...,
...
...
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