Downloads · 30 days
0
nashit93/EnglishToHindiTranslationLongContext
EnglishToHindiTranslationLongContext is a translation model from nashit93. Use it when you need text moved from one language to another. The card lists the license as apache-2.0.
1. Introduction 2. Model Overview 3. Installation 4. Quick Start 5. Detailed Usage 6. Customization and Training 7. Contributing 8. Citation 9. License 10. Contact
Downloads · 30 days
0
Access
Public
Updated Mar 29, 2024
Repo size
2.2 GB
Likes
0
Public
Click a slice to open those files.
.h52.2 GB · 100%
From the Hugging Face model README
<a name="introduction"></a>
This repository houses an advanced English-to-Hindi translation model leveraging Google's mT5-small powerful transformers. It is designed for accurate, context-aware translations, utilizing cutting-edge NLP techniques.
<a name="model-overview"></a>
<a name="installation"></a>
pip install transformers tensorflow pandas dataset tqdm
<a name="quick-start"></a>
git lfs install
git clone https://huggingface.co/nashit93/EnglishToHindiTranslationLongContext
cd EnglishToHindiTranslationLongContext
#!/usr/bin/env python
# coding: utf-8
import tensorflow as tf
import os
from transformers import TFMT5ForConditionalGeneration, MT5Tokenizer
import pandas as pd
from datasets import Dataset
from tqdm import tqdm
# Set up tokenizer
tokenizer = MT5Tokenizer.from_pretrained("google/mt5-small")
# Function to load the model from the latest checkpoint
def load_model(checkpoint_dir):
latest_checkpoint = None
if os.path.exists(checkpoint_dir):
checkpoints = [os.path.join(checkpoint_dir, d) for d in os.listdir(checkpoint_dir)]
checkpoints = [d for d in checkpoints if os.path.isdir(d)]
if checkpoints:
latest_checkpoint = max(checkpoints, key=os.path.getmtime)
if latest_checkpoint:
print("Loading model from:", latest_checkpoint)
return TFMT5ForConditionalGeneration.from_pretrained(latest_checkpoint)
else:
print("No checkpoint found, loading default model")
return TFMT5ForConditionalGeneration.from_pretrained("google/mt5-small")
# Load the model
model = load_model('model_checkpoints-small-on-1mill-dp')
# Function to prepare text for prediction
def prepare_text(text, tokenizer, max_length=200):
inputs = tokenizer.encode(text, return_tensors="tf", max_length=max_length, truncation=True)
return inputs
# Function to generate prediction with adjustable settings
def generate_prediction(text, model, tokenizer, max_length=2000, num_beams=5):
input_ids = prepare_text(text, tokenizer, max_length=max_length)
output_ids = model.generate(
input_ids,
max_length=max_length,
num_beams=num_beams,
no_repeat_ngram_size=2,
early_stopping=True
)
return tokenizer.decode(output_ids[0], skip_special_tokens=True)
# Example Prediction
sample_text = "Hi , how are you?"
prediction = generate_prediction(sample_text, model, tokenizer)
print("Prediction:", prediction)
<a name="detailed-usage"></a>
Explore advanced functionalities, including batch processing, handling different text lengths, and model fine-tuning.
<a name="contributing"></a>
We warmly welcome contributions from the community to improve and enhance the English-to-Hindi translation model. If you're looking to contribute, here's how you can get started:
After submitting your pull request:
If you need help or have questions about contributing, feel free to reach out @ [email protected]
Your contributions, big or small, make a significant impact on the project and the community. We look forward to your ideas, bug reports, feature requests, and code contributions! 🌟
<a name="citation"></a>
If you use this model in your research, please cite it.
<a name="license"></a>
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
<a name="contact"></a>
Reach out to the maintainers at [email protected] for any questions or collaboration inquiries.
<a name="acknowledgements"></a>