TensorFlow 2.0 Beta is available Learn more

tf.lookup.StaticVocabularyTable

Class StaticVocabularyTable

Inherits From: StaticVocabularyTable

Aliases:

  • Class tf.compat.v1.lookup.StaticVocabularyTable
  • Class tf.lookup.StaticVocabularyTable
View source on GitHub

__init__

View source

__init__(
    initializer,
    num_oov_buckets,
    lookup_key_dtype=None,
    name=None
)

Construct a StaticVocabularyTable object.

Args:

  • initializer: A TableInitializerBase object that contains the data used to initialize the table. If None, then we only use out-of-vocab buckets.
  • num_oov_buckets: Number of buckets to use for out-of-vocabulary keys. Must be greater than zero.
  • lookup_key_dtype: Data type of keys passed to lookup. Defaults to initializer.key_dtype if initializer is specified, otherwise tf.string. Must be string or integer, and must be castable to initializer.key_dtype.
  • name: A name for the operation (optional).

Raises:

  • ValueError: when num_oov_buckets is not positive.
  • TypeError: when lookup_key_dtype or initializer.key_dtype are not integer or string. Also when initializer.value_dtype != int64.

Properties

initializer

key_dtype

The table key dtype.

name

resource_handle

value_dtype

The table value dtype.

Methods

lookup

View source

lookup(
    keys,
    name=None
)

Looks up keys in the table, outputs the corresponding values.

It assigns out-of-vocabulary keys to buckets based in their hashes.

Args:

  • keys: Keys to look up. May be either a SparseTensor or dense Tensor.
  • name: Optional name for the op.

Returns:

A SparseTensor if keys are sparse, otherwise a dense Tensor.

Raises:

  • TypeError: when keys doesn't match the table key data type.

size

View source

size(name=None)

Compute the number of elements in this table.