# tf.contrib.lookup.HashTable

<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#L294-L372) |

A generic hash table implementation.

    tf.contrib.lookup.HashTable(
        initializer, default_value, shared_name=None, name=None
    )

#### Example usage:

    table = tf.HashTable(
        tf.KeyValueTensorInitializer(keys, values), -1)
    out = table.lookup(input_tensor)
    table.init.run()
    print(out.eval())

<br />

<br />

<br />

| ## Args ||
|---|---|
| `initializer` | The table initializer to use. See `HashTable` kernel for supported key and value types. |
| `default_value` | The value to use if a key is missing in the table. |
| `shared_name` | If non-empty, this table will be shared under the given name across multiple sessions. |
| `name` | A name for the operation (optional). |

<br />

<br />

<br />

<br />

| ## Attributes ||
|---|---|
| `default_value` | The default value of the table. |
| `init` | <br /> <br /> |
| `initializer` | <br /> <br /> |
| `key_dtype` | The table key dtype. |
| `name` | The name of the table. |
| `resource_handle` | Returns the resource handle associated with this Resource. |
| `value_dtype` | The table value dtype. |

<br />

## Methods

### `export`

[View source](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/contrib/lookup/lookup_ops.py#L355-L372)

    export(
        name=None
    )

Returns tensors of all keys and values in the table.

<br />

<br />

<br />

| Args ||
|---|---|
| `name` | A name for the operation (optional). |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| A pair of tensors with the first tensor containing all keys and the second tensors containing all values in the table. ||

<br />

### `lookup`

[View source](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/ops/lookup_ops.py#L201-L236)

    lookup(
        keys, name=None
    )

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

The `default_value` is used for keys not present in the table.

<br />

<br />

<br />

| Args ||
|---|---|
| `keys` | Keys to look up. May be either a `SparseTensor` or dense `Tensor`. |
| `name` | A name for the operation (optional). |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| A `SparseTensor` if keys are sparse, otherwise a dense `Tensor`. ||

<br />

<br />

<br />

<br />

| Raises ||
|---|---|
| `TypeError` | when `keys` or `default_value` doesn't match the table data types. |

<br />

### `size`

[View source](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/ops/lookup_ops.py#L189-L199)

    size(
        name=None
    )

Compute the number of elements in this table.

<br />

<br />

<br />

| Args ||
|---|---|
| `name` | A name for the operation (optional). |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| A scalar tensor containing the number of elements in this table. ||

<br />