【问题标题】:Keras : addition layer for embeddings / vectors?Keras:嵌入/向量的附加层?
【发布时间】:2017-11-16 09:32:42
【问题描述】:

我有 3 个词嵌入:

  • 嵌入#1:[w11,w12,w13,w14]
  • 嵌入#2:[w21,w22,w23,w24]
  • 嵌入#3:[w31,w32,w33,w34]

有没有办法通过添加所有三个向量来获得第四个嵌入,以及所有这些向量的可训练权重,例如:

  • 嵌入#4:[w11 + w21 + w31,w12 + w22 + w32,w13 + w23 + w33,w14 + w24 + w34]

?有没有办法在 keras 层中做到这一点?

问题
我想学习印尼语的词嵌入。我计划通过使用 LSTM 训练序列预测机来做到这一点。

但是,印尼语的语法与英语不同。特别是在印尼语中,您可以使用前缀和后缀来修饰单词。给定前缀的名词词可以成为动词,给定后缀可以成为形容词。你可以把这么多的词放在一个词中,这样一个基本词就可以有 5 个或更多的变体。

例如:

  1. tani 表示农场(动词)
  2. pe-tani 是农民的意思
  3. per-tani-an 表示农场(名词)
  4. ber-tani 意为农场(动词,含义略有不同)

通过给单词附加前缀来完成的语义转换在单词之间是一致的。例如:

  1. pe-tani 之于 tani 即 pe-layan 之于 layan,pe-layar 之于layar,pe-tembak 之于 tembak,等等。
  2. per-main-an 之于 main 是 per-guru-an 之于 guru,per-kira-an 之于 kira,per-surat-an 之于 surat 等等。

因此,我计划将前缀和后缀表示为嵌入,这将用于对基本词的嵌入进行添加,从而产生新的嵌入。所以复合词的含义来源于基础词和词缀的嵌入,而不是作为单独的嵌入存储。但是我不知道如何在 Keras 层中执行此操作。如果之前有人问过,我找不到它。

【问题讨论】:

    标签: python nlp keras layer embedding


    【解决方案1】:

    当你说“三个词嵌入”时,我看到三个 Embedding 层,例如:

    input1 = Input((sentenceLength,))
    input2 = Input((sentenceLength,))
    input3 = Input((sentenceLength,))
    
    emb1 = Embedding(...options...)(input1)
    emb2 = Embedding(...options...)(input2)
    emb3 = Embedding(...options...)(input3)
    

    您可以使用一个简单的Add() 层来对三者求和:

    summed = Add()([emb1,emb2,emb3])
    

    然后你继续你的建模......

    #after creating the rest of the layers and getting the desired output:
    model = Model([input1,input2,input3],output)
    

    如果你没有使用嵌入层,但你输入了三个向量:

    input1 = Input((4,)) #or perhaps (sentenceLength,4)
    input2 = Input((4,))
    input3 = Input((4,))
    
    added = Add()([input1,input2,input3])
    

    其余的都是一样的。


    如果这不是您的问题,请详细说明这三个“词嵌入”的来源、您打算如何选择它们等。

    【讨论】:

    • 我想这就是我要找的。谢谢。
    猜你喜欢
    • 1970-01-01
    • 2018-12-16
    • 2018-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-24
    • 1970-01-01
    相关资源
    最近更新 更多