tf.compat.v1.lookup.StaticVocabularyTable

View source on GitHub

String to Id table wrapper that assigns out-of-vocabulary keys to buckets.

Inherits From: StaticVocabularyTable

tf.compat.v1.lookup.StaticVocabularyTable(
    initializer, num_oov_buckets, lookup_key_dtype=None, name=None
)

For example, if an instance of StaticVocabularyTable is initialized with a string-to-id initializer that maps:

The Vocabulary object will performs the following mapping:

If input_tensor is ["emerson", "lake", "palmer", "king", "crimson"], the lookup result is [0, 1, 2, 4, 7].

If initializer is None, only out-of-vocabulary buckets are used.

Example usage:

num_oov_buckets = 3
input_tensor = tf.constant(["emerson", "lake", "palmer", "king", "crimnson"])
table = tf.lookup.StaticVocabularyTable(
    tf.TextFileIdTableInitializer(filename), num_oov_buckets)
out = table.lookup(input_tensor).
table.init.run()
print(out.eval())

The hash function used for generating out-of-vocabulary buckets ID is Fingerprint64.

Args:

Attributes:

Raises:

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:

Returns:

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

Raises:

size

View source

size(
    name=None
)

Compute the number of elements in this table.