Have a question? Connect with the community at the TensorFlow Forum Visit Forum


Performs an embedding lookup suitable for accelerator devices.

This layer uses either tf.gather or tf.one_hot to translate integer indices to float embeddings.

vocab_size Number of elements in the vocabulary.
embedding_width Output size of the embedding layer.
initializer The initializer to use for the embedding weights. Defaults to "glorot_uniform".
use_one_hot Whether to use tf.one_hot over tf.gather for the embedding lookup. Defaults to False (that is, using tf.gather). Setting this option to True may improve performance, especially on small vocabulary sizes, but will generally require more memory.
scale_factor Whether to scale the output embeddings. Defaults to None (that is, not to scale). Setting this option to a float will let values in output embeddings multiplied by scale_factor.





This is where the layer's logic lives.

Note here that call() method in tf.keras is little bit different from keras API. In keras API, you can pass support masking for layers as additional arguments. Whereas tf.keras has compute_mask() method to support masking.

inputs Input tensor, or list/tuple of input tensors.
*args Additional positional arguments. Currently unused.
**kwargs Additional keyword arguments. Currently unused.

A tensor or list/tuple of tensors.