NLP初级选手ubuntu 下安装google SyntaxNet
来源:互联网 发布:java 幂等性实现原理 编辑:程序博客网 时间:2024/06/06 12:35
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 <<EOFpackage com.example;public class ProjectRunner { public static void main(String args[]) { Greeting.sayHi(); }}EOF$ cat > src/main/java/com/example/Greeting.java <<EOFpackage com.example;public class Greeting { public static void sayHi() { System.out.println("Hi!"); }}EOF
第二步 在项目目录~/gitroot/my-project下创建BUILD文件:
# ~/gitroot/my-project/BUILDjava_binary( name = "my-runner", srcs = glob(["**/*.java"]), main_class = "com.example.ProjectRunner",)
第三步 编译生成
$ cd ~/gitroot/my-project$ bazel build //:my-runnerINFO: Found 1 target...Target //:my-runner up-to-date: bazel-bin/my-runner.jar bazel-bin/my-runnerINFO: Elapsed time: 1.021s, Critical Path: 0.83s$ bazel-bin/my-runnerHi!
在程序块中,‘#’的内容不可忽视,同样需要写入程序头;
更多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
第三步 安装 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
测试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. ↩
- NLP初级选手ubuntu 下安装google SyntaxNet
- Ubuntu下安装Google拼音输入法
- Ubuntu 下安装Google拼音输入法
- ubuntu下安装google浏览器
- Ubuntu下安装google拼音输入法
- ubuntu下安装google拼音输入法
- Ubuntu下安装google-chrome
- Ubuntu下安装google拼音输入法
- Ubuntu下google拼音输入法安装
- Ubuntu 下安装 Google Chrome
- ubuntu下安装google拼音
- SyntaxNet安装与使用详解
- Ubuntu 10.04下安装Google拼音输入法
- ubuntu下安装google输入法(转载)
- Ubuntu 10.04下安装Google拼音输入法
- Ubuntu 10.04下安装Google拼音输入法
- Ubuntu 10.04下安装Google拼音输入法
- Ubuntu 12.04下安装Google拼音输入法
- 继承的弊端
- Jersey 2.22.2 官方文档第10章学习笔记
- Java中this运用
- 用python开发股票自动技术分析的软件
- leetcode_c++:First Missing Positive(041)
- NLP初级选手ubuntu 下安装google SyntaxNet
- Spring-data-redis: pub/sub消息订阅
- Yandex.Algorithm 2016 Qualification Round 题解(待补)
- java保存到数据库中文乱码,加useUnicode=true&characterEncoding=UTF-8
- CentOs 7.0实现定时任务(定时访问网页)
- bootstrap列表页制作之列表组使用
- vi 全选
- java中的序列化以及好处
- 字符串之KMP