From 1a4add19da211e31c60c1e4ca6b27f3de5235020 Mon Sep 17 00:00:00 2001 From: abhi-agg <66322306+abhi-agg@users.noreply.github.com> Date: Mon, 3 May 2021 17:13:43 +0200 Subject: [PATCH] Improve script to patch wasm artifacts and load EN->DE vocabulary in wasm test (#125) * Improved script that patches wasm artifacts to enable wormhole - Made the regex pattern ignore multiple whitespaces b/w words of the matching pattern * Fix for loading EN->DE vocabularies in wasm test page - Loading vocabularies for EN->DE was failing because of the new structure of bergamot-models --- wasm/patch-artifacts-enable-wormhole.sh | 6 +++--- wasm/test_page/bergamot.html | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/wasm/patch-artifacts-enable-wormhole.sh b/wasm/patch-artifacts-enable-wormhole.sh index c16ba66..d636056 100644 --- a/wasm/patch-artifacts-enable-wormhole.sh +++ b/wasm/patch-artifacts-enable-wormhole.sh @@ -1,7 +1,7 @@ #!/bin/bash echo "Patching wasm artifacts to enable wormhole via APIs that compile and instantiate wasm module" -sed -i.bak 's/var result = WebAssembly.instantiateStreaming(response, info);/var result = WebAssembly.instantiateStreaming(response, info, {simdWormhole:true});/g' wasm/bergamot-translator-worker.js -sed -i.bak 's/return WebAssembly.instantiate(binary, info);/return WebAssembly.instantiate(binary, info, {simdWormhole:true});/g' wasm/bergamot-translator-worker.js -sed -i.bak 's/var module = new WebAssembly.Module(bytes);/var module = new WebAssembly.Module(bytes, {simdWormhole:true});/g' wasm/bergamot-translator-worker.js +sed -i.bak 's/WebAssembly.instantiateStreaming[[:space:]]*([[:space:]]*response[[:space:]]*,[[:space:]]*info[[:space:]]*)/WebAssembly.instantiateStreaming(response, info, {simdWormhole:true})/g' wasm/bergamot-translator-worker.js +sed -i.bak 's/WebAssembly.instantiate[[:space:]]*([[:space:]]*binary[[:space:]]*,[[:space:]]*info[[:space:]]*)/WebAssembly.instantiate(binary, info, {simdWormhole:true})/g' wasm/bergamot-translator-worker.js +sed -i.bak 's/WebAssembly.Module[[:space:]]*([[:space:]]*bytes[[:space:]]*)/WebAssembly.Module(bytes, {simdWormhole:true})/g' wasm/bergamot-translator-worker.js echo "Done" diff --git a/wasm/test_page/bergamot.html b/wasm/test_page/bergamot.html index 6bab606..95ae325 100644 --- a/wasm/test_page/bergamot.html +++ b/wasm/test_page/bergamot.html @@ -93,8 +93,8 @@ En consecuencia, durante el año 2011 se introdujeron 180 proyectos de ley que r /*const modelConfig = `models: - /${languagePair}/model.${languagePair}.intgemm.alphas.bin vocabs: - - /${vocabLanguagePair}/vocab.${vocabLanguagePair}.spm - - /${vocabLanguagePair}/vocab.${vocabLanguagePair}.spm + - /${languagePair}/vocab.${vocabLanguagePair}.spm + - /${languagePair}/vocab.${vocabLanguagePair}.spm beam-size: 1 normalize: 1.0 word-penalty: 0 @@ -114,8 +114,8 @@ shortlist: */ const modelConfigWithoutModelAndShortList = `vocabs: - - /${vocabLanguagePair}/vocab.${vocabLanguagePair}.spm - - /${vocabLanguagePair}/vocab.${vocabLanguagePair}.spm + - /${languagePair}/vocab.${vocabLanguagePair}.spm + - /${languagePair}/vocab.${vocabLanguagePair}.spm beam-size: 1 normalize: 1.0 word-penalty: 0