e34420647d
* Rework WASM compilation options Necessary to work with newer versions of emscripten that are more picky about which option goes to the compiler, and which to the linker. Also took the opportunity to remove the need for the patching of the bergamot-translation-worker.js file, this can now easily be done through supported apis. Furthermore, I tried to downsize the generated javascript and wasm code a bit. Initial estimates show that bergamot-translator compiled with emscripten 3.0.0 runs at about 3x the speed of 2.0.9 (when using embedded intgemm). Speed-up when using mozIntGemm is less dramatic. * Updated marian-dev submodule * Revert changes specific to patching external gemm modules for wasm * Better Compilation and Link flags - Added "-O3" optimization flag for linking as well - "-g2" only for release and debug builds - "-g1" for release builds - Replaced deprecated "--bind" flag with "-lembind" - Removed redundant link flag * Upgraded emsdk to 3.1.8 * Enclosed EXPORTED_FUNCTIONS values in a list * Fixed the remaining 2.0.9 reference in circle ci build script * Updated README Co-authored-by: Jelmer van der Linde <jelmer@ikhoefgeen.nl> |
||
---|---|---|
.. | ||
bindings | ||
test_page | ||
CMakeLists.txt | ||
README.md | ||
import-gemm-module.js | ||
patch-artifacts-enable-wormhole.sh | ||
patch-artifacts-import-gemm-module.sh | ||
project_version.js.in |
README.md
Using Bergamot Translator in JavaScript
All the instructions below are meant to run from the current directory.
Using JS APIs
Please refer to the file test_page/js/worker.js
that demonstrates how to use the bergamot translator in JavaScript via a <script>
tag.
Demo
-
Download bergamot model files required for translation
Use following instructions to download model files (make sure that
git-lfs
is installed and initialized before running these instructions):cd test_page git clone --depth 1 --branch main --single-branch https://github.com/mozilla/firefox-translations-models/ mkdir models cp -rf firefox-translations-models/registry.json models cp -rf firefox-translations-models/models/prod/* models cp -rf firefox-translations-models/models/dev/* models gunzip models/*/*
-
Start the test webserver (ensure you have the latest nodejs installed)
cd test_page bash start_server.sh ../../build-wasm
Provide the folder containing the wasm artifacts as the first argument of
start_server.sh
script (../../build-wasm
in this case). -
Open any of the browsers below
-
Firefox Nightly +87: make sure the following prefs are on (about:config)
dom.postMessage.sharedArrayBuffer.bypassCOOP_COEP.insecure.enabled = true javascript.options.wasm_simd = true javascript.options.wasm_simd_wormhole = true
-
Chrome Canary +90: start with the following argument
--js-flags="--experimental-wasm-simd"
-
-
Browse to the following page:
http://localhost:80
-
Perform translations:
- Choose the source and target languages using
From
andTo
dropdowns. - Type a sentence to be translated in the
From
textbox. - See the result in the
To
textbox.
- Choose the source and target languages using