Downloads · 30 days
0
amc-madalin/amc-en-it
amc-en-it is a machine learning model from amc-madalin. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as mit.
This project implements a Transformer model for language translation between English and Italian. Built from scratch, it aims to provide a deeper understanding of the Transformer architecture, which has become a corne…
Downloads · 30 days
0
Access
Public
Updated Sep 14, 2024
Repo size
904 MB
Likes
0
Public
Click a slice to open those files.
.pt904 MB · 100%
From the Hugging Face model README
This project implements a Transformer model for language translation between English and Italian. Built from scratch, it aims to provide a deeper understanding of the Transformer architecture, which has become a cornerstone in natural language processing tasks. The project explores key elements of the architecture, such as the attention mechanism, and demonstrates hands-on experience with data preprocessing, model training, and evaluation.
You can find and use the pre-trained model on Hugging Face here: Model on Hugging Face
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
# Load model and tokenizer
tokenizer = AutoTokenizer.from_pretrained("your-huggingface-model-url")
model = AutoModelForSeq2SeqLM.from_pretrained("your-huggingface-model-url")
# Translation Example
text = "Hello, how are you?"
inputs = tokenizer(text, return_tensors="pt")
outputs = model.generate(**inputs)
translated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(translated_text)
attention_visual.ipynb): A notebook for visualizing attention maps to understand how the model focuses on different sentence parts during translation.config.py): Includes hyperparameters and other modifiable settings.dataset.py): Handles loading and preprocessing of English and Italian datasets.model.py): Defines the Transformer model architecture.README.md): This file, which provides a complete overview of the project.runs/): Logs and outputs from model training sessions.tokenizer_en.json, tokenizer_it.json): Tokenizers for English and Italian text preprocessing.train.py): The script that encapsulates the training process.weights/): Stores the trained model weights for future use.To set up and run the project locally, follow these steps:
Clone the Repository:
git clone https://github.com/amc-madalin/transformer-for-language-translation.git
Create a Python Environment:
Create a Conda environment:
conda create --name transformer python=3.x
Replace 3.x with your preferred Python version.
Activate the Environment:
conda activate transformer
Install Dependencies:
Install required packages from requirements.txt:
pip install -r requirements.txt
Prepare Data:
The dataset will be automatically downloaded. Modify the source (lang_src) and target (lang_tgt) languages in config.py, if necessary. The default is set to English (en) and Italian (it):
"lang_src": "en",
"lang_tgt": "it",
Train the Model: Start the training process with:
python train.py
Use the Model:
The trained model weights will be saved in the weights/ directory. Use these weights for inference, evaluation, or further applications.
Once trained, the model can be uploaded to Hugging Face for easy access and use.
Use the following steps to upload your trained model to Hugging Face:
huggingface-cli login
transformers-cli upload ./weights/ --organization your-organization
You can easily load the model for translation tasks directly from Hugging Face:
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
tokenizer = AutoTokenizer.from_pretrained("your-huggingface-model-url")
model = AutoModelForSeq2SeqLM.from_pretrained("your-huggingface-model-url")
# Translate text
text = "How are you?"
inputs = tokenizer(text, return_tensors="pt")
outputs = model.generate(**inputs)
translation = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(translation)
Special thanks to Umar Jamil for his guidance and contributions that supported the completion of this project.