在tensorflow deep and wide教程中,embedding原理是什么

In tensorflow deep and wide tutorial, what's the embedding principle

当我玩tensorflow教程时,Wide and Deep教程中使用了一种嵌入技巧。

本教程展示了如何将稀疏特征(通常是一种热编码)转移到嵌入向量。 我知道有一些方法可以创建这种嵌入,例如词嵌入、PCA 或 t-SNE 或矩阵分解。 但是在本教程中,他们没有展示如何为稀疏向量创建嵌入。 还是教程只是使用神经网络完成嵌入?

如果您了解词嵌入,那么您应该很熟悉这种转换。来自 "The Deep Model: Neural Network with Embeddings" 部分:

The embedding values are initialized randomly, and are trained along with all other model parameters to minimize the training loss.

本质上,tf.feature_column.embedding_column(occupation, dimension=8) 所做的是创建一个 [N, 8] 矩阵,其中 Noccupation 值的数量或桶的数量,如果您使用哈希分类列。每个输入 occupation 值就像 select 大小 [8] 的嵌入向量的索引。网络的其余部分将使用这个 [8] 向量,而不知道 N 是什么。该向量通常称为 dense 以强调长度 N 编码的 one-hot 和 [8] 向量之间的区别,其中大多数值为零,所有重要的值。

嵌入是可训练的,因此在随机初始化后,它们会漂移到某些值,这些值对网络的其余部分很有用。这与 word2vec 或其他词嵌入非常相似,并且通常是非常有效的表示:

Through dense embeddings, deep models can generalize better and make predictions on feature pairs that were previously unseen in the training data.

如果你想使用预训练嵌入。只有你曾经接受过 word2vec 或其他培训。您可以尝试在 tf.feature_column.embedding_column

中设置初始值设定项
itemx_vocab = tf.feature_column.categorical_column_with_vocabulary_file(
key='itemx',
vocabulary_file=FLAGS.vocabx)

embedding_initializer_x = tf.contrib.framework.load_embedding_initializer(
ckpt_path='model.ckpt',
embedding_tensor_name='w_in',
new_vocab_size=itemx_vocab.vocabulary_size,
embedding_dim=emb_size,
old_vocab_file='FLAGS.vocab_emb',
new_vocab_file=FLAGS.vocabx
)
itemx_emb = tf.feature_column.embedding_column(itemx_vocab,
                                           dimension=128,
                                           initializer=embedding_initializer_x,
                                           trainable=False)