How to use the lattice rescorer tool.
=====================================
**Tested version infos:**
tensorflow-gpu pip package 1.8.0
tensorflow source code 1.7.0
bazel 0.11.0
protoc 3.2.0
cuda 9.0
cuDNN 7.0
g++ 5.4.0
# Install TensorFlow with pip.
[install tensorflow with pip](https://www.tensorflow.org/install/pip)
$ pip3 install --user --upgrade tensorflow-gpu
Verify the install:
$ python3 -c "import tensorflow as tf; print(tf.__version__)"
# Compile TensorFlow c++/c library from source
You can refer to [install tensorflow from source](https://www.tensorflow.org/install/source),the steps are similar.
Also, the scirpt in Kaldi [install_tensorflow_cc.sh](https://github.com/kaldi-asr/kaldi/blob/master/tools/extras/install_tensorflow_cc.sh) shows the steps to compile c++/c libraries.
## Prepare environment for Linux
Before compiling Tensorflow c++ library on Linux, install the following build tools on your system:
*bazel
*cuda, cuDNN
### Install Bazel
You should install a required version of bazel, [version information](https://www.tensorflow.org/install/source#tested_build_configurations).
[Install bazel using binary installer](https://docs.bazel.build/versions/master/install-ubuntu.html#install-with-installer-ubuntu)
#### Download Bazel
Download the Bazel binary installer named bazel-<version>-installer-linux-x86_64.sh from the [Bazel releases page on GitHub](https://github.com/bazelbuild/bazel/releases).
#### Run the installer
Run the Bazel installer as follows:
$ chmod +x bazel-<version>-installer-linux-x86_64.sh
$ ./bazel-<version>-installer-linux-x86_64.sh --user
#### Set up your environment
In your .bashrc, add the following line:
export PATH="$PATH:$HOME/bin"
### Install TensorFlow for GPU prerequisites
#### Install CUDA and cuDNN
You should install a required version of CUDA and cuDNN, [version information](https://www.tensorflow.org/install/source#tested_build_configurations):
[Install CUDA](https://developer.nvidia.com/cuda-toolkit-archive)
[Install cuDNN](https://developer.nvidia.com/rdp/cudnn-archive)
Then execute the following commands:
$ tar -xzvf cudnn-9.0-linux-x64-v7.tgz
$ mv cuda cudnn-9.0-v7.0
#### Set up your environment
Add the following command to .bashrc:
export LD_LIBRARY_PATH=/path-to-your-cudnn/lib64:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/path-to-your-cuda/extras/CUPTI/lib64
## Clone the Tensorflow repository and configure the installation
You should download a proper version of TensorFlow source code, [version information](https://www.tensorflow.org/install/source#tested_build_configurations)
Use Git to clone the TensorFlow repository
$ git clone https://github.com/tensorflow/tensorflow
$ cd tensorflow
The repo defaults to the master development branch. You can also checkout a release branch to build:
$ git checkout branch_name # r1.9, r1.10, etc.
$ ./configure
This script prompts you for the location of TensorFlow dependencies and asks for additional build configuration options (compiler flags, for example).
[A sample configuration session](https://www.tensorflow.org/install/source#configure_the_build)
## Compile Tensorflow c++ libraries
$ export TEST_TMPDIR=/u/username/bazel_outputRoot
$ tensorflow/contrib/makefile/download_dependencies.sh
$ bazel build -c opt --config=cuda --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" --local_resources=6144,4,1.0 --jobs=4 //tensorflow:libtensorflow_cc.so
$ bazel build -c opt --config=cuda --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" --local_resources=6144,4,1.0 --jobs=4 //tensorflow:libtensorflow.so
The compiled libraries are stored in /u/username/tensorflow/bazel-bin/tensorflow
## Set up your environment
Add the following command to .bashrc:
export LD_LIBRARY_PATH=/u/username/tensorflow/bazel-bin/tensorflow:$LD_LIBRARY_PATH
# Compile LSTM Op in returnn
For example:
$ ./path-to-your-returnn/tools/compile_native_op.py --native_op NativeLstm2 --output path-to-libraries.txt
The LSTM cell we used is nativelstm2, path-to-libraries.txt contains the paths to the compiled libraries. The libraries are stored by default in /var/tmp/, please move the libraries to somewhere else.
Alternatively, you can use the option --config to compile all native ops, see the script compile_native_op.py for more detailes.
# Modifications in the original network config file
1. In the config file, for each LSTM layers, please add
"initial_state" : "keep_over_epoch"
and change LSTM unit "lstm" to "nativelstm2". We tested that the LSTM unit "lstm" does not work for inference.
2. You have this in your config:
num_outputs = {"data": {"dim": num_inputs, "sparse": True, "dtype": "int32"}} # sparse data
num_outputs["delayed"] = num_outputs["data"]
Change that to:
extern_data = {
"delayed": {"dim": num_inputs, "sparse": True, "dtype": "int32", "available_in_inference": True},
"data": {"dim": num_inputs, "sparse": True, "dtype": "int32", "available_in_inference": False}}
3. Add the following line to your config file:
default_input = "delayed"
# Create the Tensorflow graph for inference
$ ./path-to-your-returnn/tools/compile_tf_graph.py graph_for_inference.config --eval 1 --output_file filename+[".meta", ".metatxt"]
.meta graph: the graph for inference.
.metatxt: contains all the node names of the graph.
**Note**: we will include the .meta graph for inference in the checkpoint.
Suppose network.040.meta is the original .meta file, network.040.inference.meta is the one we create for inference, replace the original one with the new one by:
$ mv network.040.inference.meta network.040.meta
# Example to use lattice rescorer
## Makefile
Before using the Makefile, please verify the paths to your Tensorflow source code, cuda and cuDNN in Makefile
## Gernerate executable file from source files
In the folder returnn/tools/lattice_rescorer, execute the following command
$ make
If you got the following error while compiling using Makefile:
libopenblasp-r0-39a31c03.2.18.so: cannot open shared object file: No such file or directory
Please do:
find -name libopenblasp-r0-39a31c03.2.18.so
and add the following line in .bashrc:
export LD_LIBRARY_PATH=/folder-of-the-missing-library:$LD_LIBRARY_PATH
## Usage of lattice rescorer tool
lattice_rescorer [OPTION]... [LATTICE]
For command line options information:
$ lattice_rescorer --help
--ops-Returnn arg
Text file containing the paths to libraries of the native ops defined in returnn, for more details, please check the part **"Compile LSTM op in returnn"**.
--checkpoint-files arg
checkpoint of tensorflow model, but we should replace the original .meta graph with the .meta graph for inference created using returnn, please check the part **"Create the TensorFlow graph for inference"**.
--state-vars-list arg
Text file containing the information needed to assign a value to the state variables in LSTM cell. Please check **example/README.md**.
--tensor-names-list arg
Text file of tensor names for feeding and fetching. Please chech **example/README.md**.
For the usages of the other options, please check [rwthlm](https://www-i6.informatik.rwth-aachen.de/web/Software/rwthlm.php)
Please read an example script example/rescore_lattice.sh.
## An example script to rescore a lattice
The script rescore_lattice.sh is an example to rescore a lattice.
Before using the script, please modify manually the files libs_list, state_vars_list, tensor_names_list. For the details of these three text files, please read **example/README.md**. And then
$ cd example
$ ./rescore_lattice.sh
没有合适的资源?快使用搜索试试~ 我知道了~
PyPI 官网下载 | returnn-1.20201203.111538.tar.gz
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 17 浏览量
2022-01-15
21:25:44
上传
评论
收藏 1.7MB GZ 举报
温馨提示
共350个文件
py:225个
config:43个
cpp:11个
资源来自pypi官网。 资源全名:returnn-1.20201203.111538.tar.gz
资源推荐
资源详情
资源评论
收起资源包目录
PyPI 官网下载 | returnn-1.20201203.111538.tar.gz (350个子文件)
htklatticerescorer.cc 25KB
main.cc 12KB
vocabulary.cc 5KB
12AX.cluster_map 35KB
CODEOWNERS 526B
bpe-unicode-demo.codes 794B
demo-tf-hard-att-copy.config 11KB
i600_m600_m600.sgd_b16_lr0_cl2.newbobabs.keep_over_epoch.lstm2.config 6KB
i600_m600_m600.sgd_b16_lr0_cl2.newbobabs.config 6KB
demo-timit-lstm-ctc.config 5KB
demo-tf-att-copy.config 3KB
demo-tf-enc-dec.config 3KB
demo-torch-layer.config 3KB
demo-tf-attention.config 2KB
demo-rhn-enwik8.config 2KB
demo-tf-rec-self-att.config 2KB
demo-tf-rec-explicit-lstm.config 2KB
demo-tf-neural-transducer.12ax.config 2KB
demo-tf-native-lstm2.12ax.config 2KB
demo-hyper-param-tuning.config 2KB
demo-theano-vanilla-native-op-lstm.12ax.config 2KB
demo-tf-maxgradnorm-lstm.12ax.config 1KB
demo-tf-chunking-blstm.12ax.config 1KB
demo-theano-cluster-subnetwork.12ax.config 1KB
demo-tf-vanilla-lstm.12ax.config 1KB
demo-tf-contribrnn-lstm.12ax.config 1KB
demo-tf-native-lstm-lowmem.12ax.config 1KB
demo-tf-native-lstm.12ax.config 1KB
demo-theano-vanilla-lstmp.12ax.config 1KB
demo-theano-vanilla-native-lstm.12ax.config 1KB
demo-theano-vanilla-lstm.12ax.config 1KB
demo-tf-rec-explicit-rnn.config 1KB
demo-fwd.config 1KB
demo-theano-polyn-lstm.12ax.config 1KB
demo-tf-native-lstm2.12ax.tuned.config 1KB
demo-theano-rbf-lstm.12ax.config 1KB
demo-theano-vanilla-subnetwork.12ax.config 954B
demo-theano-vanilla-generic-lstm.12ax.config 847B
demo-theano-lin-rec.12ax.config 793B
demo-theano-assoc-lstm.episodiccopy.config 781B
demo-upd-mult-model.lstm.12ax.config 766B
demo-theano-act-lstm.12ax.config 748B
demo-theano-vanilla-lstmp.big.12ax.config 736B
demo-theano-assoc-lstm.varassign.config 729B
demo-theano-assoc-lstm.xml.config 715B
demo-theano-vanilla-lstm-peep.12ax.config 691B
demo-theano-vanilla-native-lstm.big.12ax.config 678B
demo-pretrain.config 487B
demo-theano-task12ax.config 431B
config_demo 2KB
config_fwd 2KB
config_real 2KB
c_support_code_mdlstm.cpp 49KB
native_op.cpp 35KB
inv.cpp 25KB
c_support_code_mdlstm.cpp 23KB
c_support_code.cpp 11KB
two_state_hmm.cpp 5KB
ctc.cpp 5KB
c_support_code_common.cpp 4KB
two_state_best_path_decoder.cpp 2KB
best_path_decoder.cpp 2KB
c_support_code_cudnn.cpp 1KB
spelling.dic 617B
.editorconfig 255B
forwardconfig 1KB
forwardconfig 1KB
lexicon_opt.fst 386B
.gitignore 482B
.gitignore 47B
.gitignore 38B
.gitmodules 834B
htklatticerescorer.h 11KB
vocabulary.h 3KB
rescorer.h 2KB
file.h 2KB
demo.h5 243KB
returnn.iml 417B
MANIFEST.in 550B
lexicon_opt.isyms 520B
lexicon_opt.jpg 33KB
.kateconfig 79B
libs_list 100B
LICENSE 10KB
Makefile 2KB
README.md 8KB
CONTRIBUTING.md 5KB
CHANGELOG.md 4KB
README.md 1KB
README.md 257B
.name 8B
lexicon_opt.osyms 41B
PKG-INFO 4KB
a01-007-06.png 44KB
a01-007-04.png 43KB
a01-000u-00.png 42KB
rec.py 368KB
basic.py 359KB
test_TFNetworkRecLayer.py 292KB
basic.py 241KB
共 350 条
- 1
- 2
- 3
- 4
资源评论
挣扎的蓝藻
- 粉丝: 13w+
- 资源: 15万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功