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
c813d85f
Commit
c813d85f
authored
Jan 22, 2020
by
Hongkun Yu
Committed by
A. Unique TensorFlower
Jan 22, 2020
Browse files
Remove pack_inputs/unpack_inputs in bert
PiperOrigin-RevId: 291082425
parent
df15a276
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
21 deletions
+3
-21
official/nlp/bert_models.py
official/nlp/bert_models.py
+3
-21
No files found.
official/nlp/bert_models.py
View file @
c813d85f
...
...
@@ -72,20 +72,6 @@ class BertPretrainLossAndMetricLayer(tf.keras.layers.Layer):
'vocab_size'
:
vocab_size
,
}
def
__call__
(
self
,
lm_output
,
sentence_output
=
None
,
lm_label_ids
=
None
,
lm_label_weights
=
None
,
sentence_labels
=
None
,
**
kwargs
):
inputs
=
tf_utils
.
pack_inputs
([
lm_output
,
sentence_output
,
lm_label_ids
,
lm_label_weights
,
sentence_labels
])
return
super
(
BertPretrainLossAndMetricLayer
,
self
).
__call__
(
inputs
,
**
kwargs
)
def
_add_metrics
(
self
,
lm_output
,
lm_labels
,
lm_label_weights
,
lm_example_loss
,
sentence_output
,
sentence_labels
,
next_sentence_loss
):
...
...
@@ -110,14 +96,10 @@ class BertPretrainLossAndMetricLayer(tf.keras.layers.Layer):
self
.
add_metric
(
next_sentence_loss
,
name
=
'next_sentence_loss'
,
aggregation
=
'mean'
)
def
call
(
self
,
inputs
):
def
call
(
self
,
lm_output
,
sentence_output
,
lm_label_ids
,
lm_label_weights
,
sentence_labels
):
"""Implements call() for the layer."""
unpacked_inputs
=
tf_utils
.
unpack_inputs
(
inputs
)
lm_output
=
unpacked_inputs
[
0
]
sentence_output
=
unpacked_inputs
[
1
]
lm_label_ids
=
unpacked_inputs
[
2
]
lm_label_weights
=
tf
.
keras
.
backend
.
cast
(
unpacked_inputs
[
3
],
tf
.
float32
)
sentence_labels
=
unpacked_inputs
[
4
]
lm_label_weights
=
tf
.
keras
.
backend
.
cast
(
lm_label_weights
,
tf
.
float32
)
mask_label_loss
=
losses
.
weighted_sparse_categorical_crossentropy_loss
(
labels
=
lm_label_ids
,
predictions
=
lm_output
,
weights
=
lm_label_weights
)
...
...
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