Configuration data for one embedding table.
tf.tpu.experimental.embedding.TableConfig( vocabulary_size: int, dim: int, initializer: Optional[Callable[[Any], None]], optimizer: Optional[_Optimizer] = None, combiner: Text = 'mean', name: Optional[Text] = None )
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 . It 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. Useful for debugging. |
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. |
© 2020 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 3.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/versions/r2.4/api_docs/python/tf/tpu/experimental/embedding/TableConfig