Search code examples
machine-learningkerasnlpembeddingpart-of-speech

keras add features after embedding


I want to add part of speech features into my word vector after embedding in Keras. I would like to add them as one hot and concat them after embedding. But the part of speech of a word is dynamic so I can't use another embedding layer for part of speech one hot look up and combine two embedding layers.


Solution

  • Here is a simple approach, I'm assuming input as a word and its POS tag.

    word = Input(...)
    pos = Input(...)
    emb = Embedding( ... ) (word)
    layer = Concatenate()([emb, pos])
    outputs = .... # your processing
    model = Model(inputs=[word,pos], outputs=outputs)