tf.contrib.lookup.index_to_string_table_from_tensor
Returns a lookup table that maps a Tensor of indices into strings.
tf.contrib.lookup.index_to_string_table_from_tensor(
mapping, default_value='UNK', name=None
)
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 session.run(tf.compat.v1.tables_initializer) or session.run(table.init) once.
Elements in mapping cannot have duplicates, otherwise when executing the table initializer op, it will throw a FailedPreconditionError.
Sample Usages:
mapping_string = tf.constant(["emerson", "lake", "palmer"])
indices = tf.constant([1, 5], tf.int64)
table = tf.contrib.lookup.index_to_string_table_from_tensor(
mapping_string, default_value="UNKNOWN")
values = table.lookup(indices)
...
tf.compat.v1.tables_initializer().run()
values.eval() ==> ["lake", "UNKNOWN"]
| Args | |
|---|---|
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). |
| Returns | |
|---|---|
The lookup table to map a string values associated to a given index int64 Tensors. |
| Raises | |
|---|---|
ValueError | when mapping is not set. |
© 2020 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 3.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/contrib/lookup/index_to_string_table_from_tensor