2020-10-29 11:17:32 +03:00
# Bergamot Translator
2021-11-15 11:14:21 +03:00
[![CircleCI badge ](https://img.shields.io/circleci/project/github/browsermt/bergamot-translator/main.svg?label=CircleCI )](https://circleci.com/gh/browsermt/bergamot-translator/)
2021-03-10 20:30:39 +03:00
2020-10-29 11:17:32 +03:00
Bergamot translator provides a unified API for ([Marian NMT](https://marian-nmt.github.io/) framework based) neural machine translation functionality in accordance with the [Bergamot ](https://browser.mt/ ) project that focuses on improving client-side machine translation in a web browser.
2020-11-16 15:09:42 +03:00
## Build Instructions
2021-02-12 01:27:16 +03:00
### Build Natively
2021-05-12 15:44:33 +03:00
Create a folder where you want to build all the artifacts (`build-native` in this case) and compile
2021-02-12 01:27:16 +03:00
2021-05-12 15:44:33 +03:00
```bash
mkdir build-native
cd build-native
cmake ../
2021-06-08 16:36:22 +03:00
make -j2
2021-05-12 15:44:33 +03:00
```
2020-11-16 15:09:42 +03:00
2021-02-12 01:27:16 +03:00
### Build WASM
2021-05-12 15:44:33 +03:00
#### 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`
2021-06-08 16:36:22 +03:00
* Install the lastest sdk tools: `./emsdk install 2.0.9`
* Activate the latest sdk tools: `./emsdk activate 2.0.9`
2021-05-12 15:44:33 +03:00
* Activate path variables: `source ./emsdk_env.sh`
2021-02-17 14:55:31 +03:00
2021-05-12 15:44:33 +03:00
#### <a name="Compile"></a> Compile
2021-02-17 14:55:31 +03:00
2021-08-11 14:28:15 +03:00
To build a version that translates with higher speeds on Firefox Nightly browser, follow these instructions:
1. Create a folder where you want to build all the artifacts (`build-wasm` in this case) and compile
```bash
mkdir 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).
2. Enable SIMD Wormhole via Wasm instantiation API in generated artifacts
```bash
bash ../wasm/patch-artifacts-enable-wormhole.sh
```
2021-10-27 12:54:39 +03:00
3. Patch generated artifacts to import GEMM library from a separate wasm module
```bash
bash ../wasm/patch-artifacts-import-gemm-module.sh
```
2021-08-11 14:28:15 +03:00
To build a version that runs on all browsers (including Firefox Nightly) but translates slowly, follow these instructions:
1. Create a folder where you want to build all the artifacts (`build-wasm` in this case) and compile
```bash
mkdir build-wasm
cd build-wasm
emcmake cmake -DCOMPILE_WASM=on -DWORMHOLE=off ../
emmake make -j2
```
2021-02-17 14:55:31 +03:00
2021-10-27 12:54:39 +03:00
2. Patch generated artifacts to import GEMM library from a separate wasm module
```bash
bash ../wasm/patch-artifacts-import-gemm-module.sh
```
2021-02-17 14:55:31 +03:00
#### Recompiling
2021-05-12 15:44:33 +03:00
As long as you don't update any submodule, just follow [Compile ](#Compile ) steps.\
If you update a submodule, execute following command in repository root folder before executing
[Compile ](#Compile ) steps.
2021-01-22 14:51:49 +03:00
```bash
2021-02-17 14:55:31 +03:00
git submodule update --init --recursive
2021-02-12 01:27:16 +03:00
```
2021-01-22 14:51:49 +03:00
2021-02-15 12:21:36 +03:00
2021-02-17 14:55:31 +03:00
## How to use
2021-01-22 14:51:49 +03:00
2021-02-12 01:27:16 +03:00
### Using Native version
2021-01-22 14:51:49 +03:00
2021-02-17 14:55:31 +03:00
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.
2021-01-22 14:51:49 +03:00
2021-02-12 01:27:16 +03:00
### Using WASM version
2021-01-22 14:51:49 +03:00
2021-02-12 01:27:16 +03:00
Please follow the `README` inside the `wasm` folder of this repository that demonstrates how to use the translator in JavaScript.