tf.lookup.KeyValueTensorInitializer  |  TensorFlow v2.16.1 (original) (raw)

tf.lookup.KeyValueTensorInitializer

Stay organized with collections Save and categorize content based on your preferences.

Table initializers given keys and values tensors.

View aliases

Compat aliases for migration

SeeMigration guide for more details.

tf.compat.v1.lookup.KeyValueTensorInitializer

tf.lookup.KeyValueTensorInitializer(
    keys, values, key_dtype=None, value_dtype=None, name=None
)

Used in the notebooks

Used in the guide Used in the tutorials
BERT Preprocessing with TF Text Subword tokenizers Load text Client-efficient large-model federated learning via `federated_select` and sparse aggregation Federated Learning for Text Generation Apache ORC Reader Feature Engineering using TFX Pipeline and TensorFlow Transform

keys_tensor = tf.constant(['a', 'b', 'c']) vals_tensor = tf.constant([7, 8, 9]) input_tensor = tf.constant(['a', 'f']) init = tf.lookup.KeyValueTensorInitializer(keys_tensor, vals_tensor) table = tf.lookup.StaticHashTable( init, default_value=-1) table.lookup(input_tensor).numpy() array([ 7, -1], dtype=int32)

Args
keys The tensor for the keys.
values The tensor for the values.
key_dtype The keys data type. Used when keys is a python array.
value_dtype The values data type. Used when values is a python array.
name A name for the operation (optional).
Attributes
key_dtype The expected table key dtype.
value_dtype The expected table value dtype.

Methods

initialize

View source

initialize(
    table
)

Initializes the given table with keys and values tensors.

Args
table The table to initialize.
Returns
The operation that initializes the table.
Raises
TypeError when the keys and values data types do not match the table key and value data types.

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. Some content is licensed under the numpy license.

Last updated 2024-04-26 UTC.