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
fa876aee
Unverified
Commit
fa876aee
authored
Jan 19, 2021
by
Julien Plu
Committed by
GitHub
Jan 19, 2021
Browse files
Fix TF Flaubert and XLM (#9661)
* Fix Flaubert and XLM * Fix Flaubert and XLM * Apply style
parent
11ec7490
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
10 deletions
+22
-10
src/transformers/models/flaubert/modeling_tf_flaubert.py
src/transformers/models/flaubert/modeling_tf_flaubert.py
+6
-3
src/transformers/models/xlm/modeling_tf_xlm.py
src/transformers/models/xlm/modeling_tf_xlm.py
+16
-7
No files found.
src/transformers/models/flaubert/modeling_tf_flaubert.py
View file @
fa876aee
...
@@ -214,10 +214,13 @@ class TFFlaubertPreTrainedModel(TFPreTrainedModel):
...
@@ -214,10 +214,13 @@ class TFFlaubertPreTrainedModel(TFPreTrainedModel):
inputs_list
=
tf
.
constant
([[
7
,
6
,
0
,
0
,
1
],
[
1
,
2
,
3
,
0
,
0
],
[
0
,
0
,
0
,
4
,
5
]])
inputs_list
=
tf
.
constant
([[
7
,
6
,
0
,
0
,
1
],
[
1
,
2
,
3
,
0
,
0
],
[
0
,
0
,
0
,
4
,
5
]])
attns_list
=
tf
.
constant
([[
1
,
1
,
0
,
0
,
1
],
[
1
,
1
,
1
,
0
,
0
],
[
1
,
0
,
0
,
1
,
1
]])
attns_list
=
tf
.
constant
([[
1
,
1
,
0
,
0
,
1
],
[
1
,
1
,
1
,
0
,
0
],
[
1
,
0
,
0
,
1
,
1
]])
if
self
.
config
.
use_lang_emb
and
self
.
config
.
n_langs
>
1
:
if
self
.
config
.
use_lang_emb
and
self
.
config
.
n_langs
>
1
:
langs_list
=
tf
.
constant
([[
1
,
1
,
0
,
0
,
1
],
[
1
,
1
,
1
,
0
,
0
],
[
1
,
0
,
0
,
1
,
1
]])
return
{
"input_ids"
:
inputs_list
,
"attention_mask"
:
attns_list
,
"langs"
:
tf
.
constant
([[
1
,
1
,
0
,
0
,
1
],
[
1
,
1
,
1
,
0
,
0
],
[
1
,
0
,
0
,
1
,
1
]]),
}
else
:
else
:
langs_list
=
None
return
{
"input_ids"
:
inputs_list
,
"attention_mask"
:
attns_list
}
return
{
"input_ids"
:
inputs_list
,
"attention_mask"
:
attns_list
,
"langs"
:
langs_list
}
@
add_start_docstrings
(
@
add_start_docstrings
(
...
...
src/transformers/models/xlm/modeling_tf_xlm.py
View file @
fa876aee
...
@@ -536,10 +536,13 @@ class TFXLMPreTrainedModel(TFPreTrainedModel):
...
@@ -536,10 +536,13 @@ class TFXLMPreTrainedModel(TFPreTrainedModel):
inputs_list
=
tf
.
constant
([[
7
,
6
,
0
,
0
,
1
],
[
1
,
2
,
3
,
0
,
0
],
[
0
,
0
,
0
,
4
,
5
]])
inputs_list
=
tf
.
constant
([[
7
,
6
,
0
,
0
,
1
],
[
1
,
2
,
3
,
0
,
0
],
[
0
,
0
,
0
,
4
,
5
]])
attns_list
=
tf
.
constant
([[
1
,
1
,
0
,
0
,
1
],
[
1
,
1
,
1
,
0
,
0
],
[
1
,
0
,
0
,
1
,
1
]])
attns_list
=
tf
.
constant
([[
1
,
1
,
0
,
0
,
1
],
[
1
,
1
,
1
,
0
,
0
],
[
1
,
0
,
0
,
1
,
1
]])
if
self
.
config
.
use_lang_emb
and
self
.
config
.
n_langs
>
1
:
if
self
.
config
.
use_lang_emb
and
self
.
config
.
n_langs
>
1
:
langs_list
=
tf
.
constant
([[
1
,
1
,
0
,
0
,
1
],
[
1
,
1
,
1
,
0
,
0
],
[
1
,
0
,
0
,
1
,
1
]])
return
{
"input_ids"
:
inputs_list
,
"attention_mask"
:
attns_list
,
"langs"
:
tf
.
constant
([[
1
,
1
,
0
,
0
,
1
],
[
1
,
1
,
1
,
0
,
0
],
[
1
,
0
,
0
,
1
,
1
]]),
}
else
:
else
:
langs_list
=
None
return
{
"input_ids"
:
inputs_list
,
"attention_mask"
:
attns_list
}
return
{
"input_ids"
:
inputs_list
,
"attention_mask"
:
attns_list
,
"langs"
:
langs_list
}
# Remove when XLMWithLMHead computes loss like other LM models
# Remove when XLMWithLMHead computes loss like other LM models
...
@@ -1045,10 +1048,16 @@ class TFXLMForMultipleChoice(TFXLMPreTrainedModel, TFMultipleChoiceLoss):
...
@@ -1045,10 +1048,16 @@ class TFXLMForMultipleChoice(TFXLMPreTrainedModel, TFMultipleChoiceLoss):
Returns:
Returns:
tf.Tensor with dummy inputs
tf.Tensor with dummy inputs
"""
"""
return
{
# Sometimes XLM has language embeddings so don't forget to build them as well if needed
"input_ids"
:
tf
.
constant
(
MULTIPLE_CHOICE_DUMMY_INPUTS
),
if
self
.
config
.
use_lang_emb
and
self
.
config
.
n_langs
>
1
:
"langs"
:
tf
.
constant
(
MULTIPLE_CHOICE_DUMMY_INPUTS
),
return
{
}
"input_ids"
:
tf
.
constant
(
MULTIPLE_CHOICE_DUMMY_INPUTS
),
"langs"
:
tf
.
constant
(
MULTIPLE_CHOICE_DUMMY_INPUTS
),
}
else
:
return
{
"input_ids"
:
tf
.
constant
(
MULTIPLE_CHOICE_DUMMY_INPUTS
),
}
@
add_start_docstrings_to_model_forward
(
XLM_INPUTS_DOCSTRING
.
format
(
"batch_size, num_choices, sequence_length"
))
@
add_start_docstrings_to_model_forward
(
XLM_INPUTS_DOCSTRING
.
format
(
"batch_size, num_choices, sequence_length"
))
@
add_code_sample_docstrings
(
@
add_code_sample_docstrings
(
...
...
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