This repository contains a Jupyter Notebook for building a language translation tool using Python. The tool utilizes the transformers library from Hugging Face and other necessary packages to perform translations between different languages.
Before running the notebook, you need to install the following packages:
transformers
sentencepiece
langid
These can be installed using pip
:
pip install transformers
pip install sentencepiece
pip install langid
To use the language translation tool, follow these steps:
Clone this repository to your local machine using the following command:
git clone https://github.com/your-username/language-translation-tool.git
Ensure that you have all the required packages installed. You can run the cells in the notebook that contain the pip install
commands, or manually install them as shown above.
Open the Language_Translation_Tool.ipynb
notebook in Jupyter or any compatible environment and execute the cells sequentially.
Follow the instructions in the notebook to input text and translate it into the desired language. The notebook contains code cells that guide you through the translation process.
The notebook contains the following sections:
- Installation: Commands to install the required packages.
- Code: The main code for language translation using Hugging Face's transformers.
Here is an example of how you can use the language translation tool:
from transformers import MarianMTModel, MarianTokenizer
model_name = 'Helsinki-NLP/opus-mt-en-fr'
model = MarianMTModel.from_pretrained(model_name)
tokenizer = MarianTokenizer.from_pretrained(model_name)
def translate(text):
inputs = tokenizer(text, return_tensors='pt', padding=True, truncation=True)
translated_tokens = model.generate(**inputs)
translated_text = tokenizer.batch_decode(translated_tokens, skip_special_tokens=True)
return translated_text
text = "Hello, how are you?"
translated_text = translate(text)
print(translated_text) # Output: "Bonjour, comment ça va ?"
Contributions are welcome! If you have any suggestions or improvements, please follow these steps:
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch
). - Make your changes.
- Commit your changes (
git commit -m 'Add some feature'
). - Push to the branch (
git push origin feature-branch
). - Open a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.