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

2024-07-04 05:57:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我想建立一个以句子作为输入来预测情绪的网络。所以我的输入看起来像(numofsamples x num of questions x num of words)。然后我想把它放到一个嵌入层来学习单词向量,然后求和得到句子向量。这种类型的建筑在keras可能吗?还是Tensorflow?从文档中,Keras的嵌入层只接受输入(nb_样本,序列长度)。有什么办法吗?在


Tags: of文档网络类型tensorflow单词向量num
1条回答
网友
1楼 · 发布于 2024-07-04 05:57:29

我想这个类解决了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,)

相关问题 更多 >

    热门问题