# tf.contrib.lookup.string_to_index

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/contrib/lookup/lookup_ops.py#L146-L192) |

Maps `tensor` of strings into `int64` indices based on `mapping`. (deprecated)

    tf.contrib.lookup.string_to_index(
        tensor, mapping, default_value=-1, name=None
    )

> [!WARNING]
> **Warning:** THIS FUNCTION IS DEPRECATED. It will be removed after 2017-01-07. Instructions for updating: This op will be removed after the deprecation date. Please switch to index_table_from_tensor and call the lookup method of the returned table.

This operation converts `tensor` of strings into `int64` indices.
The mapping is initialized from a string `mapping` tensor where each element
is a key and corresponding index within the tensor is the value.

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

Elements in `mapping` cannot be duplicated, otherwise the initialization
will throw a FailedPreconditionError.

The underlying table must be initialized by calling
`session.run(tf.compat.v1.tables_initializer)` once.

#### For example:

    mapping_strings = tf.constant(["emerson", "lake", "palmer"])
    feats = tf.constant(["emerson", "lake", "and", "palmer"])
    ids = tf.contrib.lookup.string_to_index(
        feats, mapping=mapping_strings, default_value=-1)
    ...
    tf.compat.v1.tables_initializer().run()

    ids.eval()  ==> [0, 1, -1, 2]

<br />

<br />

<br />

| ## Args ||
|---|---|
| `tensor` | A 1-D input `Tensor` with the strings to map to indices. |
| `mapping` | A 1-D string `Tensor` that specifies the mapping of strings to indices. |
| `default_value` | The `int64` value to use for out-of-vocabulary strings. Defaults to -1. |
| `name` | A name for this op (optional). |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| The mapped indices. It has the same shape and tensor type (dense or sparse) as `tensor`. ||

<br />