简体   繁体   English

将3D张量输入到keras或tensorflow中的嵌入层?

[英]3D tensor input to embedding layer in keras or tensorflow?

I want to build a network which takes in sentences as input to predict the sentiment. 我想建立一个以句子为输入来预测情绪的网络。 So my input looks something like (num of samples x num of sentences x num of words). 所以我的输入看起来像(样本数x句子数x单词数)。 I then want to feed this in an embedding layer to learn the word vectors which can be then summed to get sentence vector. 然后,我想将其提供给嵌入层,以学习单词向量,然后将其求和以获得句子向量。 Is this type of architecture possible in keras? 在喀拉拉邦,这种建筑可能吗? or Tensorflow? 还是Tensorflow? From the documentation Keras's embedding layer only takes in input (nb_samples, sequence_length). 从文档中,Keras的嵌入层仅接受输入(nb_samples,sequence_length)。 Is there any work around possible? 有没有可能的解决方法?

I guess this class resolves for Keras: 我猜这堂课可以解决Keras的问题:

class AnyShapeEmbedding(Embedding):
    '''
    This Embedding works with inputs of any number of dimensions.
    This can be accomplished by simply changing the output shape computation.
    '''
    #@overrides
    def compute_output_shape(self, input_shape):
        return input_shape + (self.output_dim,)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM