bergamot-translator/wasm
Abhishek Aggarwal 8884b39055
Disabled importing optimized gemm module (#282)
- Until the optimized gemm module stops requiring
   Shared Array Buffer, we can't really use it in
   Firefox
2021-12-17 17:39:43 +01:00
..
bindings HTML input (#253) 2021-11-25 13:57:50 +00:00
test_page Additional logs in JS translation worker (#277) 2021-12-14 21:52:00 +01:00
CMakeLists.txt Import matrix-multiply from a separate wasm module (#232) 2021-10-27 11:54:39 +02:00
import-gemm-module.js Disabled importing optimized gemm module (#282) 2021-12-17 17:39:43 +01:00
patch-artifacts-enable-wormhole.sh Improved wasm scripts and README (#128) 2021-05-04 10:18:45 +01:00
patch-artifacts-import-gemm-module.sh Import optimized gemm implementation (when available) for wasm target (#265) 2021-11-17 09:18:55 +01:00
project_version.js.in Modified wasm cmake file to include version information in built artifacts 2021-05-17 19:34:58 +02:00
README.md Wasm test page UI for translating b/w non-English language pairs (#231) 2021-10-19 14:40:54 +02:00

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/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 and To dropdowns.
    • Type a sentence to be translated in the From textbox.
    • See the result in the To textbox.