XapaJIaMnu / translateLocally

Fast and secure translation on your local machine, powered by marian and Bergamot.
MIT License
501 stars 28 forks source link

Ability to load firefox-translations-models #134

Closed c6401 closed 9 months ago

c6401 commented 1 year ago

Wondering if I can load some of models from https://github.com/mozilla/firefox-translations-models ?

Godnoken commented 1 year ago

Yes, it is possible :)

Let's say you want the Dutch - English model.

  1. Create a folder called nlen.student.tiny in User/>Your username</Appdata/Roaming/translateLocally
  2. Download the files here
  3. Unpack each file to your new folder
  4. Create a file called model_info.json and copy & paste this text;
{
  "modelName": "Dutch-English tiny",
  "shortName": "nl-en-tiny",
  "type":      "tiny",
  "src":       "Dutch",
  "trg":       "English",
  "srcTags":   {"nl": "Dutch"},
  "trgTag":    "en",
  "repository": "Bergamot",
  "version":   1,
  "API":       1
}
  1. Create a file called config.intgemm8bitalpha.yml and copy & paste this text;
relative-paths: true
models:
  - model.nlen.intgemm.alphas.bin
vocabs:
  - vocab.nlen.spm
  - vocab.nlen.spm
shortlist:
    - lex.50.50.nlen.s2t.bin
    - false
beam-size: 1
normalize: 1.0
word-penalty: 0
mini-batch: 64
maxi-batch: 1000
maxi-batch-sort: src
workspace: 2000
max-length-factor: 2.0
skip-cost: true
gemm-precision: int8shiftAlphaAll
  1. You should now be able to see it in the translateLocally app

That's it. Basically you just have to adjust each of their models to fit into translateLocally's format. Keep in mind that you'll have to rename some lines in these two files to adjust for other languages. Some models may also have two vocab files, one for source and one for target.

Edit;

While the config.intgemm8bitalpha.yml in the example above may work just fine in terms of quality/performance, it may not be ideal for every model. Unfortunately, I can't help you with that at the moment as I don't possess the knowledge of how it works in detail yet.

c6401 commented 1 year ago

Awesome, thank you!

c6401 commented 9 months ago

the solution works brillliantly