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
e5f021ce
Commit
e5f021ce
authored
Feb 14, 2020
by
Hongkun Yu
Committed by
A. Unique TensorFlower
Feb 14, 2020
Browse files
[Refactor] Deprecate nlp/bert_modeling.py as the bert models are using new implementation.
PiperOrigin-RevId: 295231490
parent
f2882f6e
Changes
2
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
878 deletions
+22
-878
official/nlp/bert_modeling.py
official/nlp/bert_modeling.py
+0
-865
official/nlp/transformer/attention_layer.py
official/nlp/transformer/attention_layer.py
+22
-13
No files found.
official/nlp/bert_modeling.py
deleted
100644 → 0
View file @
f2882f6e
This diff is collapsed.
Click to expand it.
official/nlp/transformer/attention_layer.py
View file @
e5f021ce
...
...
@@ -19,7 +19,7 @@ from __future__ import division
from
__future__
import
print_function
import
tensorflow
as
tf
from
official.nlp
import
bert_modeling
as
common_
layer
from
official.nlp
.modeling
import
layer
s
class
Attention
(
tf
.
keras
.
layers
.
Layer
):
...
...
@@ -47,18 +47,27 @@ class Attention(tf.keras.layers.Layer):
"""Builds the layer."""
# Layers for linearly projecting the queries, keys, and values.
size_per_head
=
self
.
hidden_size
//
self
.
num_heads
self
.
query_dense_layer
=
common_layer
.
Dense3D
(
self
.
num_heads
,
size_per_head
,
kernel_initializer
=
"glorot_uniform"
,
use_bias
=
False
,
name
=
"query"
)
self
.
key_dense_layer
=
common_layer
.
Dense3D
(
self
.
num_heads
,
size_per_head
,
kernel_initializer
=
"glorot_uniform"
,
use_bias
=
False
,
name
=
"key"
)
self
.
value_dense_layer
=
common_layer
.
Dense3D
(
self
.
num_heads
,
size_per_head
,
kernel_initializer
=
"glorot_uniform"
,
use_bias
=
False
,
name
=
"value"
)
self
.
output_dense_layer
=
common_layer
.
Dense3D
(
self
.
num_heads
,
size_per_head
,
kernel_initializer
=
"glorot_uniform"
,
use_bias
=
False
,
output_projection
=
True
,
name
=
"output_transform"
)
self
.
query_dense_layer
=
layers
.
DenseEinsum
(
output_shape
=
(
self
.
num_heads
,
size_per_head
),
kernel_initializer
=
"glorot_uniform"
,
use_bias
=
False
,
name
=
"query"
)
self
.
key_dense_layer
=
layers
.
DenseEinsum
(
output_shape
=
(
self
.
num_heads
,
size_per_head
),
kernel_initializer
=
"glorot_uniform"
,
use_bias
=
False
,
name
=
"key"
)
self
.
value_dense_layer
=
layers
.
DenseEinsum
(
output_shape
=
(
self
.
num_heads
,
size_per_head
),
kernel_initializer
=
"glorot_uniform"
,
use_bias
=
False
,
name
=
"value"
)
self
.
output_dense_layer
=
layers
.
DenseEinsum
(
output_shape
=
self
.
hidden_size
,
num_summed_dimensions
=
2
,
kernel_initializer
=
"glorot_uniform"
,
use_bias
=
False
,
name
=
"output_transform"
)
super
(
Attention
,
self
).
build
(
input_shape
)
def
get_config
(
self
):
...
...
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