Pythonはどのように訓練した語ベクトルを読みますか?

570 ワード

word 2 vecで訓練した語ベクトルを読み取る
    def load_word2vec_object(self, source_data_path):
        source_data = open(source_data_path, 'rb')
        source_data_dict = {}
        for i, line in enumerate(source_data):
            if i == 0 and 'word2vec' in line:
                continue
            line = line.split(' ')
            word = line[0].decode('utf-8')
            word_vec_list = [float(x) for x in line[1:]]
            source_data_dict[word] = np.array(word_vec_list)  #     
        return source_data_dict