python - 来自 tensorflow 的 tf.contrib.layers.embedding_column

标签 python tensorflow embedding

我正在阅读 tensorflow 教程 tensorflow .我想找到以下行的描述:

tf.contrib.layers.embedding_column

我想知道它是否使用 word2vec 或其他任何东西,或者我的想法可能完全错误。我试图在 GibHub 上四处点击,但一无所获。我猜想在 GitHub 上查找并不容易,因为 python 可能会引用一些 C++ 库。谁能指出我正确的方向?

最佳答案

我也一直在想这个问题。我不太清楚他们在做什么,但这是我发现的。

paper on wide and deep learning ,他们将嵌入向量描述为随机初始化,然后在训练期间进行调整以最小化误差。

通常,当您进行嵌入时,您会采用数据的一些任意向量表示(例如单热向量),然后将其乘以表示嵌入的矩阵。该矩阵可以通过 PCA 找到,也可以在通过 t-SNE 或 word2vec 等工具进行训练时找到。

embedding_column 的实际代码是 here ,它被实现为一个名为 _EmbeddingColumn 的类,它是 _FeatureColumn 的子类。它将嵌入矩阵存储在其 sparse_id_column 属性中。然后,方法 to_dnn_input_layer 应用这个嵌入矩阵来生成下一层的嵌入。

 def to_dnn_input_layer(self,
                         input_tensor,
                         weight_collections=None,
                         trainable=True):
    output, embedding_weights = _create_embedding_lookup(
        input_tensor=self.sparse_id_column.id_tensor(input_tensor),
        weight_tensor=self.sparse_id_column.weight_tensor(input_tensor),
        vocab_size=self.length,
        dimension=self.dimension,
        weight_collections=_add_variable_collection(weight_collections),
        initializer=self.initializer,
        combiner=self.combiner,
        trainable=trainable)

据我所知,嵌入似乎是通过将您正在使用的任何学习规则(梯度下降等)应用于嵌入矩阵而形成的。

关于python - 来自 tensorflow 的 tf.contrib.layers.embedding_column,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38808643/

相关文章:

python - Django 中的酒店预订系统 : How to make a room unavailable to other users for a period of time

Python-属性错误: 'str' object has no attribute 'append'

python - Tensorflow将tf.CsvDataset.map()转换为Bert输入格式

python - 使用 numpy 方法修改(keras/tensorflow)张量

jquery - 在 DIV 中加载的网站的宽度和高度属性

python - 在库 libxml2 中找不到函数 xmlCheckVersion。是否安装了 libxml2?错误 : command 'gcc' failed with exit status 1

python - 如何在给定的不规则日期对时间序列重新采样

tensorflow - tensorflow 数据集中图像的展平元组

flash - FLASH-从其他主机/域加载声音

matplotlib - 在 matplotlib 的子图中嵌入小图