Imports python bindings and associated sources incubated in https://github.com/jerinphilip/lemonade to bergamot-translator. Adds a pybind11 dependency for python bindings. Following the import, the python build is integrated into the existing CMake based build system here. There is a command-line application provided through python which provides the ability to fetch and prepare models from model-repositories (like browsermt/students or OPUS). Wheels built for a few common operating systems are provided via GitHub releases through automated actions configured to run at tagged semantic versions and pushes to main. The documentation for python is also integrated into our existing documentation setup. Previous documentation GitHub action is now configured to run behind python builds in Ubuntu 18.04 Python3.7, in order to pick up the packaged as a wheel bergamot module and the sphinx documentation using the python module. Formatting checks of black, isort with profile black and a pytype type checker is configured for the python component residing in this repository. |
||
---|---|---|
.circleci | ||
.github/workflows | ||
3rd_party | ||
app | ||
bergamot-translator-tests@e49686b7ca | ||
bindings | ||
cmake | ||
doc | ||
examples | ||
patches | ||
src | ||
vcpkg-override/ports/pcre2 | ||
wasm | ||
.clang-format | ||
.clang-format-ignore | ||
.clang-tidy | ||
.gitignore | ||
.gitmodules | ||
BERGAMOT_VERSION | ||
build-wasm.sh | ||
CMakeLists.txt | ||
Doxyfile.in | ||
LICENSE | ||
MANIFEST.in | ||
README.md | ||
run-clang-format.py | ||
setup.py |
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
Create a folder where you want to build all the artifacts (build-native
in this case) and compile
mkdir build-native
cd build-native
cmake ../
make -j2
Build WASM
Prerequisite
Building on wasm requires Emscripten toolchain. It can be downloaded and installed 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 2.0.9
- Activate the latest sdk tools:
./emsdk activate 2.0.9
- Activate path variables:
source ./emsdk_env.sh
Compile
To build a version that translates with higher speeds on Firefox Nightly browser, follow these instructions:
-
Create a folder where you want to build all the artifacts (
build-wasm
in this case) and compilemkdir build-wasm cd build-wasm emcmake cmake -DCOMPILE_WASM=on ../ emmake make -j2
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
-
Patch generated artifacts to import GEMM library from a separate wasm module
bash ../wasm/patch-artifacts-import-gemm-module.sh
To build a version that runs on all browsers (including Firefox Nightly) but translates slowly, follow these instructions:
-
Create a folder where you want to build all the artifacts (
build-wasm
in this case) and compilemkdir build-wasm cd build-wasm emcmake cmake -DCOMPILE_WASM=on -DWORMHOLE=off ../ emmake make -j2
-
Patch generated artifacts to import GEMM library from a separate wasm module
bash ../wasm/patch-artifacts-import-gemm-module.sh
Recompiling
As long as you don't update any submodule, just follow Compile steps.
If you update a submodule, execute following command in repository root folder before executing
Compile steps.
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.