我是靠谱客的博主 激情大象,这篇文章主要介绍为什么建立embedding_matrix时要再一开始多加一行?,现在分享给大家,希望可以做个参考。

why : nb_words = len(tokenizer.word_index) + 1 ?????

answer: 

 

1. word index start from 1, so the index of 0 would be 0 all the time

embedding_matrix = np.zeros((nb_words, embedding_dim))

for word, i in word_index.items():
        try:
            embedding_vector = word_vectors[word]
            if embedding_vector is not None:
                embedding_matrix[i] = embedding_vector
        except KeyError:
            print("vector not found for word - %s" % word)

 

2. while mapping the word to vector, the padding of 0 would be mapping to np.array(0,embedding_dim)

    train_sequences_1 = tokenizer.texts_to_sequences(sentence1) # texts_to_sequences -------- map the index of words to words
    train_padded_data_1 = pad_sequences(train_sequences_1,maxlen = max_sequence_length) # padding to the max length of sequence
 

3. the sentence encoding would be complete

最后

以上就是激情大象最近收集整理的关于为什么建立embedding_matrix时要再一开始多加一行?的全部内容,更多相关为什么建立embedding_matrix时要再一开始多加一行内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(67)

评论列表共有 0 条评论

立即
投稿
返回
顶部