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
7e12e4f4
"src/vscode:/vscode.git/clone" did not exist on "554b374d20edff433192e2925fff5c2f99b7cbf8"
Commit
7e12e4f4
authored
Nov 20, 2019
by
Chen Chen
Committed by
A. Unique TensorFlower
Nov 20, 2019
Browse files
Internal Change
PiperOrigin-RevId: 281630227
parent
e16594d1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
8 deletions
+8
-8
official/nlp/bert_models.py
official/nlp/bert_models.py
+8
-8
No files found.
official/nlp/bert_models.py
View file @
7e12e4f4
...
@@ -374,7 +374,8 @@ def squad_model(bert_config,
...
@@ -374,7 +374,8 @@ def squad_model(bert_config,
bert_config: BertConfig, the config defines the core Bert model.
bert_config: BertConfig, the config defines the core Bert model.
max_seq_length: integer, the maximum input sequence length.
max_seq_length: integer, the maximum input sequence length.
float_type: tf.dtype, tf.float32 or tf.bfloat16.
float_type: tf.dtype, tf.float32 or tf.bfloat16.
initializer: Initializer for weights in BertSquadLogitsLayer.
initializer: Initializer for the final dense layer in the span labeler.
Defaulted to TruncatedNormal initializer.
hub_module_url: TF-Hub path/url to Bert module.
hub_module_url: TF-Hub path/url to Bert module.
use_keras_bert: Whether to use keras BERT. Note that when the above
use_keras_bert: Whether to use keras BERT. Note that when the above
'hub_module_url' is specified, 'use_keras_bert' cannot be True.
'hub_module_url' is specified, 'use_keras_bert' cannot be True.
...
@@ -389,12 +390,14 @@ def squad_model(bert_config,
...
@@ -389,12 +390,14 @@ def squad_model(bert_config,
if
hub_module_url
and
use_keras_bert
:
if
hub_module_url
and
use_keras_bert
:
raise
ValueError
(
raise
ValueError
(
'Cannot use hub_module_url and keras BERT at the same time.'
)
'Cannot use hub_module_url and keras BERT at the same time.'
)
if
initializer
is
None
:
initializer
=
tf
.
keras
.
initializers
.
TruncatedNormal
(
stddev
=
bert_config
.
initializer_range
)
if
use_keras_bert
:
if
use_keras_bert
:
bert_encoder
=
_get_transformer_encoder
(
bert_encoder
=
_get_transformer_encoder
(
bert_config
,
max_seq_length
,
bert_config
,
max_seq_length
,
float_type
)
float_type
)
return
bert_span_labeler
.
BertSpanLabeler
(
return
bert_span_labeler
.
BertSpanLabeler
(
network
=
bert_encoder
),
bert_encoder
network
=
bert_encoder
,
initializer
=
initializer
),
bert_encoder
input_word_ids
=
tf
.
keras
.
layers
.
Input
(
input_word_ids
=
tf
.
keras
.
layers
.
Input
(
shape
=
(
max_seq_length
,),
dtype
=
tf
.
int32
,
name
=
'input_word_ids'
)
shape
=
(
max_seq_length
,),
dtype
=
tf
.
int32
,
name
=
'input_word_ids'
)
...
@@ -421,9 +424,6 @@ def squad_model(bert_config,
...
@@ -421,9 +424,6 @@ def squad_model(bert_config,
# has dimensionality (batch_size, sequence_length, num_hidden).
# has dimensionality (batch_size, sequence_length, num_hidden).
sequence_output
=
core_model
.
outputs
[
1
]
sequence_output
=
core_model
.
outputs
[
1
]
if
initializer
is
None
:
initializer
=
tf
.
keras
.
initializers
.
TruncatedNormal
(
stddev
=
bert_config
.
initializer_range
)
squad_logits_layer
=
BertSquadLogitsLayer
(
squad_logits_layer
=
BertSquadLogitsLayer
(
initializer
=
initializer
,
float_type
=
float_type
,
name
=
'squad_logits'
)
initializer
=
initializer
,
float_type
=
float_type
,
name
=
'squad_logits'
)
start_logits
,
end_logits
=
squad_logits_layer
(
sequence_output
)
start_logits
,
end_logits
=
squad_logits_layer
(
sequence_output
)
...
...
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