embeddings = np.zeros([len(vocab), dim])
    model = Word2Vec.load_word2vec_format(glove_filename, binary=True)
    count = 0
    for word in vocab:
        if model.__contains__(word):
            word_idx = vocab[word]
            embeddings[word_idx] = np.asarray(model[word])
        else:
            count += 1
            print(word)
    print ("number of unknown word in word embedding", count)
    np.savez_compressed(trimmed_filename, embeddings=embeddings)

更多推荐