使用word2vec(C语言版本)训练中文语料 并且将得到的vector.bin文件转换成txt文件
来源:互联网 发布:单片机蜂鸣器报警电路 编辑:程序博客网 时间:2024/06/05 07:27
1、下载word2vec源码:http://download.csdn.net/download/qq_15987811/8681485
2、得到分词好的中文训练语料。
3、修改demo-word.sh文件:
- make
- #if [ ! -e text8 ]; then
- # wget http://mattmahoney.net/dc/text8.zip -O text8.gz
- # gzip -d text8.gz -f
- #fi
- time ./word2vec -train Result_Country.txt -output vectors.bin -cbow 1 -size 200 -window 8 -negative 25 -hs 0 -sample 1e-4 -threads 20 -binary 1 -iter 15
- ./distance vectors.bin
4、执行make命令
5、执行: sh demo-word.sh命令 得到vectors.bin文件,即为训练好的词向量文件
6、将bin文件转换成txt的格式,方便直接打开。
bin转txt的代码转自 http://www.cnblogs.com/zhangtianyuan/p/6922825.html
# -*- coding: utf-8 -*- import gensim import codecs def main(): path_to_model = 'F:/my_learning_ml/LSTM/20170805learn_initial_py/vectors.bin' output_file = 'file.txt' bin2txt(path_to_model, output_file) def bin2txt(path_to_model, output_file): output = codecs.open(output_file, 'w' , 'utf-8') model = gensim.models.KeyedVectors.load_word2vec_format(path_to_model, binary=True) print('Done loading Word2Vec!') vocab = model.vocab for item in vocab: vector = list() for dimension in model[item]: vector.append(str(dimension)) vector_str = ",".join(vector) line = item + "\t" + vector_str output.writelines(line + "\n") #本来用的是write()方法,但是结果出来换行效果不对。改成writelines()方法后还没试过。 print ('Done Write') output.close() if __name__ == "__main__": main()
阅读全文
0 0
- 使用word2vec(C语言版本)训练中文语料 并且将得到的vector.bin文件转换成txt文件
- 使用word2vec训练wiki中文语料
- 中文语料上的word2vec训练
- word2vec中的bin文件转换为txt 文件
- windows10 训练word2vec 中文语料
- word2vec 自己训练中文语料
- gensim 中文语料训练 word2vec
- 将txt文件转换成excel文件的方法
- Windows系统下使用维基百科中文语料训练Word2Vec词向量
- Word2vec的bin文件的java处理
- 将vector<vector<string>>写入TXT文件
- 使用开源包pdfbox将pdf文件批量转换成txt文件
- Word2Vec中文语料实战
- Word2Vec中文语料实战
- bin文件转换为hex文件C语言实现
- hex文件转换为bin文件C语言实现
- 经常需要将TXT文件转换成pdf的方法
- 将pdf文件转换成txt格式的操作方法
- Kaggle 入门介绍 https://dnc1994.com/2016/04/rank-10-percent-in-first-kaggle-competition/
- Netty(一):基础概念及消息处理流程
- Java Swing 调节图片亮度
- scala学习-scala中的元组Tuple概念
- #bzoj3393#二叉树(Splay / RMQ)
- 使用word2vec(C语言版本)训练中文语料 并且将得到的vector.bin文件转换成txt文件
- mybatis 初识2
- 入门 Webpack,看这篇就够了
- 魔法阵
- 关于事务
- 1.Java后端开发 基础入门须知!
- loadrunner 11.0 破解授权问题
- 统计字符数(POJ NO.1744)
- Android和Python之间的不能说的小秘密