Skip to content

Free and open source pre-trained translation models, including Kurdish, Samoan, Xhosa, Lao, Corsican, Cebuano, Galician, Yiddish, Swahili, and Yoruba.

License

Notifications You must be signed in to change notification settings

lingvanex-mt/models

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lingvanex Translator

Try it online! | Translation API | Blog

Python versions

Free and Open Source Machine Translation Models in 12 languages, entirely self-hosted. Unlike other APIs, it doesn't rely on proprietary providers such as Google or AWS to perform translations. Instead, its translation engine is powered by the open source CTranslate2 library.

Also we have translation models for 100 other languages. Contact us [email protected]

Translation

Try it online! | API Docs

Free Language Translation Models for CTranslate2

The models support the following languages:

The models are available for download and you can use them in your projects. You can easily run them in your Python environment as shown below.

Requirements

To run the models, you need to install ctranslate2 and sentencepiece:

pip install ctranslate2 sentencepiece

Simple Usage Example

The following code demonstrates how to load and use a model for translation from English to Kurdish (en → ku).

import sentencepiece as spm
from ctranslate2 import Translator

path_to_model = <here_is_your_path_to_the_model>
source = 'en'
target = 'ku'

translator = Translator(path_to_model, compute_type='int8')
source_tokenizer = spm.SentencePieceProcessor(f'{path_to_model}/{source}.spm.model')
target_tokenizer = spm.SentencePieceProcessor(f'{path_to_model}/{target}.spm.model')

text = [
  'I need to make a phone call.',
  'Can I help you prepare food?',
  'We want to go for a walk.'
]

input_tokens = source_tokenizer.EncodeAsPieces(text)
translator_output = translator.translate_batch(
  input_tokens,
  batch_type='tokens',
  beam_size=2,
  max_input_length=0,
  max_decoding_length=256
)

output_tokens = [item.hypotheses[0] for item in translator_output]
translation = target_tokenizer.DecodePieces(output_tokens)
print('\n'.join(translation))

API Usage Examples

Simple

Request:

const url = 'https://api-b2b.backenster.com/b1/api/v3/translate';
const options = {
  method: 'POST',
  headers: {
    accept: 'application/json',
    'content-type': 'application/json',
    Authorization: 'API Key'
  },
  body: JSON.stringify({
      platform: 'api',
      from: 'en', 
      to: 'es',
      data: 'Hello'
    })
};

fetch(url, options)
  .then(res => res.json())
  .then(json => console.log(json))
  .catch(err => console.error(err));

Response:

{
  "err": null,
  "result": "Hola"
}

List of language codes: https://docs.lingvanex.com/reference/user-guide

Auto Detect Language

Request:

const url = 'https://api-b2b.backenster.com/b1/api/v3/translate';
const options = {
  method: 'POST',
  headers: {
    accept: 'application/json',
    'content-type': 'application/json',
    Authorization: 'API Key'
  },
  body: JSON.stringify({
      platform: 'api',
      to: 'en',
      data: 'Auf Wiedersehen'
    })
};

fetch(url, options)
  .then(res => res.json())
  .then(json => console.log(json))
  .catch(err => console.error(err));

Response:

{
  "err": null,
  "result": "Goodbye",
  "from": "de"
}

HTML

Request:

const url = 'https://api-b2b.backenster.com/b1/api/v3/translate';
const options = {
  method: 'POST',
  headers: {
    accept: 'application/json',
    'content-type': 'application/json',
    Authorization: 'API Key'
  },
  body: JSON.stringify({
      platform: 'api',
      translateMode: 'html',
      from: 'en', 
      to: 'es',
      data: '<h1>Welcome to the test page</h1>'
    })
};

fetch(url, options)
  .then(res => res.json())
  .then(json => console.log(json))
  .catch(err => console.error(err));

Response:

{
  "err": null,
  "result": "<h1>Bienvenido a la página de prueba</h1>"
}

Transliteration

Request:

const url = 'https://api-b2b.backenster.com/b1/api/v3/translate';
const options = {
  method: 'POST',
  headers: {
    accept: 'application/json',
    'content-type': 'application/json',
    Authorization: 'API Key'
  },
  body: JSON.stringify({
      platform: 'api',
      from: 'en', 
      to: 'zh-Hans_CN',
      data: 'Hello',
      enableTransliteration: true
    })
};

fetch(url, options)
  .then(res => res.json())
  .then(json => console.log(json))
  .catch(err => console.error(err));

Response:

{
  "err": null,
  "result": "你好",
  "sourceTransliteration": "Hello",
  "targetTransliteration": "Ni Hao"
}

Usage Examples in Different Languages

You can use the Lingvanex API using the following different languages:

Desktop Apps

Mobile Apps

Web Browser

Translator Bot for Slack

License

This project is licensed under the MIT License.

Contact

If you have any questions, just email [email protected]