instant-distance/instant-distance-py/examples/translations
Dirkjan Ochtman 7caae1db16 py: bump aiohttp dependency to 3.8.3 to avoid build error 2023-02-02 11:50:48 +01:00
..
.gitignore Add a translation example (#11) 2021-05-29 18:04:36 +02:00
README.md Add a translation example (#11) 2021-05-29 18:04:36 +02:00
requirements.txt py: bump aiohttp dependency to 3.8.3 to avoid build error 2023-02-02 11:50:48 +01:00
translate.py Increment progress bar if we skip a word 2021-06-01 06:48:42 +02:00

README.md

Translation Example

This example uses the pre-trained aligned word vectors made available by Facebook Research as part of fastText to translate English words to French and Italian.

Trying it out

Currently, macOS and Python 3.9 is required.

First, install the requirements:

pip install -r requirements.txt

Run the following command to translate an english word:

python translate.py translate hello
Loading indexes from filesystem...
Language: fr, Translation: hello
Language: it, Translation: hello
Language: it, Translation: ciao
Language: fr, Translation: bonjours
Language: fr, Translation: bonjour
Language: fr, Translation: bonsoir
Language: fr, Translation: !
Language: fr, Translation: salutations
Language: it, Translation: buongiorno
Language: it, Translation: hey

The translate command will download the vector data and build an index on the first run. Subsequent runs will be faster.

Downloading and building the index takes about 7 minutes on a MacBook Pro (16-inch, 2019) with 2.4 GHz 8-Core Intel Core i9 and 64GB of RAM and a gigabit internet connection.

If you like, you can rebuild the index at any time:

python translate.py build