Download Models

Downloading all the models required by the English/French and French/English translation web services from Hugging Face.

Imports

We import the AutoTokenizer and AutoModelForSeq2SeqLM classes from Hugging Face’s transformers library. Those are used to automatically load any type of model and tokenizer.

from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
import os

Get Model and Tokenizer Files

The next step is to download each model_name to the specified model_path. For the given model_name, the function will download all the appropriate model and tokenizer files to that path. If the specified path is not existing, then it will be created by the function.


source

download_model

 download_model (model_path:str, model_name:str)

Download a Hugging Face model and tokenizer to the specified directory

Download Models

The final step is to download the English/French translation model and the French/English translation model which are two different

download_model('models/en_fr/', 'Helsinki-NLP/opus-mt-en-fr')
download_model('models/fr_en/', 'Helsinki-NLP/opus-mt-fr-en')