3.9 KiB
Bergamot Translator
Bergamot translator provides a unified API for (Marian NMT framework based) neural machine translation functionality in accordance with the Bergamot project that focuses on improving client-side machine translation in a web browser.
Build Instructions
Build Natively
-
Clone the repository using these instructions:
git clone https://github.com/mozilla/bergamot-translator cd bergamot-translator
-
Compile
Create a folder where you want to build all the artifacts (
build-native
in this case) and compile in that foldermkdir build-native cd build-native cmake ../ make -j
Build WASM
Compiling for the first time
-
Download and Install Emscripten using following instructions
- Get the latest sdk:
git clone https://github.com/emscripten-core/emsdk.git
- Enter the cloned directory:
cd emsdk
- Install the lastest sdk tools:
./emsdk install latest
- Activate the latest sdk tools:
./emsdk activate latest
- Activate path variables:
source ./emsdk_env.sh
- Get the latest sdk:
-
Clone the repository using these instructions:
git clone https://github.com/mozilla/bergamot-translator cd bergamot-translator
-
Download files (only required if you want to perform inference using build artifacts)
It packages the vocabulary files into wasm binary, which is required only if you want to perform inference. The compilation commands will preload these files in Emscripten’s virtual file system.
If you want to package bergamot project specific files, please follow these instructions:
git clone --depth 1 --branch main --single-branch https://github.com/mozilla-applied-ml/bergamot-models mkdir models cp -rf bergamot-models/prod/* models gunzip models/*/* find models \( -type f -name "model*" -or -type f -name "lex*" \) -delete
-
Compile
-
Create a folder where you want to build all the artefacts (
build-wasm
in this case)mkdir build-wasm cd build-wasm
-
Compile the artefacts
-
If you want to package files into wasm binary then execute following commands (Replace
FILES_TO_PACKAGE
with the directory containing all the files to be packaged)emcmake cmake -DCOMPILE_WASM=on -DPACKAGE_DIR=FILES_TO_PACKAGE ../ emmake make -j
e.g. If you want to package bergamot project specific files (downloaded using step 3 above) then replace
FILES_TO_PACKAGE
with../models
-
If you don't want to package any file into wasm binary then execute following commands:
emcmake cmake -DCOMPILE_WASM=on ../ emmake make -j
The wasm artifacts (.js and .wasm files) will be available in the build directory ("build-wasm" in this case).
-
-
Enable SIMD Wormhole via Wasm instantiation API in generated artifacts
bash ../wasm/patch-artifacts-enable-wormhole.sh
-
Recompiling
As long as you don't update any submodule, just follow steps in 4.ii
and 4.iii
to recompile.
If you update a submodule, execute following command before executing steps in 4.ii
and 4.iii
to recompile.
git submodule update --init --recursive
How to use
Using Native version
The builds generate library that can be integrated to any project. All the public header files are specified in src
folder.
A short example of how to use the APIs is provided in app/main.cpp
file.
Using WASM version
Please follow the README
inside the wasm
folder of this repository that demonstrates how to use the translator in JavaScript.