Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

codecov

OVOS No Language Left Behind Plugin (CTranslate2)

This is a language plugin for NLLB-200, a translation model from Meta AI.

Overview

NLLB200Translator translates text between languages with the NLLB-200 models. It plugs into the OVOS framework and uses CTranslate2 to run translation fast and efficiently.

Model Options

The table below lists the available models for the NLLB-200 translator.

Model Name Source Description
flores200_sacrebleu_tokenizer_spm CTranslate2 Tokenizer model
nllb-200_600M_int8 CTranslate2 600M parameter model, int8 quantized
nllb-200_1.2B_int8 CTranslate2 1.2B parameter model, int8 quantized
nllb-200_3.3B_int8 CTranslate2 3.3B parameter model, int8 quantized
nllb-200-distilled-1.3B-ct2-int8 HuggingFace Hub: OpenNMT/nllb-200-distilled-1.3B-ct2-int8 1.3B distilled model, int8 quantized
nllb-200-3.3B-ct2-int8 HuggingFace Hub: OpenNMT/nllb-200-3.3B-ct2-int8 3.3B model, int8 quantized

Install

Install the plugin with pip:

pip install ovos-translate-plugin-nllb

Usage

OVOS Integration

Use the plugin inside OVOS to translate utterances and text on demand. Add this configuration to one of the configuration files, for example ~/.config/mycroft/mycroft.conf:

{
  "language": {
    "translation_module": "ovos-translate-plugin-nllb",
    "ovos-translate-plugin-nllb": {
      "model": "nllb-200_600M_int8"
    }
  }
}

Python Script

This example shows how to use NLLB200Translator in a Python script.

from ovos_translate_plugin_nllb import NLLB200Translator

src = "es"
tgt = "en-us"
tx = NLLB200Translator(config={"model": "nllb-200_600M_int8"})

utts = ["Hola Mundo"]
print("Translations:", tx.translate(utts, tgt, src))

utts = "hello world"
print("Translations:", tx.translate(utts, src, tgt))

Advanced Configuration

HuggingFace Integration

To use a model hosted on the HuggingFace Hub, set the model parameter to the HuggingFace model ID. NLLB200Translator downloads and loads the model from HuggingFace.

Additional Parameters

  • beam_size: the beam size used for translation. A larger value trades speed for translation quality.
  • device: the device to run on, either cpu or cuda (GPU).
from ovos_translate_plugin_nllb import NLLB200Translator
tx = NLLB200Translator(config={
    "model": "nllb-200_600M_int8",
    "beam_size": 5,
    "device": "cuda"
})

Using CUDA/GPU

Set NLLB200Translator to the cuda device to use GPU acceleration. This can speed up translation for large batches or long texts.

Prerequisites

You need a CUDA-compatible GPU and the CUDA drivers for your system. See the CUDA Installation Guide for details.

Example

This example configures and runs NLLB200Translator with CUDA.

from ovos_translate_plugin_nllb import NLLB200Translator

if __name__ == "__main__":
    src = "es"
    tgt = "en-us"
    tx = NLLB200Translator(config={
        "model": "nllb-200-3.3B-int8",
        "beam_size": 5,
        "device": "cuda"
    })
    
    utts = ["Hola Mundo"]
    print("Translations:", tx.translate(utts, tgt, src))
    
    utts = "hello world"
    print("Translations:", tx.translate(utts, src, tgt))

Related Projects

License

This project is licensed under the Apache License 2.0.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ovos_translate_plugin_nllb-0.0.2a5.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ovos_translate_plugin_nllb-0.0.2a5-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file ovos_translate_plugin_nllb-0.0.2a5.tar.gz.

File metadata

File hashes

Hashes for ovos_translate_plugin_nllb-0.0.2a5.tar.gz
Algorithm Hash digest
SHA256 8eab0782434a409be66a3134d747a2b8b6f3308d3d43f766c96d360f7903e21d
MD5 1ee810ab6be2a64eb7b3ac249fcfe3ea
BLAKE2b-256 9a9b0f77df53e944dec22cd53f9aeb9e63e864e52df572d2b0fbbb6a22c70bee

See more details on using hashes here.

File details

Details for the file ovos_translate_plugin_nllb-0.0.2a5-py3-none-any.whl.

File metadata

File hashes

Hashes for ovos_translate_plugin_nllb-0.0.2a5-py3-none-any.whl
Algorithm Hash digest
SHA256 6179a3ebe5c682c321a0f31da0df016cc115cd02595fdaafe0cf982408a282b1
MD5 9c5e2dc2bebd6743f67f5b46753cbf91
BLAKE2b-256 bb52ebdd19b2057028642bde504ea3ff6f6ca8173cd14bd8d09008faa0737ea9

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.0.2a5 This release

2 files

0.0.1

2 files

0.0.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page