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
67f81649
Commit
67f81649
authored
Jul 18, 2019
by
guptapriya
Browse files
Remove loss layer
parent
ffbada72
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
22 deletions
+0
-22
official/transformer/v2/metrics.py
official/transformer/v2/metrics.py
+0
-22
No files found.
official/transformer/v2/metrics.py
View file @
67f81649
...
...
@@ -181,25 +181,3 @@ def transformer_loss(logits, labels, smoothing, vocab_size):
xentropy
,
weights
=
padded_cross_entropy_loss
(
logits
,
labels
,
smoothing
,
vocab_size
)
return
tf
.
reduce_sum
(
xentropy
)
/
tf
.
reduce_sum
(
weights
)
class
LossLayer
(
tf
.
keras
.
layers
.
Layer
):
"""Custom a layer of transformer loss for Transformer model."""
def
__init__
(
self
,
vocab_size
,
label_smoothing
):
super
(
LossLayer
,
self
).
__init__
()
self
.
vocab_size
=
vocab_size
self
.
label_smoothing
=
label_smoothing
def
get_config
(
self
):
return
{
"vocab_size"
:
self
.
vocab_size
,
"label_smoothing"
:
self
.
label_smoothing
,
}
def
call
(
self
,
inputs
):
logits
,
targets
=
inputs
[
0
],
inputs
[
1
]
loss
=
transformer_loss
(
logits
,
targets
,
self
.
label_smoothing
,
self
.
vocab_size
)
self
.
add_loss
(
loss
)
return
logits
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