資源 | Github項目推薦 | Google發布序列到序列建模模組化可擴展框架Lingvo
- 2019 年 10 月 31 日
- 筆記
查看使用Lingvo的出版物列表,請點擊:
https://github.com/tensorflow/lingvo/blob/master/PUBLICATIONS.md
論文地址:
https://arxiv.org/abs/1902.08295
View:
https://www.arxiv-vanity.com/papers/1902.08295/
快速入門
Docker
最簡單的入門方法是使用我們提供的Docker腳本。 如果你想直接在機器上安裝它,請查看下一節。
首先,安裝docker。 然後,以下命令已經提供安裝了Lingvo的工作shell。
LINGVO_DIR="/tmp/lingvo" # (change to the cloned lingvo directory, e.g. "$HOME/lingvo") LINGVO_DEVICE="gpu" # (Leave empty to build and run CPU only docker) sudo docker build --tag tensorflow:lingvo $(test "$LINGVO_DEVICE" = "gpu" && echo "--build-arg base_image=nvidia/cuda:10.0-cudnn7-runtime-ubuntu16.04") - < ${LINGVO_DIR}/docker/dev.dockerfile sudo docker run --rm $(test "$LINGVO_DEVICE" = "gpu" && echo "--runtime=nvidia") -it -v ${LINGVO_DIR}:/tmp/lingvo -v ${HOME}/.gitconfig:/home/${USER}/.gitconfig:ro -p 6006:6006 -p 8888:8888 --name lingvo tensorflow:lingvo bash bazel test -c opt //lingvo:trainer_test //lingvo:models_test
直接安裝
直接安裝就是上述Docker方法的替代選擇。
安裝的前提條件:
- TensorFlow安裝(目前需要用到 tf-nightly ),
- 一個 C++ 編譯器(官方只支援g++ 4.8),以及
- bazel構建系統。
建議到 docker/dev.dockerfile 查看更多詳情:
https://github.com/tensorflow/lingvo/blob/master/docker/dev.dockerfile
運行MNIST影像模型
準備輸入的數據
mkdir -p /tmp/mnist bazel run -c opt //lingvo/tools:keras2ckpt -- --dataset=mnist --out=/tmp/mnist/mnist
你將會在 /tmp/mnist 文件夾獲得以下文件:
- mnist.data-00000-of-00001: 53MB.
- mnist.index: 241 bytes.
運行模型
要在單機模式下運行訓練器,請使用:
bazel build -c opt //lingvo:trainer bazel-bin/lingvo/trainer --run_locally=cpu --mode=sync --model=image.mnist.LeNet5 --logdir=/tmp/mnist/log --logtostderr
幾秒鐘後,第100步訓練精度應達到 85% ,結果如下所示:
INFO:tensorflow:step: 100 accuracy:0.85546875 log_pplx:0.46025506 loss:0.46025506 num_preds:256 num_samples_in_batch:256
工件將在 /tmp/mnist/log/control 中生成:
- params.txt:超參數
- model_analysis.txt:每層的模型大小。
- train.pbtxt:訓練 tf.GraphDef
- events.*:tensorboard的事件文件。
在 /tmp/mnist/log/train 目錄中,你將會獲得:
- ckpt-* :檢查點文件
- checkpoint :包含有關檢查點文件的資訊的文本文件。
運行機器翻譯模型
要運行更精細的模型,你需要一個具有GPU的集群。 有關更多資訊,請參閱:
lingvo/tasks/mt/README.md 。
現有模型
自動語音識別
- asr.librispeech.Librispeech960Grapheme [1,2]
- asr.librispeech.Librispeech960Wpm [1,2]
影像
- image.mnist.LeNet5 [3]
語言建模
- lm.one_billion_wds.WordLevelOneBwdsSimpleSampledSoftmax [4]
機器翻譯
- mt.wmt14_en_de.WmtEnDeTransformerBase [5]
- mt.wmt14_en_de.WmtEnDeRNMT [5]
- mt.wmtm16_en_de.WmtCaptionEnDeTransformer [5]
—————-
[1]: Listen, Attend and Spell. William Chan, Navdeep Jaitly, Quoc V. Le, and Oriol Vinyals. ICASSP 2016.
[2]: End-to-end Continuous Speech Recognition using Attention-based Recurrent NN: First Results. Jan Chorowski, Dzmitry Bahdanau, Kyunghyun Cho, and Yoshua Bengio. arXiv 2014.
[3]: Gradient-based learning applied to document recognition. Yann LeCun, Leon Bottou, Yoshua Bengio, and Patrick Haffner. IEEE 1998.
[4]: Exploring the Limits of Language Modeling. Rafal Jozefowicz, Oriol Vinyals, Mike Schuster, Noam Shazeer, and Yonghui Wu. arXiv, 2016.
[5]: The Best of Both Worlds: Combining Recent Advances in Neural Machine Translation. Mia X. Chen, Orhan Firat, Ankur Bapna, Melvin Johnson, Wolfgang Macherey, George Foster, Llion Jones, Mike Schuster, Noam Shazeer, Niki Parmar, Ashish Vaswani, Jakob Uszkoreit, Lukasz Kaiser, Zhifeng Chen, Yonghui Wu, and Macduff Hughes. ACL 2018.
參考
- API 文檔:
https://tensorflow.github.io/lingvo/
請在引用Lingvo時引用這篇論文:
https://arxiv.org/abs/1902.08295
@misc{shen2019lingvo, title={Lingvo: a Modular and Scalable Framework for Sequence-to-Sequence Modeling}, author={Jonathan Shen and Patrick Nguyen and Yonghui Wu and Zhifeng Chen and others}, year={2019}, eprint={1902.08295}, archivePrefix={arXiv}, primaryClass={cs.LG} }