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
36db2450
Commit
36db2450
authored
Dec 09, 2020
by
Poorva Potdar
Committed by
A. Unique TensorFlower
Dec 09, 2020
Browse files
Internal change
PiperOrigin-RevId: 346570482
parent
a5ed2bb7
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
5 deletions
+5
-5
official/nlp/modeling/ops/sampling_module.py
official/nlp/modeling/ops/sampling_module.py
+5
-5
No files found.
official/nlp/modeling/ops/sampling_module.py
View file @
36db2450
...
@@ -25,7 +25,7 @@ from official.nlp.modeling.ops import decoding_module
...
@@ -25,7 +25,7 @@ from official.nlp.modeling.ops import decoding_module
def
greedy
(
log_probs
):
def
greedy
(
log_probs
):
"""Returns the top ids and scores based on greedy decoding."""
"""Returns the top ids and scores based on greedy decoding."""
log_probs
,
ids
=
tf
.
nn
.
top_k
(
log_probs
,
k
=
1
)
log_probs
,
ids
=
tf
.
math
.
top_k
(
log_probs
,
k
=
1
)
return
log_probs
,
ids
return
log_probs
,
ids
...
@@ -56,9 +56,9 @@ def sample_top_k(logits, top_k):
...
@@ -56,9 +56,9 @@ def sample_top_k(logits, top_k):
Logits with top_k filtering applied.
Logits with top_k filtering applied.
"""
"""
top_k_logits
=
tf
.
math
.
top_k
(
logits
,
k
=
top_k
)
top_k_logits
=
tf
.
math
.
top_k
(
logits
,
k
=
top_k
)
indices_to_remove
=
logits
<
top_k_logits
[
0
][...,
-
1
,
None
]
indices_to_remove
=
logits
<
tf
.
expand_dims
(
top_k_logits
[
0
][...,
-
1
]
,
-
1
)
top_k_logits
=
set_tensor_by_indices_to_value
(
top_k_logits
=
set_tensor_by_indices_to_value
(
logits
,
indices_to_remove
,
logits
,
indices_to_remove
,
np
.
NINF
)
np
.
NINF
)
return
top_k_logits
return
top_k_logits
...
@@ -425,7 +425,7 @@ class SamplingModule(decoding_module.DecodingModule, metaclass=abc.ABCMeta):
...
@@ -425,7 +425,7 @@ class SamplingModule(decoding_module.DecodingModule, metaclass=abc.ABCMeta):
finished_cond
,
finished_seq
)
finished_cond
,
finished_seq
)
score_cond
=
decoding_module
.
expand_to_same_rank
(
score_cond
=
decoding_module
.
expand_to_same_rank
(
finished_cond
,
finished_scores
)
finished_cond
,
finished_scores
)
finished_seq
=
tf
.
where
(
seq_cond
,
finished_seq
,
alive_seq
,
finished_scores
)
finished_seq
=
tf
.
where
(
seq_cond
,
finished_seq
,
alive_seq
)
finished_scores
=
tf
.
where
(
score_cond
,
finished_scores
,
alive_log_probs
)
finished_scores
=
tf
.
where
(
score_cond
,
finished_scores
,
alive_log_probs
)
return
finished_seq
,
finished_scores
return
finished_seq
,
finished_scores
...
...
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