Older releases
#### 0.8.2
* **General**
* NestedMap Flatten/Pack/Transform/Filter etc now expand descendent dicts
as well.
* Subclasses of BaseLayer extending from `abc.ABCMeta` should now extend
`base_layer.ABCLayerMeta` instead.
* Trying to call self.CreateChild outside of `__init__` now raises an
error.
* `base_layer.initializer` has been removed. Subclasses no longer need to
decorate their `__init__` function.
* Trying to call self.CreateVariable outside of `__init__` or
`_CreateLayerVariables` now raises an error.
* It is no longer possible to access self.vars or self.theta inside of
`__init__`. Refactor by moving the variable creation and access to
`_CreateLayerVariables`. The variable scope is set automatically
according to the layer name in `_CreateLayerVariables`.
Details for older releases are unavailable.
## Quick start
### Installation
There are two ways to set up Lingvo: installing a fixed version through pip, or
cloning the repository and building it with bazel. Docker configurations are
provided for each case.
If you would just like to use the framework as-is, it is easiest to just install
it through pip. This makes it possible to develop and train custom models using
a frozen version of the Lingvo framework. However, it is difficult to modify the
framework code or implement new custom ops.
If you would like to develop the framework further and potentially contribute
pull requests, you should avoid using pip and clone the repository instead.
**pip:**
The [Lingvo pip package](https://pypi.org/project/lingvo) can be installed with
`pip3 install lingvo`.
See the
[codelab](https://colab.research.google.com/github/tensorflow/lingvo/blob/master/codelabs/introduction.ipynb)
for how to get started with the pip package.
**From sources:**
The prerequisites are:
* a TensorFlow 2.7 [installation](https://www.tensorflow.org/install/),
* a `C++` compiler (only g++ 7.3 is officially supported), and
* the bazel build system.
Refer to [docker/dev.Dockerfile](docker/dev.Dockerfile) for a set of working
requirements.
`git clone` the repository, then use bazel to build and run targets directly.
The `python -m module` commands in the codelab need to be mapped onto `bazel
run` commands.
**docker:**
Docker configurations are available for both situations. Instructions can be
found in the comments on the top of each file.
* [lib.dockerfile](docker/lib.dockerfile) has the Lingvo pip package
preinstalled.
* [dev.Dockerfile](docker/dev.Dockerfile) can be used to build Lingvo from
sources.
[How to install docker.](https://docs.docker.com/install/linux/docker-ce/ubuntu/)
### Running the MNIST image model
#### Preparing the input data
**pip:**
```shell
mkdir -p /tmp/mnist
python3 -m lingvo.tools.keras2ckpt --dataset=mnist
```
**bazel:**
```shell
mkdir -p /tmp/mnist
bazel run -c opt //lingvo/tools:keras2ckpt -- --dataset=mnist
```
The following files will be created in `/tmp/mnist`:
* `mnist.data-00000-of-00001`: 53MB.
* `mnist.index`: 241 bytes.
#### Running the model
**pip:**
```shell
cd /tmp/mnist
curl -O https://raw.githubusercontent.com/tensorflow/lingvo/master/lingvo/tasks/image/params/mnist.py
python3 -m lingvo.trainer --run_locally=cpu --mode=sync --model=mnist.LeNet5 --logdir=/tmp/mnist/log
```
**bazel:**
```shell
(cpu) bazel build -c opt //lingvo:trainer
(gpu) bazel build -c opt --config=cuda //lingvo:trainer
bazel-bin/lingvo/trainer --run_locally=cpu --mode=sync --model=image.mnist.LeNet5 --logdir=/tmp/mnist/log --logtostderr
```
After about 20 seconds, the loss should drop below 0.3 and a checkpoint will be
saved, like below. Kill the trainer with Ctrl+C.
```
trainer.py:518] step: 205, steps/sec: 11.64 ... loss:0.25747201 ...
checkpointer.py:115] Save checkpoint
checkpointer.py:117] Save checkpoint done: /tmp/mnist/log/train/ckpt-00000205
```
Some artifacts will be produced in `/tmp/mnist/log/control`:
* `params.txt`: hyper-parameters.
* `model_analysis.txt`: model sizes for each layer.
* `train.pbtxt`: the training `tf.GraphDef`.
* `events.*`: a tensorboard events file.
As well as in `/tmp/mnist/log/train`:
* `checkpoint`: a text file containing information about the checkpoint files.
* `ckpt-*`: the checkpoint files.
Now, let's evaluate the model on the "Test" dataset. In the normal training
setup the trainer and evaler should be run at the same time as two separate
processes.
**pip:**
```shell
python3 -m lingvo.trainer --job=evaler_test --run_locally=cpu --mode=sync --model=mnist.LeNet5 --logdir=/tmp/mnist/log
```
**bazel:**
```shell
bazel-bin/lingvo/trainer --job=evaler_test --run_locally=cpu --mode=sync --model=image.mnist.LeNet5 --logdir=/tmp/mnist/log --logtostderr
```
Kill the job with Ctrl+C when it starts waiting for a new checkpoint.
```
base_runner.py:177] No new check point is found: /tmp/mnist/log/train/ckpt-00000205
```
The evaluation accuracy can be found slightly earlier in the logs.
```
base_runner.py:111] eval_test: step: 205, acc5: 0.99775392, accuracy: 0.94150388, ..., loss: 0.20770954, ...
```
### Running the machine translation model
To run a more elaborate model, you'll need a cluster with GPUs. Please refer to
[`third_party/py/lingvo/tasks/mt/README.md`](https://github.com/tensorflow/lingvo/blob/master/lingvo/tasks/mt/README.md)
for more information.
### Running the GShard transformer based giant language model
To train a GShard language model with one trillion parameters on GCP using
CloudTPUs v3-512 using 512-way model parallelism, please refer to
[`third_party/py/lingvo/tasks/lm/README.md`](https://github.com/tensorflow/lingvo/blob/master/lingvo/tasks/lm/README.md)
for more information.
### Running the 3d object detection model
To run the StarNet model using CloudTPUs on GCP, please refer to
[`third_party/py/lingvo/tasks/car/README.md`](https://github.com/tensorflow/lingvo/blob/master/lingvo/tasks/car/README.md).
## Models
### Automatic Speech Recognition
* [Listen, Attend and Spell](https://arxiv.org/pdf/1508.01211.pdf).