Skip to main content
Version: Next

Function: createMarianTranslator()

createMarianTranslator(config, runtime?): Promise<MarianTranslator>

Defined in: extensions/nlp/tasks/marianTranslation.ts:87

Creates a translator for Marian encoder-decoder models such as Opus-MT.

The source sentence is encoded once into per-layer cross-attention keys and values, then decoded greedily one token at a time, starting from the pad token, until the end-of-sentence token. Sentences longer than the model's maximum source length are truncated.

Parameters​

config​

MarianTranslatorModel

Model and tokenizer paths. See MarianTranslatorModel.

runtime?​

any

Optional worklet runtime thread on which to run the model execution.

Returns​

Promise<MarianTranslator>

A promise resolving to the instantiated MarianTranslator.

Throws​

With code LOAD_FAILED if the model or tokenizer fails to load, or SCHEMA_MISMATCH if the model schema does not match the Marian specification.