View source on GitHub |
A generic mutable hash table implementation.
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.
table = tfra.dynamic_embedding.RedisTable(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())
__init__(
key_dtype,
value_dtype,
default_value,
name='RedisTable',
checkpoint=(False),
config=None
)
Creates an empty RedisTable
object.
Creates a redis table through OS envionment variables, the type of its keys and values are specified by key_dtype and value_dtype, respectively.
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, usually it's embedding table name).checkpoint
: if True, the contents of the table are saved to and restored from a Redis binary dump files according to the directory "[model_lib_abs_dir]/[model_tag]/[name].rdb". Ifshared_name
is empty for a checkpointed table, it is shared using the table node name.
A RedisTable
object.
ValueError
: If checkpoint is True and no name was specified.
The table key dtype.
The name of the table.
Returns the resource handle associated with this Resource.
The table value dtype.
__getitem__(keys)
Looks up keys
in a table, outputs the corresponding values.
accum(
keys,
values_or_deltas,
exists,
name=None
)
Associates keys
with values
.
keys
: Keys to accmulate. Can be a tensor of any shape. Must match the table's key type.values_or_deltas
: values to be associated with keys. Must be a tensor of the same shape askeys
and match the table's value type.exists
: A bool type tensor indicates if keys already exist or not. Must be a tensor of the same shape askeys
.name
: A name for the operation (optional).
The created Operation.
TypeError
: whenkeys
orvalues
doesn't match the table data types.
clear(name=None)
clear all keys and values in the table.
name
: A name for the operation (optional).
The created Operation.
export(name=None)
Returns nothing in Redis Implement. It will dump some binary files to model_lib_abs_dir.
name
: A name for the operation (optional).
A pair of tensors with the first tensor containing all keys and the second tensors containing all values in the table.
insert(
keys,
values,
name=None
)
Associates keys
with values
.
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 askeys
and match the table's value type.name
: A name for the operation (optional).
The created Operation.
TypeError
: whenkeys
orvalues
doesn't match the table data types.
lookup(
keys,
dynamic_default_values=None,
return_exists=(False),
name=None
)
Looks up keys
in a table, outputs the corresponding values.
The default_value
is used for keys not present in the table.
keys
: Keys to look up. Can be a tensor of any shape. Must match the table's key_dtype.dynamic_default_values
: The values to use if a key is missing in the table. If None (by default), the static default_valueself._default_value
will be used.return_exists
: if True, will return a additional Tensor which indicates if or not keys are existing in the table.name
: A name for the operation (optional).
A tensor containing the values in the same shape as keys
using the
table's value type.
exists
: A bool type Tensor of the same shape askeys
which indicates if keys are existing in the table. Only provided ifreturn_exists
is True.
TypeError
: whenkeys
do not match the table data types.
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.
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).
The created Operation.
TypeError
: whenkeys
do not match the table data types.
size(name=None)
Compute the number of elements in this table.
name
: A name for the operation (optional).
A scalar tensor containing the number of elements in this table.