tf.contrib.lookup.index_to_string_table_from_tensor(mapping, default_value='UNK', name=None)

tf.contrib.lookup.index_to_string_table_from_tensor(mapping, default_value='UNK', name=None)

Returns a lookup table that maps a Tensor of indices into strings.

This operation constructs a lookup table to map int64 indices into string values. The mapping is initialized from a string mapping 1-D Tensor where each element is a value and the corresponding index within the tensor is the key.

Any input which does not have a corresponding index in 'mapping' (an out-of-vocabulary entry) is assigned the default_value

The underlying table must be initialized by calling or once.

Elements in mapping cannot have duplicates, otherwise when executing the table initializer op, it will throw a FailedPreconditionError.

Sample Usages:

mapping_string = t.constant(["emerson", "lake", "palmer")
indices = tf.constant([1, 5], tf.int64)
table = tf.contrib.lookup.index_to_string_from_tensor(
    mapping_string, default_value="UNKNOWN")
values = table.lookup(indices)

values.eval() ==> ["lake", "UNKNOWN"]


  • mapping: A 1-D string Tensor that specifies the strings to map from indices.
  • default_value: The value to use for out-of-vocabulary indices.
  • name: A name for this op (optional).


The lookup table to map a string values associated to a given index int64 Tensors.


  • ValueError: when mapping is not set.

Defined in tensorflow/contrib/lookup/