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
ModelZoo
ResNet50_tensorflow
Commits
e6ffa057
Commit
e6ffa057
authored
Sep 16, 2020
by
Hongkun Yu
Committed by
A. Unique TensorFlower
Sep 16, 2020
Browse files
Internal change
PiperOrigin-RevId: 332092620
parent
4ab0b381
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
1 addition
and
36 deletions
+1
-36
official/nlp/modeling/layers/transformer_scaffold.py
official/nlp/modeling/layers/transformer_scaffold.py
+1
-12
official/nlp/modeling/layers/transformer_scaffold_test.py
official/nlp/modeling/layers/transformer_scaffold_test.py
+0
-24
No files found.
official/nlp/modeling/layers/transformer_scaffold.py
View file @
e6ffa057
...
@@ -115,18 +115,7 @@ class TransformerScaffold(tf.keras.layers.Layer):
...
@@ -115,18 +115,7 @@ class TransformerScaffold(tf.keras.layers.Layer):
raise
ValueError
(
raise
ValueError
(
"TransformerScaffold expects a three-dimensional input of "
"TransformerScaffold expects a three-dimensional input of "
"shape [batch, sequence, width]."
)
"shape [batch, sequence, width]."
)
batch_size
,
sequence_length
,
hidden_size
=
input_tensor_shape
hidden_size
=
input_tensor_shape
[
-
1
]
if
len
(
input_shape
)
==
2
:
mask_tensor_shape
=
tf
.
TensorShape
(
input_shape
[
1
])
expected_mask_tensor_shape
=
tf
.
TensorShape
(
[
batch_size
,
sequence_length
,
sequence_length
])
if
not
expected_mask_tensor_shape
.
is_compatible_with
(
mask_tensor_shape
):
raise
ValueError
(
"When passing a mask tensor to TransformerLayer, the "
"mask tensor must be of shape [batch, "
"sequence_length, sequence_length] (here %s). Got a "
"mask tensor of shape %s."
%
(
expected_mask_tensor_shape
,
mask_tensor_shape
))
if
hidden_size
%
self
.
_num_heads
!=
0
:
if
hidden_size
%
self
.
_num_heads
!=
0
:
raise
ValueError
(
raise
ValueError
(
"The input size (%d) is not a multiple of the number of attention "
"The input size (%d) is not a multiple of the number of attention "
...
...
official/nlp/modeling/layers/transformer_scaffold_test.py
View file @
e6ffa057
...
@@ -182,30 +182,6 @@ class TransformerLayerTest(keras_parameterized.TestCase):
...
@@ -182,30 +182,6 @@ class TransformerLayerTest(keras_parameterized.TestCase):
self
.
assertNotEmpty
(
call_list
)
self
.
assertNotEmpty
(
call_list
)
self
.
assertTrue
(
call_list
[
0
],
"The passed layer class wasn't instantiated."
)
self
.
assertTrue
(
call_list
[
0
],
"The passed layer class wasn't instantiated."
)
def
test_layer_creation_with_incorrect_mask_fails
(
self
):
sequence_length
=
21
width
=
80
call_list
=
[]
attention_layer_cfg
=
{
'num_heads'
:
10
,
'key_dim'
:
8
,
'call_list'
:
call_list
,
}
test_layer
=
transformer_scaffold
.
TransformerScaffold
(
attention_cls
=
ValidatedAttentionLayer
,
attention_cfg
=
attention_layer_cfg
,
num_attention_heads
=
10
,
intermediate_size
=
2048
,
intermediate_activation
=
'relu'
)
# Create a 3-dimensional input (the first dimension is implicit).
data_tensor
=
tf
.
keras
.
Input
(
shape
=
(
sequence_length
,
width
))
# Create a 2-dimensional input (the first dimension is implicit).
mask_tensor
=
tf
.
keras
.
Input
(
shape
=
(
sequence_length
,
sequence_length
-
3
))
with
self
.
assertRaisesRegex
(
ValueError
,
'When passing a mask tensor.*'
):
_
=
test_layer
([
data_tensor
,
mask_tensor
])
def
test_layer_invocation
(
self
):
def
test_layer_invocation
(
self
):
sequence_length
=
21
sequence_length
=
21
width
=
80
width
=
80
...
...
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