NLP初级选手ubuntu 下安装google SyntaxNet
2016-05-23 00:28
429 查看
NLP初级选手ubuntu 下安装google SyntaxNet
初级选手安装走了很多弯路,但是也收获不少经验,特别是熟悉了环境搭建过程中涉及到的框架工具。可能目前对这些框架工具理解和使用都欠缺,但是并不影响成功搭建SyntaxNet的工作环境。本人所有安装步骤参考github上给出的SyntaxNet的教程介绍1。1.python 安装
特别提醒:只能用python2.7
目前syntaxnet并不能被python3+支持
$ sudo apt-get install python2.7
2.bazel 安装
installing bazel: http://bazel.io/docs/install.html
首先,安装jdk 1.8 (不赘述)
下载Bazel bazel-0.2.2b-installer-linux-x86_64.sh (注意版本号)
$ chmod +x bazel-version-installer-os.sh $ ./bazel-version-installer-os.sh --user
设置环境变量 ~/.bashrc
export PATH="$PATH:$HOME/bin"
测试是否安装成功:
Bazel的运行需要项目中有个空文档WORKSPACE,所以建立项目目录~/gitroot/my-project/, 接着创建项目WORKSPACE文档~/gitroot/my-project/WORKSPACE。
第一步创建build文件
# If you're not already there, move to your workspace directory. $ cd ~/gitroot/my-project $ mkdir -p src/main/java/com/example $ cat > src/main/java/com/example/ProjectRunner.java <<EOF package com.example; public class ProjectRunner { public static void main(String args[]) { Greeting.sayHi(); } } EOF $ cat > src/main/java/com/example/Greeting.java <<EOF package com.example; public class Greeting { public static void sayHi() { System.out.println("Hi!"); } } EOF
第二步 在项目目录~/gitroot/my-project下创建BUILD文件:
# ~/gitroot/my-project/BUILD java_binary( name = "my-runner", srcs = glob(["**/*.java"]), main_class = "com.example.ProjectRunner", )
第三步 编译生成
$ cd ~/gitroot/my-project $ bazel build //:my-runner INFO: Found 1 target... Target //:my-runner up-to-date: bazel-bin/my-runne 4000 r.jar bazel-bin/my-runner INFO: Elapsed time: 1.021s, Critical Path: 0.83s $ bazel-bin/my-runner Hi!
在程序块中,‘#’的内容不可忽视,同样需要写入程序头;
更多bazel实例可参考官网Getting Started with Bazel
3.swig 安装
$ apt-get install swig
4.tensorflow安装
本人在安装tensorflow时受挫比较大。在此希望读者需谨慎。
先给出tensorflow的官网安装教程(可能需要翻墙) tensorflow download and setup
本人基本按此教程进行,即使这样,还是遇到了不少问题。在此给出我的成功安装的步骤。
第一步 安装pip
#可选一下两种,建议选择1 #1. pip for python $ sudo apt-get install python-pip python-dev #2. pip3 for python3 $ sudo apt-get install python3-pip python3-dev
第二步 安装tensorflow
由于在PC机上安装,所以没有选择GPU的方式安装(请参考官网),选择的是CPU安装。
#1. pip: Ubuntu/Linux 64-bit, CPU only: $ sudo pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.8.0-cp27-none-linux_x86_64.whl #2. pip3: Ubuntu/Linux 64-bit, CPU only: $ sudo pip3 install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.8.0-cp34-cp34m-linux_x86_64.whl[/code]
第三步 安装 victualenv
该工具必须安装,否则syntaxtnet最后编译无法全通过# 1. pip $ sudo apt-get install python-virtualenv # 2. pip3 $ sudo apt-get install python3-virtualenv
在virtualenv中创建tensorfloe环境$ virtualenv --system-site-packages ~/tensorflow
激活tensorflow的virtualenv环境$ source ~/tensorflow/bin/activate # 1. pip (tensorflow)$ pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.8.0-cp27-none-linux_x86_64.whl # 2. pip3 (tensorflow)$ pip3 install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.8.0-cp34-cp34m-linux_x86_64.whl[/code]
测试tensorflow安装# python2.7/python3.4 $ python2.7 ... >>> import tensorflow as tf >>> hello = tf.constant('Hello, TensorFlow!') >>> sess = tf.Session() >>> print(sess.run(hello)) Hello, TensorFlow! >>> a = tf.constant(10) >>> b = tf.constant(32) >>> print(sess.run(a + b)) 42 >>>
5.pip安装 protobuf/ asciitree / numpy# pip for python2.7/pip3 for python3.4 $ pip freeze | grep protobuf $ pip install -U protobuf==3.0.0b2 $ pip install asciitree $ pip install numpy
6.syntaxnet 配置
注意此部分必须在virtualenv中完成(tensorflow)$ git clone --recursive https://github.com/tensorflow/models.git (tensorflow)$ cd models/syntaxnet/tensorflow (tensorflow)$ ./configure (tensorflow)$ cd .. (tensorflow)$ bazel test syntaxnet/... util/utf8/...
必须完全passed 12 tests
测试syntaxnet实例(tensorflow)$ echo 'Bob brought the pizza to Alice.' | syntaxnet/demo.sh
https://github.com/tensorflow/models/tree/master/syntaxnet. ↩
相关文章推荐
- 新版Chrome浏览器去掉了一个常用功能:点退格键回到之前网页
- django的admin 管理
- sublime text 3 搭建go语言开发
- go slice与函数
- Django[基础知识]
- HDU 3966 Aragorn's Story (树链点权剖分,成段修改单点查询)
- go语言的变量声明
- HDU 1847 Good Luck in CET-4 Everybody! (博弈)
- 开源项目GoodView点赞效果
- 2015山东省第六届ACM-BIGZHUGOD and His Friends II(赛瓦定理+二分法求三次方程)
- Django的初识
- Uva11054——Wine trading in Gergovia
- K-means Algorithm 聚类算法
- Go语言实现将[]string转化为[]byte
- Go打印函数printf格式简介
- django第二个项目--使用模板
- 自适应波束形成算法 之 算法篇【二】(Adaptive Beamforming Algorithm)
- google找后台用法
- Google I/O 2016 Keynote个人总结
- PKU1003 Hangover(水题)