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
fcff6f65
Commit
fcff6f65
authored
Sep 09, 2020
by
Zhenyu Tan
Committed by
A. Unique TensorFlower
Sep 09, 2020
Browse files
BertEncoder to ingest OnDeviceEmbedding from keras_nlp.
PiperOrigin-RevId: 330767398
parent
ad65d85b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
5 deletions
+4
-5
official/nlp/modeling/networks/bert_encoder.py
official/nlp/modeling/networks/bert_encoder.py
+4
-5
No files found.
official/nlp/modeling/networks/bert_encoder.py
View file @
fcff6f65
...
@@ -19,7 +19,6 @@ import tensorflow as tf
...
@@ -19,7 +19,6 @@ import tensorflow as tf
from
official.modeling
import
activations
from
official.modeling
import
activations
from
official.nlp
import
keras_nlp
from
official.nlp
import
keras_nlp
from
official.nlp.modeling
import
layers
@
tf
.
keras
.
utils
.
register_keras_serializable
(
package
=
'Text'
)
@
tf
.
keras
.
utils
.
register_keras_serializable
(
package
=
'Text'
)
...
@@ -123,7 +122,7 @@ class BertEncoder(tf.keras.Model):
...
@@ -123,7 +122,7 @@ class BertEncoder(tf.keras.Model):
if
embedding_width
is
None
:
if
embedding_width
is
None
:
embedding_width
=
hidden_size
embedding_width
=
hidden_size
if
embedding_layer
is
None
:
if
embedding_layer
is
None
:
self
.
_embedding_layer
=
layers
.
OnDeviceEmbedding
(
self
.
_embedding_layer
=
keras_nlp
.
layers
.
OnDeviceEmbedding
(
vocab_size
=
vocab_size
,
vocab_size
=
vocab_size
,
embedding_width
=
embedding_width
,
embedding_width
=
embedding_width
,
initializer
=
initializer
,
initializer
=
initializer
,
...
@@ -133,12 +132,12 @@ class BertEncoder(tf.keras.Model):
...
@@ -133,12 +132,12 @@ class BertEncoder(tf.keras.Model):
word_embeddings
=
self
.
_embedding_layer
(
word_ids
)
word_embeddings
=
self
.
_embedding_layer
(
word_ids
)
# Always uses dynamic slicing for simplicity.
# Always uses dynamic slicing for simplicity.
self
.
_position_embedding_layer
=
keras_nlp
.
PositionEmbedding
(
self
.
_position_embedding_layer
=
keras_nlp
.
layers
.
PositionEmbedding
(
initializer
=
initializer
,
initializer
=
initializer
,
max_length
=
max_sequence_length
,
max_length
=
max_sequence_length
,
name
=
'position_embedding'
)
name
=
'position_embedding'
)
position_embeddings
=
self
.
_position_embedding_layer
(
word_embeddings
)
position_embeddings
=
self
.
_position_embedding_layer
(
word_embeddings
)
self
.
_type_embedding_layer
=
layers
.
OnDeviceEmbedding
(
self
.
_type_embedding_layer
=
keras_nlp
.
layers
.
OnDeviceEmbedding
(
vocab_size
=
type_vocab_size
,
vocab_size
=
type_vocab_size
,
embedding_width
=
embedding_width
,
embedding_width
=
embedding_width
,
initializer
=
initializer
,
initializer
=
initializer
,
...
@@ -168,7 +167,7 @@ class BertEncoder(tf.keras.Model):
...
@@ -168,7 +167,7 @@ class BertEncoder(tf.keras.Model):
self
.
_transformer_layers
=
[]
self
.
_transformer_layers
=
[]
data
=
embeddings
data
=
embeddings
attention_mask
=
keras_nlp
.
SelfAttentionMask
()(
data
,
mask
)
attention_mask
=
keras_nlp
.
layers
.
SelfAttentionMask
()(
data
,
mask
)
encoder_outputs
=
[]
encoder_outputs
=
[]
for
i
in
range
(
num_layers
):
for
i
in
range
(
num_layers
):
if
i
==
num_layers
-
1
and
output_range
is
not
None
:
if
i
==
num_layers
-
1
and
output_range
is
not
None
:
...
...
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