You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Running the test_page example in this repository left me wowed, but also with a little bad taste, as for the complexity of how much code one needs to write/copy in order to use it.
Additionally, all paths in that example are relative, requiring every user to adjust the worker code to their directory structure.
import{createBergamotWorker}from'@sign-mt/browsermt';// OR import {createBergamotWorker} from 'https://unpkg.com/@sign-mt/[email protected]/build/bundled/index.js'constworker=createBergamotWorker('/node_modules/@sign-mt/browsermt/build/esm/worker.js');// OR createBergamotWorker('https://unpkg.com/@sign-mt/[email protected]/build/bundled/worker.js')// Copy these artifacts to your deployed folderawaitworker.importBergamotWorker('browsermt/bergamot-translator-worker.js','browsermt/bergamot-translator-worker.wasm',);// Create object with URLs to the mode filesconstmodelRegistry={enru: {model: {name: "/models/enru/model.enru.intgemm.alphas.bin"},lex: {name: "/models/enru/lex.50.50.enru.s2t.bin"},vocab: {name: "/models/enru/vocab.enru.spm"}}};awaitworker.loadModel('en','ru',modelRegistry);consttranslations=awaitworker.translate('en','ru',['test sentence','other sentence'],{isHtml: false});console.log(translations);
The text was updated successfully, but these errors were encountered:
Thanks @kpu
I was not aware of that PR, would have saved me some time :)
My code has multiple advantages, namely:
control about every file's location (workers, models, etc)
types support (written in typescript, and heavily typed)
minimally changes your implementation in this repository
supports worker threads in node.js (now tested)
And disadvantages:
I probably did not put as much thought into this as @jelmervdi did, and thus may have not included some extra features / some additional code cleaning, as my goal was having something published, and usable right away.
Running the
test_page
example in this repository left me wowed, but also with a little bad taste, as for the complexity of how much code one needs to write/copy in order to use it.Additionally, all paths in that example are relative, requiring every user to adjust the worker code to their directory structure.
I replicated that example fully here - https://github.com/sign/browsermt/tree/main/example/src
And wrote an npm module to work with bergamot models
From your app, usage becomes extremely simple:
The text was updated successfully, but these errors were encountered: