2016-07-25 71 views
1

我想建立一個以句子爲輸入來預測情緒的網絡。所以我的輸入看起來像(樣本的數量x的句子數量x的單詞數量)。然後,我想在嵌入層中提供這些信息來學習單詞向量,然後可以將它們相加得到句子向量。這種類型的建築可能在凱拉斯嗎?或Tensorflow?從文檔Keras的嵌入層只接受輸入(nb_samples,sequence_length)。有沒有可能的工作?3D張量輸入到keras或tensorflow嵌入層?

回答

0

我想這個類解決了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,)