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
5e539a3d
Commit
5e539a3d
authored
Apr 21, 2020
by
A. Unique TensorFlower
Browse files
Test that training=True activates dropout in a reusable SavedModel for BERT.
PiperOrigin-RevId: 307633374
parent
1f685c54
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
0 deletions
+10
-0
official/nlp/bert/export_tfhub_test.py
official/nlp/bert/export_tfhub_test.py
+10
-0
No files found.
official/nlp/bert/export_tfhub_test.py
View file @
5e539a3d
...
@@ -84,6 +84,16 @@ class ExportTfhubTest(tf.test.TestCase):
...
@@ -84,6 +84,16 @@ class ExportTfhubTest(tf.test.TestCase):
self
.
assertAllClose
(
source_output
.
numpy
(),
hub_output
.
numpy
())
self
.
assertAllClose
(
source_output
.
numpy
(),
hub_output
.
numpy
())
self
.
assertAllClose
(
source_output
.
numpy
(),
encoder_output
.
numpy
())
self
.
assertAllClose
(
source_output
.
numpy
(),
encoder_output
.
numpy
())
# Test that training=True makes a difference (activates dropout).
def
_dropout_mean_stddev
(
training
,
num_runs
=
20
):
input_ids
=
np
.
array
([[
14
,
12
,
42
,
95
,
99
]],
np
.
int32
)
inputs
=
[
input_ids
,
np
.
ones_like
(
input_ids
),
np
.
zeros_like
(
input_ids
)]
outputs
=
np
.
concatenate
(
[
hub_layer
(
inputs
,
training
=
training
)[
0
]
for
_
in
range
(
num_runs
)])
return
np
.
mean
(
np
.
std
(
outputs
,
axis
=
0
))
self
.
assertLess
(
_dropout_mean_stddev
(
training
=
False
),
1e-6
)
self
.
assertGreater
(
_dropout_mean_stddev
(
training
=
True
),
1e-3
)
# Test propagation of seq_length in shape inference.
# Test propagation of seq_length in shape inference.
input_word_ids
=
tf
.
keras
.
layers
.
Input
(
shape
=
(
seq_length
,),
dtype
=
tf
.
int32
)
input_word_ids
=
tf
.
keras
.
layers
.
Input
(
shape
=
(
seq_length
,),
dtype
=
tf
.
int32
)
input_mask
=
tf
.
keras
.
layers
.
Input
(
shape
=
(
seq_length
,),
dtype
=
tf
.
int32
)
input_mask
=
tf
.
keras
.
layers
.
Input
(
shape
=
(
seq_length
,),
dtype
=
tf
.
int32
)
...
...
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