Number of buckets to use for out-of-vocabulary keys.
hasher_spec
A HasherSpec to specify the hash function to use for
assignation of out-of-vocabulary buckets (optional).
name
A name for the operation (optional).
key_dtype
Data type of keys passed to lookup. Defaults to
table.key_dtype if table is specified, otherwise tf.string. Must
be string or integer, and must be castable to table.key_dtype.
Raises
ValueError
when table in None and num_oov_buckets is not positive.
TypeError
when hasher_spec is invalid.
Attributes
init
DEPRECATED FUNCTION
initializer
key_dtype
The table key dtype.
name
The name of the table.
resource_handle
Returns the resource handle associated with this Resource.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2020-10-01 UTC."],[],[],null,["# tf.contrib.lookup.IdTableWithHashBuckets\n\n\u003cbr /\u003e\n\n|-------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/ops/lookup_ops.py#L829-L1033) |\n\nString to Id table wrapper that assigns out-of-vocabulary keys to buckets.\n\nInherits From: [`LookupInterface`](../../../tf/contrib/lookup/LookupInterface) \n\n tf.contrib.lookup.IdTableWithHashBuckets(\n table, num_oov_buckets, hasher_spec=tf.contrib.lookup.FastHashSpec, name=None,\n key_dtype=None\n )\n\nFor example, if an instance of `IdTableWithHashBuckets` is initialized with a\nstring-to-id table that maps:\n\n- `emerson -\u003e 0`\n- `lake -\u003e 1`\n- `palmer -\u003e 2`\n\nThe `IdTableWithHashBuckets` object will performs the following mapping:\n\n- `emerson -\u003e 0`\n- `lake -\u003e 1`\n- `palmer -\u003e 2`\n- `\u003cother term\u003e -\u003e bucket_id`, where bucket_id will be between `3` and `3 + num_oov_buckets - 1`, calculated by: `hash(\u003cterm\u003e) % num_oov_buckets + vocab_size`\n\nIf input_tensor is `[\"emerson\", \"lake\", \"palmer\", \"king\", \"crimson\"]`,\nthe lookup result is `[0, 1, 2, 4, 7]`.\n\nIf `table` is None, only out-of-vocabulary buckets are used.\n\n#### Example usage:\n\n num_oov_buckets = 3\n input_tensor = tf.constant([\"emerson\", \"lake\", \"palmer\", \"king\", \"crimnson\"])\n table = tf.IdTableWithHashBuckets(\n tf.StaticHashTable(tf.TextFileIdTableInitializer(filename),\n default_value),\n num_oov_buckets)\n out = table.lookup(input_tensor).\n table.init.run()\n print(out.eval())\n\nThe hash function used for generating out-of-vocabulary buckets ID is handled\nby `hasher_spec`.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `table` | Table that maps [`tf.string`](../../../tf#string) or [`tf.int64`](../../../tf#int64) keys to [`tf.int64`](../../../tf#int64) ids. |\n| `num_oov_buckets` | Number of buckets to use for out-of-vocabulary keys. |\n| `hasher_spec` | A `HasherSpec` to specify the hash function to use for assignation of out-of-vocabulary buckets (optional). |\n| `name` | A name for the operation (optional). |\n| `key_dtype` | Data type of keys passed to `lookup`. Defaults to `table.key_dtype` if `table` is specified, otherwise [`tf.string`](../../../tf#string). Must be string or integer, and must be castable to `table.key_dtype`. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|-------------------------------------------------------------|\n| `ValueError` | when `table` in None and `num_oov_buckets` is not positive. |\n| `TypeError` | when `hasher_spec` is invalid. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Attributes ---------- ||\n|-------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `init` | DEPRECATED FUNCTION \u003cbr /\u003e | **Warning:** THIS FUNCTION IS DEPRECATED. It will be removed after 2018-12-15. Instructions for updating: Use `initializer` instead. |\n| `initializer` | \u003cbr /\u003e |\n| `key_dtype` | The table key dtype. |\n| `name` | The name of the table. |\n| `resource_handle` | Returns the resource handle associated with this Resource. |\n| `value_dtype` | The table value dtype. |\n\n\u003cbr /\u003e\n\nMethods\n-------\n\n### `lookup`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/ops/lookup_ops.py#L989-L1033) \n\n lookup(\n keys, name=None\n )\n\nLooks up `keys` in the table, outputs the corresponding values.\n\nIt assigns out-of-vocabulary keys to buckets based in their hashes.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|--------|--------------------------------------------------------------------|\n| `keys` | Keys to look up. May be either a `SparseTensor` or dense `Tensor`. |\n| `name` | Optional name for the op. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| A `SparseTensor` if keys are sparse, otherwise a dense `Tensor`. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ||\n|-------------|----------------------------------------------------|\n| `TypeError` | when `keys` doesn't match the table key data type. |\n\n\u003cbr /\u003e\n\n### `size`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/ops/lookup_ops.py#L967-L974) \n\n size(\n name=None\n )\n\nCompute the number of elements in this table."]]