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
6de0c8e9
Commit
6de0c8e9
authored
Aug 19, 2021
by
A. Unique TensorFlower
Browse files
Internal change
PiperOrigin-RevId: 391807562
parent
9b6b95a8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
10 deletions
+24
-10
official/nlp/serving/serving_modules.py
official/nlp/serving/serving_modules.py
+24
-10
No files found.
official/nlp/serving/serving_modules.py
View file @
6de0c8e9
...
@@ -80,12 +80,10 @@ class SentencePrediction(export_base.ExportModule):
...
@@ -80,12 +80,10 @@ class SentencePrediction(export_base.ExportModule):
lower_case
=
params
.
lower_case
,
lower_case
=
params
.
lower_case
,
preprocessing_hub_module_url
=
params
.
preprocessing_hub_module_url
)
preprocessing_hub_module_url
=
params
.
preprocessing_hub_module_url
)
@
tf
.
function
def
_serve_tokenized_input
(
self
,
def
serve
(
self
,
input_word_ids
,
input_word_ids
,
input_mask
=
None
,
input_mask
=
None
,
input_type_ids
=
None
)
->
tf
.
Tensor
:
input_type_ids
=
None
,
use_prob
=
False
)
->
Dict
[
str
,
tf
.
Tensor
]:
if
input_type_ids
is
None
:
if
input_type_ids
is
None
:
# Requires CLS token is the first token of inputs.
# Requires CLS token is the first token of inputs.
input_type_ids
=
tf
.
zeros_like
(
input_word_ids
)
input_type_ids
=
tf
.
zeros_like
(
input_word_ids
)
...
@@ -98,10 +96,26 @@ class SentencePrediction(export_base.ExportModule):
...
@@ -98,10 +96,26 @@ class SentencePrediction(export_base.ExportModule):
input_word_ids
=
input_word_ids
,
input_word_ids
=
input_word_ids
,
input_mask
=
input_mask
,
input_mask
=
input_mask
,
input_type_ids
=
input_type_ids
)
input_type_ids
=
input_type_ids
)
if
not
use_prob
:
return
self
.
inference_step
(
inputs
)
return
dict
(
outputs
=
self
.
inference_step
(
inputs
))
else
:
@
tf
.
function
return
dict
(
outputs
=
tf
.
nn
.
softmax
(
self
.
inference_step
(
inputs
)))
def
serve
(
self
,
input_word_ids
,
input_mask
=
None
,
input_type_ids
=
None
)
->
Dict
[
str
,
tf
.
Tensor
]:
return
dict
(
outputs
=
self
.
_serve_tokenized_input
(
input_word_ids
,
input_mask
,
input_type_ids
))
@
tf
.
function
def
serve_probability
(
self
,
input_word_ids
,
input_mask
=
None
,
input_type_ids
=
None
)
->
Dict
[
str
,
tf
.
Tensor
]:
return
dict
(
outputs
=
tf
.
nn
.
softmax
(
self
.
_serve_tokenized_input
(
input_word_ids
,
input_mask
,
input_type_ids
)))
@
tf
.
function
@
tf
.
function
def
serve_examples
(
self
,
inputs
)
->
Dict
[
str
,
tf
.
Tensor
]:
def
serve_examples
(
self
,
inputs
)
->
Dict
[
str
,
tf
.
Tensor
]:
...
...
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