Skip to content

sparsemax returns nan for big values #2314

Open
@w4nderlust

Description

@w4nderlust

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Ubuntu 20.04
  • TensorFlow version and how it was installed (source or binary): 2.3.1
  • TensorFlow-Addons version and how it was installed (source or binary): 0.12.0-dev
  • Python version: 3.8.5
  • Is GPU used? (yes/no): yes

Describe the bug

For very large values, sparsemax returns NaN.

Code to reproduce the issue

import tensorflow_addos as tfa

tfa.activations.sparsemax([1.36762051e+6, 1.59594639e+6])
Out[0]: <tf.Tensor: shape=(2,), dtype=float32, numpy=array([0., 1.], dtype=float32)>
tfa.activations.sparsemax([1.36762051e+7, 1.59594639e+7])
Out[1]: <tf.Tensor: shape=(2,), dtype=float32, numpy=array([0., 1.], dtype=float32)>
tfa.activations.sparsemax([1.36762051e+8, 1.59594639e+8])
Out[2]: <tf.Tensor: shape=(2,), dtype=float32, numpy=array([nan, nan], dtype=float32)>
tfa.activations.sparsemax([1.36762051e+9, 1.59594639e+9])
Out[3]: <tf.Tensor: shape=(2,), dtype=float32, numpy=array([nan, nan], dtype=float32)>

spmx = tfa.layers.Sparsemax()
spmx([1.36762051e+6, 1.59594639e+6])
Out[4]: <tf.Tensor: shape=(2,), dtype=float32, numpy=array([0., 1.], dtype=float32)>
spmx([1.36762051e+7, 1.59594639e+7])
Out[5]: <tf.Tensor: shape=(2,), dtype=float32, numpy=array([0., 1.], dtype=float32)>
spmx([1.36762051e+8, 1.59594639e+8])
Out[6]: <tf.Tensor: shape=(2,), dtype=float32, numpy=array([nan, nan], dtype=float32)>

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions