instant-distance/instant-distance-py/examples/translations
Dirkjan Ochtman dc0bc5a219 Bump dependency for GHSA-45c4-8wx5-qw6w 2023-08-02 10:04:00 +02: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 Bump dependency for GHSA-45c4-8wx5-qw6w 2023-08-02 10:04:00 +02:00
translate.py py: use asyncio.run() function 2023-02-02 11:50:48 +01: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