Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
bd701ab1
Unverified
Commit
bd701ab1
authored
Jan 27, 2021
by
Julien Plu
Committed by
GitHub
Jan 27, 2021
Browse files
Fix template (#9840)
parent
c7b7bd99
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
4 deletions
+8
-4
src/transformers/models/bert/modeling_tf_bert.py
src/transformers/models/bert/modeling_tf_bert.py
+3
-1
templates/adding_a_new_model/cookiecutter-template-{{cookiecutter.modelname}}/modeling_tf_{{cookiecutter.lowercase_modelname}}.py
...ame}}/modeling_tf_{{cookiecutter.lowercase_modelname}}.py
+5
-3
No files found.
src/transformers/models/bert/modeling_tf_bert.py
View file @
bd701ab1
...
...
@@ -777,7 +777,9 @@ class TFBertMainLayer(tf.keras.layers.Layer):
# Since we are adding it to the raw scores before the softmax, this is
# effectively the same as removing these entirely.
extended_attention_mask
=
tf
.
cast
(
extended_attention_mask
,
dtype
=
embedding_output
.
dtype
)
extended_attention_mask
=
tf
.
multiply
(
tf
.
subtract
(
1.0
,
extended_attention_mask
),
-
10000.0
)
one_cst
=
tf
.
constant
(
1.0
,
dtype
=
embedding_output
.
dtype
)
ten_thousand_cst
=
tf
.
constant
(
-
10000.0
,
dtype
=
embedding_output
.
dtype
)
extended_attention_mask
=
tf
.
multiply
(
tf
.
subtract
(
one_cst
,
extended_attention_mask
),
ten_thousand_cst
)
# Prepare head mask if needed
# 1.0 in head_mask indicate we keep the head
...
...
templates/adding_a_new_model/cookiecutter-template-{{cookiecutter.modelname}}/modeling_tf_{{cookiecutter.lowercase_modelname}}.py
View file @
bd701ab1
...
...
@@ -695,7 +695,9 @@ class TF{{cookiecutter.camelcase_modelname}}MainLayer(tf.keras.layers.Layer):
# Since we are adding it to the raw scores before the softmax, this is
# effectively the same as removing these entirely.
extended_attention_mask
=
tf
.
cast
(
extended_attention_mask
,
dtype
=
embedding_output
.
dtype
)
extended_attention_mask
=
tf
.
multiply
(
tf
.
subtract
(
1.0
,
extended_attention_mask
),
-
10000.0
)
one_cst
=
tf
.
constant
(
1.0
,
dtype
=
embedding_output
.
dtype
)
ten_thousand_cst
=
tf
.
constant
(
-
10000.0
,
dtype
=
embedding_output
.
dtype
)
extended_attention_mask
=
tf
.
multiply
(
tf
.
subtract
(
one_cst
,
extended_attention_mask
),
ten_thousand_cst
)
# Prepare head mask if needed
# 1.0 in head_mask indicate we keep the head
...
...
@@ -917,7 +919,7 @@ class TF{{cookiecutter.camelcase_modelname}}ForMaskedLM(TF{{cookiecutter.camelca
)
self
.{{
cookiecutter
.
lowercase_modelname
}}
=
TF
{{
cookiecutter
.
camelcase_modelname
}}
MainLayer
(
config
,
name
=
"{{cookiecutter.lowercase_modelname}}"
)
self
.
mlm
=
TF
{{
cookiecutter
.
camelcase_modelname
}}
MLMHead
(
config
,
input
s
_embeddings
=
self
.{{
cookiecutter
.
lowercase_modelname
}}.
embeddings
.
word_embeddings
,
name
=
"mlm___cls"
)
self
.
mlm
=
TF
{{
cookiecutter
.
camelcase_modelname
}}
MLMHead
(
config
,
input_embeddings
=
self
.{{
cookiecutter
.
lowercase_modelname
}}.
embeddings
.
word_embeddings
,
name
=
"mlm___cls"
)
def
get_lm_head
(
self
)
->
tf
.
keras
.
layers
.
Layer
:
return
self
.
mlm
.
predictions
...
...
@@ -1014,7 +1016,7 @@ class TF{{cookiecutter.camelcase_modelname}}ForCausalLM(TF{{cookiecutter.camelca
logger
.
warning
(
"If you want to use `TF{{cookiecutter.camelcase_modelname}}ForCausalLM` as a standalone, add `is_decoder=True.`"
)
self
.{{
cookiecutter
.
lowercase_modelname
}}
=
TF
{{
cookiecutter
.
camelcase_modelname
}}
MainLayer
(
config
,
name
=
"{{cookiecutter.lowercase_modelname}}"
)
self
.
mlm
=
TF
{{
cookiecutter
.
camelcase_modelname
}}
MLMHead
(
config
,
input
s
_embeddings
=
self
.{{
cookiecutter
.
lowercase_modelname
}}.
embeddings
.
word_embeddings
,
name
=
"mlm___cls"
)
self
.
mlm
=
TF
{{
cookiecutter
.
camelcase_modelname
}}
MLMHead
(
config
,
input_embeddings
=
self
.{{
cookiecutter
.
lowercase_modelname
}}.
embeddings
.
word_embeddings
,
name
=
"mlm___cls"
)
def
get_lm_head
(
self
)
->
tf
.
keras
.
layers
.
Layer
:
return
self
.
mlm
.
predictions
...
...
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