Assign custom word vector to UNK token during prediction?

匆匆过客 提交于 2020-01-16 18:00:10

问题


I use a tensorflow embedding layer for a classification model like with

with tf.variable_scope('embeddings'):
        word_embeddings = tf.constant(self.embedding_mat, dtype=tf.float32, name="embedding")
        self.embedded_x1 = tf.nn.embedding_lookup(word_embeddings, self.x1)
        self.embedded_x2 = tf.nn.embedding_lookup(word_embeddings, self.x2)

If I have a UNK token in my embedding matrix but I did not used this UNK in training, can I assign a custom vector (eg. from fasttext) during prediction? So, for this UNK word which might be similar to a trained word such that the text is classified as same class? I wonder if this is possible to cange a vector during prediction on the fly the value of the UNK vector?

How could I possibly do that?

来源:https://stackoverflow.com/questions/56045468/assign-custom-word-vector-to-unk-token-during-prediction

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!