赞
踩
关于google的word2vec项目,这里就不用介绍了,接下来需要很干货的分享给大伙,在CentOS下安装word2vec的linux教程。关于如何在各个linux操作系统上安装word2vec,google的word2vec项目首页并未过多讲,或是详细的描述安装的linux教程。
word2vec项目的官网上,只有这么几段简短的关于使用的描述和linux教程:
Quick start
Download the code: svn checkout http://word2vec.googlecode.com/svn/trunk/
Run ‘make’ to compile word2vec tool
Run the demo scripts: ./demo-word.sh and ./demo-phrases.sh
For questions about the toolkit, see http://groups.google.com/group/word2vec-toolkit
详细的安装word2vec项目的linux如下:
当然,如上所说,该操作是在CentOS系统下的。
1、确保gcc为最新版
2、安装subversion,用来获取word2vec源码
3、指定一个任意目录为word2vec工作目录,通过svn指令获取word2vec源码
svn checkout http:
//word2vec
.googlecode.com
/svn/trunk/
|
4、使用make指令进行安装
可以发现在安装的时候,会出现如下error:
gcc word2vec.c -o word2vec -lm -pthread -0fast -march=native -Wall -funroll-loops -Wno-unused-result
cc1: error: invalid option argument ?0fast?
cc1: warning: unrecognized command line option “-Wno-unused-result”
make: *** [word2vec] Error 1
这是因为该系统的gcc不支持0fast选项的原因。
5、编辑makefile文件,更改gcc安装选项
vi ./makefile
word2vec的makefile源码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
CC = gcc
#The -Ofast might not work with older versions of gcc; in that
case
,
use
-O2
CFLAGS = -lm -pthread -Ofast -march=native -Wall -funroll-loops -Wno-unused-result
all: word2vec word2phrase distance word-analogy compute-accuracy
word2vec : word2vec.c
$(CC) word2vec.c -o word2vec $(CFLAGS)
word2phrase : word2phrase.c
$(CC) word2phrase.c -o word2phrase $(CFLAGS)
distance : distance.c
$(CC) distance.c -o distance $(CFLAGS)
word-analogy : word-analogy.c
$(CC) word-analogy.c -o word-analogy $(CFLAGS)
compute-accuracy : compute-accuracy.c
$(CC) compute-accuracy.c -o compute-accuracy $(CFLAGS)
chmod
+x *.sh
clean:
rm -rf word2vec word2phrase distance word-analogy compute-accuracy
|
注意观察,第二行:
#The -0fast might not work with older versions of gcc; in that case, use -02(是0)
google的工程师这里有写到相关注意事项,告诉开发者,-0fast安装选项,可能对于旧版本的gcc不支持,如果在这种情况下,需要将-0fast改为-02
所以将第三行
CFLAGS = -lm -pthread -0fast -march=native -Wall -funroll-loops -Wno-unused-result
更改为
CFLAGS = -lm -pthread -02-march=native -Wall -funroll-loops -Wno-unused-result
6、使用make指令安装通过
安装通过后的内容为:
gcc word2vec.c -o word2vec -lm -pthread -02 -march=native -Wall -funroll-loops -Wno-unused-result
gcc word2phrase.c -o word2phrase -lm -pthread -02 -march=native -Wall -funroll-loops -Wno-unused-result
gcc distance.c -o distance -lm -pthread -O2 -march=native -Wall -funroll-loops -Wno-unused-result
gcc word-analogy.c -o word-analogy -lm -pthread -02 -march=native -Wall -funroll-loops -Wno-unused-result
gcc compute-accuracy.c -o compute-accuracy -lm -pthread -02 -march=native -Wall -funroll-loops -Wno-unused-result
chmod +x *.sh
关于CentOS下安装word2vec的linux教程介绍到此,应该没有问题,亲自尝试后,通过。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。