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
5bf1cc5f
Commit
5bf1cc5f
authored
Jun 03, 2022
by
A. Unique TensorFlower
Browse files
Ensure sample_top_k samples a valid number in SamplingModule.
PiperOrigin-RevId: 452839394
parent
6ddc94f6
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
2 additions
and
0 deletions
+2
-0
official/nlp/modeling/ops/sampling_module.py
official/nlp/modeling/ops/sampling_module.py
+2
-0
No files found.
official/nlp/modeling/ops/sampling_module.py
View file @
5bf1cc5f
...
...
@@ -55,6 +55,8 @@ def sample_top_k(logits, top_k):
Returns:
Logits with top_k filtering applied.
"""
top_k
=
tf
.
clip_by_value
(
top_k
,
clip_value_min
=
1
,
clip_value_max
=
tf
.
shape
(
logits
)[
-
1
])
top_k_logits
=
tf
.
math
.
top_k
(
logits
,
k
=
top_k
)
indices_to_remove
=
logits
<
tf
.
expand_dims
(
top_k_logits
[
0
][...,
-
1
],
-
1
)
top_k_logits
=
set_tensor_by_indices_to_value
(
logits
,
indices_to_remove
,
...
...
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