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
afc5a1ea
Unverified
Commit
afc5a1ea
authored
Apr 01, 2022
by
Dahlbomii
Committed by
GitHub
Apr 01, 2022
Browse files
Type hints added (#16529)
parent
483a9450
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
48 deletions
+50
-48
src/transformers/models/openai/modeling_tf_openai.py
src/transformers/models/openai/modeling_tf_openai.py
+50
-48
No files found.
src/transformers/models/openai/modeling_tf_openai.py
View file @
afc5a1ea
...
@@ -16,8 +16,9 @@
...
@@ -16,8 +16,9 @@
""" TF 2.0 OpenAI GPT model."""
""" TF 2.0 OpenAI GPT model."""
from
dataclasses
import
dataclass
from
dataclasses
import
dataclass
from
typing
import
Optional
,
Tuple
from
typing
import
Optional
,
Tuple
,
Union
import
numpy
as
np
import
tensorflow
as
tf
import
tensorflow
as
tf
from
...activations_tf
import
get_tf_activation
from
...activations_tf
import
get_tf_activation
...
@@ -25,6 +26,7 @@ from ...modeling_tf_outputs import TFBaseModelOutput, TFCausalLMOutput, TFSequen
...
@@ -25,6 +26,7 @@ from ...modeling_tf_outputs import TFBaseModelOutput, TFCausalLMOutput, TFSequen
from
...modeling_tf_utils
import
(
from
...modeling_tf_utils
import
(
TFCausalLanguageModelingLoss
,
TFCausalLanguageModelingLoss
,
TFConv1D
,
TFConv1D
,
TFModelInputType
,
TFPreTrainedModel
,
TFPreTrainedModel
,
TFSequenceClassificationLoss
,
TFSequenceClassificationLoss
,
TFSequenceSummary
,
TFSequenceSummary
,
...
@@ -510,18 +512,18 @@ class TFOpenAIGPTModel(TFOpenAIGPTPreTrainedModel):
...
@@ -510,18 +512,18 @@ class TFOpenAIGPTModel(TFOpenAIGPTPreTrainedModel):
)
)
def
call
(
def
call
(
self
,
self
,
input_ids
=
None
,
input_ids
:
Optional
[
TFModelInputType
]
=
None
,
attention_mask
=
None
,
attention_mask
:
Optional
[
Union
[
np
.
ndarray
,
tf
.
Tensor
]]
=
None
,
token_type_ids
=
None
,
token_type_ids
:
Optional
[
Union
[
np
.
ndarray
,
tf
.
Tensor
]]
=
None
,
position_ids
=
None
,
position_ids
:
Optional
[
Union
[
np
.
ndarray
,
tf
.
Tensor
]]
=
None
,
head_mask
=
None
,
head_mask
:
Optional
[
Union
[
np
.
ndarray
,
tf
.
Tensor
]]
=
None
,
inputs_embeds
=
None
,
inputs_embeds
:
Optional
[
Union
[
np
.
ndarray
,
tf
.
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
,
training
=
False
,
training
:
Optional
[
bool
]
=
False
,
**
kwargs
,
**
kwargs
,
):
)
->
Union
[
Tuple
,
TFBaseModelOutput
]
:
outputs
=
self
.
transformer
(
outputs
=
self
.
transformer
(
input_ids
=
input_ids
,
input_ids
=
input_ids
,
...
@@ -573,19 +575,19 @@ class TFOpenAIGPTLMHeadModel(TFOpenAIGPTPreTrainedModel, TFCausalLanguageModelin
...
@@ -573,19 +575,19 @@ class TFOpenAIGPTLMHeadModel(TFOpenAIGPTPreTrainedModel, TFCausalLanguageModelin
)
)
def
call
(
def
call
(
self
,
self
,
input_ids
=
None
,
input_ids
:
Optional
[
TFModelInputType
]
=
None
,
attention_mask
=
None
,
attention_mask
:
Optional
[
Union
[
np
.
ndarray
,
tf
.
Tensor
]]
=
None
,
token_type_ids
=
None
,
token_type_ids
:
Optional
[
Union
[
np
.
ndarray
,
tf
.
Tensor
]]
=
None
,
position_ids
=
None
,
position_ids
:
Optional
[
Union
[
np
.
ndarray
,
tf
.
Tensor
]]
=
None
,
head_mask
=
None
,
head_mask
:
Optional
[
Union
[
np
.
ndarray
,
tf
.
Tensor
]]
=
None
,
inputs_embeds
=
None
,
inputs_embeds
:
Optional
[
Union
[
np
.
ndarray
,
tf
.
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
,
labels
=
None
,
labels
:
Optional
[
Union
[
np
.
ndarray
,
tf
.
Tensor
]]
=
None
,
training
=
False
,
training
:
Optional
[
bool
]
=
False
,
**
kwargs
,
**
kwargs
,
):
)
->
Union
[
Tuple
,
TFCausalLMOutput
]
:
r
"""
r
"""
labels (`tf.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
labels (`tf.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
Labels for computing the cross entropy classification loss. Indices should be in `[0, ...,
Labels for computing the cross entropy classification loss. Indices should be in `[0, ...,
...
@@ -656,19 +658,19 @@ class TFOpenAIGPTDoubleHeadsModel(TFOpenAIGPTPreTrainedModel):
...
@@ -656,19 +658,19 @@ class TFOpenAIGPTDoubleHeadsModel(TFOpenAIGPTPreTrainedModel):
@
replace_return_docstrings
(
output_type
=
TFOpenAIGPTDoubleHeadsModelOutput
,
config_class
=
_CONFIG_FOR_DOC
)
@
replace_return_docstrings
(
output_type
=
TFOpenAIGPTDoubleHeadsModelOutput
,
config_class
=
_CONFIG_FOR_DOC
)
def
call
(
def
call
(
self
,
self
,
input_ids
=
None
,
input_ids
:
Optional
[
TFModelInputType
]
=
None
,
attention_mask
=
None
,
attention_mask
:
Optional
[
Union
[
np
.
ndarray
,
tf
.
Tensor
]]
=
None
,
token_type_ids
=
None
,
token_type_ids
:
Optional
[
Union
[
np
.
ndarray
,
tf
.
Tensor
]]
=
None
,
position_ids
=
None
,
position_ids
:
Optional
[
Union
[
np
.
ndarray
,
tf
.
Tensor
]]
=
None
,
head_mask
=
None
,
head_mask
:
Optional
[
Union
[
np
.
ndarray
,
tf
.
Tensor
]]
=
None
,
inputs_embeds
=
None
,
inputs_embeds
:
Optional
[
Union
[
np
.
ndarray
,
tf
.
Tensor
]]
=
None
,
mc_token_ids
=
None
,
mc_token_ids
:
Optional
[
Union
[
np
.
ndarray
,
tf
.
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
,
training
=
False
,
training
:
Optional
[
bool
]
=
False
,
**
kwargs
,
**
kwargs
,
):
)
->
Union
[
Tuple
,
TFOpenAIGPTDoubleHeadsModelOutput
]
:
r
"""
r
"""
mc_token_ids (`tf.Tensor` or `Numpy array` of shape `(batch_size, num_choices)`, *optional*, default to index of the last token of the input):
mc_token_ids (`tf.Tensor` or `Numpy array` of shape `(batch_size, num_choices)`, *optional*, default to index of the last token of the input):
Index of the classification token in each input sequence. Selected in the range `[0, input_ids.size(-1) -
Index of the classification token in each input sequence. Selected in the range `[0, input_ids.size(-1) -
...
@@ -800,19 +802,19 @@ class TFOpenAIGPTForSequenceClassification(TFOpenAIGPTPreTrainedModel, TFSequenc
...
@@ -800,19 +802,19 @@ class TFOpenAIGPTForSequenceClassification(TFOpenAIGPTPreTrainedModel, TFSequenc
)
)
def
call
(
def
call
(
self
,
self
,
input_ids
=
None
,
input_ids
:
Optional
[
TFModelInputType
]
=
None
,
attention_mask
=
None
,
attention_mask
:
Optional
[
Union
[
np
.
ndarray
,
tf
.
Tensor
]]
=
None
,
token_type_ids
=
None
,
token_type_ids
:
Optional
[
Union
[
np
.
ndarray
,
tf
.
Tensor
]]
=
None
,
position_ids
=
None
,
position_ids
:
Optional
[
Union
[
np
.
ndarray
,
tf
.
Tensor
]]
=
None
,
head_mask
=
None
,
head_mask
:
Optional
[
Union
[
np
.
ndarray
,
tf
.
Tensor
]]
=
None
,
inputs_embeds
=
None
,
inputs_embeds
:
Optional
[
Union
[
np
.
ndarray
,
tf
.
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
,
labels
=
None
,
labels
:
Optional
[
Union
[
np
.
ndarray
,
tf
.
Tensor
]]
=
None
,
training
=
False
,
training
:
Optional
[
bool
]
=
False
,
**
kwargs
,
**
kwargs
,
):
)
->
Union
[
Tuple
,
TFSequenceClassifierOutput
]
:
r
"""
r
"""
labels (`tf.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
labels (`tf.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
Labels for computing the cross entropy classification loss. Indices should be in `[0, ...,
Labels for computing the cross entropy 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