来自张量流的tf.contrib.layers.embedding_column

时间:2016-08-06 20:58:11

标签: python tensorflow embedding

我正在通过tensorflow教程tensorflow。我想找到以下行的描述:

tf.contrib.layers.embedding_column

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

2 个答案:

答案 0 :(得分:6)

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

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)

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

答案 1 :(得分:2)

我对嵌入有类似的怀疑。

以下是要点:

  

添加嵌入层和传统宽线性模型的能力允许通过将稀疏维度降低到低维度来进行准确预测。

enter image description here

这是关于它的good post

这是一个simple example组合嵌入图层。使用Titanic Kaggle数据来预测乘客是否会根据某些属性(如姓名,性别,他们拥有的机票,他们支付给他们的客舱的票价等等)来生存。

相关问题