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
ef99be0b
Commit
ef99be0b
authored
Jun 10, 2020
by
A. Unique TensorFlower
Browse files
Internal change
PiperOrigin-RevId: 315789209
parent
dc9c75dd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
3 deletions
+14
-3
official/nlp/modeling/networks/classification.py
official/nlp/modeling/networks/classification.py
+7
-1
official/nlp/tasks/masked_lm.py
official/nlp/tasks/masked_lm.py
+7
-2
No files found.
official/nlp/modeling/networks/classification.py
View file @
ef99be0b
...
@@ -63,7 +63,13 @@ class Classification(tf.keras.Model):
...
@@ -63,7 +63,13 @@ class Classification(tf.keras.Model):
kernel_initializer
=
initializer
,
kernel_initializer
=
initializer
,
name
=
'predictions/transform/logits'
)(
name
=
'predictions/transform/logits'
)(
cls_output
)
cls_output
)
predictions
=
tf
.
keras
.
layers
.
Activation
(
tf
.
nn
.
log_softmax
)(
self
.
logits
)
policy
=
tf
.
keras
.
mixed_precision
.
experimental
.
global_policy
()
if
policy
.
name
==
'mixed_bfloat16'
:
# b/158514794: bf16 is not stable with post-softmax cross-entropy.
policy
=
tf
.
float32
predictions
=
tf
.
keras
.
layers
.
Activation
(
tf
.
nn
.
log_softmax
,
dtype
=
policy
)(
self
.
logits
)
if
output
==
'logits'
:
if
output
==
'logits'
:
output_tensors
=
self
.
logits
output_tensors
=
self
.
logits
...
...
official/nlp/tasks/masked_lm.py
View file @
ef99be0b
...
@@ -55,11 +55,16 @@ class MaskedLMTask(base_task.Task):
...
@@ -55,11 +55,16 @@ class MaskedLMTask(base_task.Task):
weights
=
features
[
'masked_lm_weights'
])
weights
=
features
[
'masked_lm_weights'
])
metrics
[
'lm_example_loss'
].
update_state
(
mlm_loss
)
metrics
[
'lm_example_loss'
].
update_state
(
mlm_loss
)
if
'next_sentence_labels'
in
features
:
if
'next_sentence_labels'
in
features
:
policy
=
tf
.
keras
.
mixed_precision
.
experimental
.
global_policy
()
if
policy
.
name
==
'mixed_bfloat16'
:
# b/158514794: bf16 is not stable.
policy
=
tf
.
float32
predictions
=
tf
.
keras
.
layers
.
Activation
(
tf
.
nn
.
log_softmax
,
dtype
=
policy
)(
model_outputs
[
'next_sentence'
])
sentence_labels
=
features
[
'next_sentence_labels'
]
sentence_labels
=
features
[
'next_sentence_labels'
]
sentence_loss
=
loss_lib
.
weighted_sparse_categorical_crossentropy_loss
(
sentence_loss
=
loss_lib
.
weighted_sparse_categorical_crossentropy_loss
(
labels
=
sentence_labels
,
labels
=
sentence_labels
,
predictions
=
tf
.
nn
.
log_softmax
(
predictions
=
predictions
)
model_outputs
[
'next_sentence'
],
axis
=-
1
))
metrics
[
'next_sentence_loss'
].
update_state
(
sentence_loss
)
metrics
[
'next_sentence_loss'
].
update_state
(
sentence_loss
)
total_loss
=
mlm_loss
+
sentence_loss
total_loss
=
mlm_loss
+
sentence_loss
else
:
else
:
...
...
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