tf.tpu.experimental.embedding.TableConfig
Stay organized with collections
Save and categorize content based on your preferences.
Configuration data for one embedding table.
tf.tpu.experimental.embedding.TableConfig(
vocabulary_size: int,
dim: int,
initializer: Optional[Callable[[Any], None]] = None,
optimizer: Optional[_Optimizer] = None,
combiner: Text = 'mean',
name: Optional[Text] = None,
quantization_config: tf.tpu.experimental.embedding.QuantizationConfig
= None,
layout: Optional[Any] = None
)
Used in the notebooks
Used in the guide |
Used in the tutorials |
|
|
This class holds the configuration data for a single embedding table. It is
used as the table
parameter of a
tf.tpu.experimental.embedding.FeatureConfig
. Multiple
tf.tpu.experimental.embedding.FeatureConfig
objects can use the same
tf.tpu.experimental.embedding.TableConfig
object. In this case a shared
table will be created for those feature lookups.
table_config_one = tf.tpu.experimental.embedding.TableConfig(
vocabulary_size=...,
dim=...)
table_config_two = tf.tpu.experimental.embedding.TableConfig(
vocabulary_size=...,
dim=...)
feature_config = {
'feature_one': tf.tpu.experimental.embedding.FeatureConfig(
table=table_config_one),
'feature_two': tf.tpu.experimental.embedding.FeatureConfig(
table=table_config_one),
'feature_three': tf.tpu.experimental.embedding.FeatureConfig(
table=table_config_two)}
embedding = tf.tpu.experimental.embedding.TPUEmbedding(
feature_config=feature_config,
batch_size=...
optimizer=tf.tpu.experimental.embedding.Adam(0.1))
The above configuration has 2 tables, and three features. The first two
features will be looked up in the first table and the third feature will be
looked up in the second table.
Args |
vocabulary_size
|
Size of the table's vocabulary (number of rows).
|
dim
|
The embedding dimension (width) of the table.
|
initializer
|
A callable initializer taking one parameter, the shape of the
variable that will be initialized. Will be called once per task, to
initialize that task's shard of the embedding table. If not specified,
defaults to truncated_normal_initializer with mean 0.0 and standard
deviation 1/sqrt(dim) .
|
optimizer
|
An optional instance of an optimizer parameters class, instance
of one of tf.tpu.experimental.embedding.SGD ,
tf.tpu.experimental.embedding.Adagrad or
tf.tpu.experimental.embedding.Adam . If set will override the global
optimizer passed to tf.tpu.experimental.embedding.TPUEmbedding .
|
combiner
|
A string specifying how to reduce if there are multiple entries
in a single row. Currently 'mean', 'sqrtn', 'sum' are supported, with
'mean' the default. 'sqrtn' often achieves good accuracy, in particular
with bag-of-words columns. For more information, see
tf.nn.embedding_lookup_sparse .
|
name
|
An optional string used to name the table. Must be defined if
running on SparseCore.
|
quantization_config
|
The simulated quantization config. An instance of
tf.tpu.experimental.embedding.QuantizationConfig . See the class for
more documentation.
|
layout
|
If the table already has its layout computed, you can pass it in
here. Otherwise, we will compute it for you. Most users should leave
this as None.
|
Raises |
ValueError
|
if vocabulary_size is not a positive integer.
|
ValueError
|
if dim is not a positive integer.
|
ValueError
|
if initializer is specified and is not callable.
|
ValueError
|
if combiner is not supported.
|
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.
[[["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 2024-04-26 UTC."],[],[],null,["# tf.tpu.experimental.embedding.TableConfig\n\n\u003cbr /\u003e\n\n|-------------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/tpu/tpu_embedding_v2_utils.py#L987-L1170) |\n\nConfiguration data for one embedding table.\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.tpu.experimental.embedding.TableConfig`](https://www.tensorflow.org/api_docs/python/tf/tpu/experimental/embedding/TableConfig)\n\n\u003cbr /\u003e\n\n tf.tpu.experimental.embedding.TableConfig(\n vocabulary_size: int,\n dim: int,\n initializer: Optional[Callable[[Any], None]] = None,\n optimizer: Optional[_Optimizer] = None,\n combiner: Text = 'mean',\n name: Optional[Text] = None,\n quantization_config: ../../../../tf/tpu/experimental/embedding/QuantizationConfig = None,\n layout: Optional[Any] = None\n )\n\n### Used in the notebooks\n\n| Used in the guide | Used in the tutorials |\n|----------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------|\n| - [Migrate from TPU embedding_columns to TPUEmbedding layer](https://www.tensorflow.org/guide/migrate/tpu_embedding) | - [TensorFlow 2 TPUEmbeddingLayer: Quick Start](https://www.tensorflow.org/recommenders/examples/tpu_embedding_layer) |\n\nThis class holds the configuration data for a single embedding table. It is\nused as the `table` parameter of a\n[`tf.tpu.experimental.embedding.FeatureConfig`](../../../../tf/tpu/experimental/embedding/FeatureConfig). Multiple\n[`tf.tpu.experimental.embedding.FeatureConfig`](../../../../tf/tpu/experimental/embedding/FeatureConfig) objects can use the same\n[`tf.tpu.experimental.embedding.TableConfig`](../../../../tf/tpu/experimental/embedding/TableConfig) object. In this case a shared\ntable will be created for those feature lookups. \n\n table_config_one = tf.tpu.experimental.embedding.TableConfig(\n vocabulary_size=...,\n dim=...)\n table_config_two = tf.tpu.experimental.embedding.TableConfig(\n vocabulary_size=...,\n dim=...)\n feature_config = {\n 'feature_one': tf.tpu.experimental.embedding.FeatureConfig(\n table=table_config_one),\n 'feature_two': tf.tpu.experimental.embedding.FeatureConfig(\n table=table_config_one),\n 'feature_three': tf.tpu.experimental.embedding.FeatureConfig(\n table=table_config_two)}\n embedding = tf.tpu.experimental.embedding.TPUEmbedding(\n feature_config=feature_config,\n batch_size=...\n optimizer=tf.tpu.experimental.embedding.Adam(0.1))\n\nThe above configuration has 2 tables, and three features. The first two\nfeatures will be looked up in the first table and the third feature will be\nlooked up in the second table.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-----------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `vocabulary_size` | Size of the table's vocabulary (number of rows). |\n| `dim` | The embedding dimension (width) of the table. |\n| `initializer` | A callable initializer taking one parameter, the shape of the variable that will be initialized. Will be called once per task, to initialize that task's shard of the embedding table. If not specified, defaults to `truncated_normal_initializer` with mean `0.0` and standard deviation `1/sqrt(dim)`. |\n| `optimizer` | An optional instance of an optimizer parameters class, instance of one of [`tf.tpu.experimental.embedding.SGD`](../../../../tf/tpu/experimental/embedding/SGD), [`tf.tpu.experimental.embedding.Adagrad`](../../../../tf/tpu/experimental/embedding/Adagrad) or [`tf.tpu.experimental.embedding.Adam`](../../../../tf/tpu/experimental/embedding/Adam). If set will override the global optimizer passed to [`tf.tpu.experimental.embedding.TPUEmbedding`](../../../../tf/tpu/experimental/embedding/TPUEmbedding). |\n| `combiner` | A string specifying how to reduce if there are multiple entries in a single row. Currently 'mean', 'sqrtn', 'sum' are supported, with 'mean' the default. 'sqrtn' often achieves good accuracy, in particular with bag-of-words columns. For more information, see [`tf.nn.embedding_lookup_sparse`](../../../../tf/nn/embedding_lookup_sparse). |\n| `name` | An optional string used to name the table. Must be defined if running on SparseCore. |\n| `quantization_config` | The simulated quantization config. An instance of [`tf.tpu.experimental.embedding.QuantizationConfig`](../../../../tf/tpu/experimental/embedding/QuantizationConfig). See the class for more documentation. |\n| `layout` | If the table already has its layout computed, you can pass it in here. Otherwise, we will compute it for you. Most users should leave this as None. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|----------------------------------------------------|\n| `ValueError` | if `vocabulary_size` is not a positive integer. |\n| `ValueError` | if `dim` is not a positive integer. |\n| `ValueError` | if `initializer` is specified and is not callable. |\n| `ValueError` | if `combiner` is not supported. |\n\n\u003cbr /\u003e"]]