tf.contrib.lookup.MutableHashTable
Stay organized with collections
Save and categorize content based on your preferences.
A generic mutable hash table implementation.
Inherits From: LookupInterface
tf.contrib.lookup.MutableHashTable(
key_dtype, value_dtype, default_value, name='MutableHashTable', checkpoint=True
)
Data can be inserted by calling the insert method and removed by calling the
remove method. It does not support initialization via the init method.
Example usage:
table = tf.lookup.MutableHashTable(key_dtype=tf.string, value_dtype=tf.int64,
default_value=-1)
sess.run(table.insert(keys, values))
out = table.lookup(query_keys)
print(out.eval())
Args |
key_dtype
|
the type of the key tensors.
|
value_dtype
|
the type of the value tensors.
|
default_value
|
The value to use if a key is missing in the table.
|
name
|
A name for the operation (optional).
|
checkpoint
|
if True, the contents of the table are saved to and restored
from checkpoints. If shared_name is empty for a checkpointed table, it
is shared using the table node name.
|
Raises |
ValueError
|
If checkpoint is True and no name was specified.
|
Attributes |
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.
|
Methods
export
View source
export(
name=None
)
Returns tensors of all keys and values in the table.
Args |
name
|
A name for the operation (optional).
|
Returns |
A pair of tensors with the first tensor containing all keys and the
second tensors containing all values in the table.
|
insert
View source
insert(
keys, values, name=None
)
Associates keys
with values
.
Args |
keys
|
Keys to insert. Can be a tensor of any shape. Must match the table's
key type.
|
values
|
Values to be associated with keys. Must be a tensor of the same
shape as keys and match the table's value type.
|
name
|
A name for the operation (optional).
|
Returns |
The created Operation.
|
Raises |
TypeError
|
when keys or values doesn't match the table data
types.
|
lookup
View source
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.
Args |
keys
|
Keys to look up. Can be a tensor of any shape. Must match the
table's key_dtype.
|
name
|
A name for the operation (optional).
|
Returns |
A tensor containing the values in the same shape as keys using the
table's value type.
|
Raises |
TypeError
|
when keys do not match the table data types.
|
remove
View source
remove(
keys, name=None
)
Removes keys
and its associated values from the table.
If a key is not present in the table, it is silently ignored.
Args |
keys
|
Keys to remove. Can be a tensor of any shape. Must match the table's
key type.
|
name
|
A name for the operation (optional).
|
Returns |
The created Operation.
|
Raises |
TypeError
|
when keys do not match the table data types.
|
size
View source
size(
name=None
)
Compute the number of elements in this table.
Args |
name
|
A name for the operation (optional).
|
Returns |
A scalar tensor containing the number of elements in this table.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2020-10-01 UTC.
[[["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.MutableHashTable\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#L1594-L1827) |\n\nA generic mutable hash table implementation.\n\nInherits From: [`LookupInterface`](../../../tf/contrib/lookup/LookupInterface) \n\n tf.contrib.lookup.MutableHashTable(\n key_dtype, value_dtype, default_value, name='MutableHashTable', checkpoint=True\n )\n\nData can be inserted by calling the insert method and removed by calling the\nremove method. It does not support initialization via the init method.\n\n#### Example usage:\n\n table = tf.lookup.MutableHashTable(key_dtype=tf.string, value_dtype=tf.int64,\n default_value=-1)\n sess.run(table.insert(keys, values))\n out = table.lookup(query_keys)\n print(out.eval())\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-----------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `key_dtype` | the type of the key tensors. |\n| `value_dtype` | the type of the value tensors. |\n| `default_value` | The value to use if a key is missing in the table. |\n| `name` | A name for the operation (optional). |\n| `checkpoint` | if True, the contents of the table are saved to and restored from checkpoints. If `shared_name` is empty for a checkpointed table, it is shared using the table node name. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|--------------------------------------------------|\n| `ValueError` | If checkpoint is True and no name was specified. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Attributes ---------- ||\n|-------------------|------------------------------------------------------------|\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### `export`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/ops/lookup_ops.py#L1783-L1798) \n\n export(\n name=None\n )\n\nReturns tensors of all keys and values in the table.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|--------|--------------------------------------|\n| `name` | A name for the operation (optional). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| A pair of tensors with the first tensor containing all keys and the second tensors containing all values in the table. ||\n\n\u003cbr /\u003e\n\n### `insert`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/ops/lookup_ops.py#L1756-L1781) \n\n insert(\n keys, values, name=None\n )\n\nAssociates `keys` with `values`.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|----------|-------------------------------------------------------------------------------------------------------------------|\n| `keys` | Keys to insert. Can be a tensor of any shape. Must match the table's key type. |\n| `values` | Values to be associated with keys. Must be a tensor of the same shape as `keys` and match the table's value type. |\n| `name` | A name for the operation (optional). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| The created Operation. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ||\n|-------------|-------------------------------------------------------------|\n| `TypeError` | when `keys` or `values` doesn't match the table data types. |\n\n\u003cbr /\u003e\n\n### `lookup`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/ops/lookup_ops.py#L1731-L1754) \n\n lookup(\n keys, name=None\n )\n\nLooks up `keys` in a table, outputs the corresponding values.\n\nThe `default_value` is used for keys not present in the table.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|--------|----------------------------------------------------------------------------------|\n| `keys` | Keys to look up. Can be a tensor of any shape. Must match the table's key_dtype. |\n| `name` | A name for the operation (optional). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| A tensor containing the values in the same shape as `keys` using the table's value type. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ||\n|-------------|------------------------------------------------|\n| `TypeError` | when `keys` do not match the table data types. |\n\n\u003cbr /\u003e\n\n### `remove`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/ops/lookup_ops.py#L1705-L1729) \n\n remove(\n keys, name=None\n )\n\nRemoves `keys` and its associated values from the table.\n\nIf a key is not present in the table, it is silently ignored.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|--------|--------------------------------------------------------------------------------|\n| `keys` | Keys to remove. Can be a tensor of any shape. Must match the table's key type. |\n| `name` | A name for the operation (optional). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| The created Operation. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ||\n|-------------|------------------------------------------------|\n| `TypeError` | when `keys` do not match the table data types. |\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#L1692-L1703) \n\n size(\n name=None\n )\n\nCompute the number of elements in this table.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|--------|--------------------------------------|\n| `name` | A name for the operation (optional). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| A scalar tensor containing the number of elements in this table. ||\n\n\u003cbr /\u003e"]]