Downloads · 30 days
0
DarcyCheng/T5-finetune-model
T5-finetune-model is a translation model from DarcyCheng. Use it when you need text moved from one language to another.
This project fine-tunes the T5 pre-trained model to implement neural machine translation from Chinese to English. T5 (Text-To-Text Transfer Transformer) is a unified text-to-text pre-trained model proposed by Google.…
Downloads · 30 days
0
Access
Public
Updated Dec 28, 2025
Repo size
—
Likes
0
Public
Click a slice to open those files.
.md4.8 KB · 76%
From the Hugging Face model README
This project fine-tunes the T5 pre-trained model to implement neural machine translation from Chinese to English. T5 (Text-To-Text Transfer Transformer) is a unified text-to-text pre-trained model proposed by Google. By unifying various NLP tasks as text generation tasks, it has achieved excellent performance across multiple tasks. In this project, we use the T5-base model and fine-tune it on Chinese-English parallel corpora to achieve high-quality Chinese-to-English translation.
Due to the model chechpoint is too big to upload to github, so I put it on huggingface: https://huggingface.co/DarcyCheng/T5-finetune-model
And if you want to download the pretrained model of T5, please go to the url: https://huggingface.co/google-t5/t5-base/tree/main
The data compression package contains four JSONL files, corresponding to the small-scale training set, large-scale training set, validation set, and test set, with 100k, 10k, 500, and 200 samples respectively. Each line in each JSONL file contains a parallel sentence pair. The final model performance will be evaluated based on the results on the test set.
Data file structure:
train_100k.jsonl: Small-scale training set (100,000 entries)train_10k.jsonl: Large-scale training set (10,000 entries)val.jsonl: Validation set (500 entries)test.jsonl: Test set (200 entries)Format of each JSONL file:
{"zh": "Chinese sentence", "en": "English sentence"}
pip install -r requirements.txt
Key dependencies include:
torch>=2.0.1transformershydra-coreomegaconfnltkjiebasentencepiecenumpytqdmBefore training the T5 model, you can first train the SentencePiece (SPM) model to achieve better tokenization performance:
conda activate llm_course
python train_spm_models.py
Train the T5 model for Chinese-to-English translation (SPM is used automatically):
python train.py
Training configurations are stored in configs/train.yaml, with key parameters including:
NUM_EPOCHS: Number of training epochs (default: 50)BATCH_SIZE: Batch size (default: 64)LEARNING_RATE: Learning rate (default: 1e-5)DATA_DIR: Path to the data directoryEvaluate the model performance on the test set:
python evaluation.py
The evaluation script calculates BLEU-1, BLEU-2, BLEU-3, and BLEU-4 scores (in percentage, ranging from 0 to 100).
python inference.py input_text="Hello"
python inference.py input_file=test.txt output_file=translations.txt
python inference.py interactive=True
python inference.py input_file=test.txt reference_file=reference.txt
Inference configurations are stored in configs/inference.yaml, which can be set as follows:
model_path: Path to the trained model checkpointmax_length: Maximum generation lengthnum_beams: Beam search sizeWe would like to acknowledge the following repositories: