lijn14 commited on
Commit ·
fb0dadc
1
Parent(s): c0396a3
完成训练
Browse files- requirements-colab.txt +4 -3
- requirements.txt +4 -3
- result/evaluation_results.json +10 -0
- result/final_evaluation_metrics.png +0 -0
- result/train_loss_curve.png +0 -0
- result/training_summary.json +30 -0
- result/translation_examples.json +18 -0
- setup.py +6 -4
- src/easytranslate/evaluation/metrics.py +17 -5
requirements-colab.txt
CHANGED
|
@@ -8,13 +8,14 @@
|
|
| 8 |
transformers>=4.36.0,<4.45.0
|
| 9 |
datasets>=2.16.0,<3.0.0
|
| 10 |
tokenizers>=0.15.0,<0.20.0
|
| 11 |
-
sentencepiece>=0.
|
| 12 |
accelerate>=0.25.0,<0.35.0
|
| 13 |
peft>=0.7.0,<0.12.0
|
| 14 |
sacrebleu>=2.4.0,<3.0.0
|
| 15 |
-
unbabel-comet>=2.2.0,<2.3.0
|
| 16 |
omegaconf>=2.3.0,<3.0.0
|
| 17 |
rich>=13.0.0,<14.0.0
|
| 18 |
tqdm>=4.66.0,<5.0.0
|
| 19 |
wandb>=0.16.0,<0.18.0
|
| 20 |
-
tensorboard>=2.15.0,<2.17.0
|
|
|
|
|
|
|
|
|
| 8 |
transformers>=4.36.0,<4.45.0
|
| 9 |
datasets>=2.16.0,<3.0.0
|
| 10 |
tokenizers>=0.15.0,<0.20.0
|
| 11 |
+
sentencepiece>=0.2.0,<0.3.0
|
| 12 |
accelerate>=0.25.0,<0.35.0
|
| 13 |
peft>=0.7.0,<0.12.0
|
| 14 |
sacrebleu>=2.4.0,<3.0.0
|
|
|
|
| 15 |
omegaconf>=2.3.0,<3.0.0
|
| 16 |
rich>=13.0.0,<14.0.0
|
| 17 |
tqdm>=4.66.0,<5.0.0
|
| 18 |
wandb>=0.16.0,<0.18.0
|
| 19 |
+
tensorboard>=2.15.0,<2.17.0
|
| 20 |
+
protobuf>=5.28.3,<7.0.0
|
| 21 |
+
fsspec==2025.3.0
|
requirements.txt
CHANGED
|
@@ -7,14 +7,14 @@
|
|
| 7 |
# =============================================================================
|
| 8 |
|
| 9 |
# Core ML Framework
|
| 10 |
-
torch>=2.1.0,<2.
|
| 11 |
torchvision>=0.16.0; platform_system != "Darwin" or platform_machine != "arm64"
|
| 12 |
|
| 13 |
# HuggingFace Ecosystem
|
| 14 |
transformers>=4.36.0,<4.45.0
|
| 15 |
datasets>=2.16.0,<3.0.0
|
| 16 |
tokenizers>=0.15.0,<0.20.0
|
| 17 |
-
sentencepiece>=0.
|
| 18 |
accelerate>=0.25.0,<0.35.0
|
| 19 |
|
| 20 |
# Parameter-Efficient Fine-Tuning
|
|
@@ -40,8 +40,9 @@ pyyaml>=6.0.0,<7.0.0
|
|
| 40 |
rich>=13.0.0,<14.0.0
|
| 41 |
|
| 42 |
# Data Processing
|
| 43 |
-
numpy>=1.24.0,<
|
| 44 |
pandas>=2.0.0,<2.3.0
|
|
|
|
| 45 |
tqdm>=4.66.0,<5.0.0
|
| 46 |
|
| 47 |
# Visualization
|
|
|
|
| 7 |
# =============================================================================
|
| 8 |
|
| 9 |
# Core ML Framework
|
| 10 |
+
torch>=2.1.0,<2.11.0
|
| 11 |
torchvision>=0.16.0; platform_system != "Darwin" or platform_machine != "arm64"
|
| 12 |
|
| 13 |
# HuggingFace Ecosystem
|
| 14 |
transformers>=4.36.0,<4.45.0
|
| 15 |
datasets>=2.16.0,<3.0.0
|
| 16 |
tokenizers>=0.15.0,<0.20.0
|
| 17 |
+
sentencepiece>=0.2.0,<0.3.0
|
| 18 |
accelerate>=0.25.0,<0.35.0
|
| 19 |
|
| 20 |
# Parameter-Efficient Fine-Tuning
|
|
|
|
| 40 |
rich>=13.0.0,<14.0.0
|
| 41 |
|
| 42 |
# Data Processing
|
| 43 |
+
numpy>=1.24.0,<3.0.0
|
| 44 |
pandas>=2.0.0,<2.3.0
|
| 45 |
+
protobuf>=5.28.3,<7.0.0
|
| 46 |
tqdm>=4.66.0,<5.0.0
|
| 47 |
|
| 48 |
# Visualization
|
result/evaluation_results.json
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bleu": 15.1403,
|
| 3 |
+
"bleu_1": 43.0105,
|
| 4 |
+
"bleu_2": 20.1492,
|
| 5 |
+
"bleu_3": 10.4122,
|
| 6 |
+
"bleu_4": 5.8232,
|
| 7 |
+
"bp": 1.0,
|
| 8 |
+
"chrf": 15.2513,
|
| 9 |
+
"ter": 177.5966
|
| 10 |
+
}
|
result/final_evaluation_metrics.png
ADDED
|
result/train_loss_curve.png
ADDED
|
result/training_summary.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"best_epoch": 3,
|
| 3 |
+
"best_metric": Infinity,
|
| 4 |
+
"metric_name": "bleu",
|
| 5 |
+
"total_steps": 7630,
|
| 6 |
+
"train_loss_history": [
|
| 7 |
+
8.249846095573231,
|
| 8 |
+
6.610892885478108,
|
| 9 |
+
5.28016960105296,
|
| 10 |
+
4.47492950561006,
|
| 11 |
+
4.051334980548131
|
| 12 |
+
],
|
| 13 |
+
"val_metrics_history": [
|
| 14 |
+
{
|
| 15 |
+
"val_loss": 7.903
|
| 16 |
+
},
|
| 17 |
+
{
|
| 18 |
+
"val_loss": 6.9446
|
| 19 |
+
},
|
| 20 |
+
{
|
| 21 |
+
"val_loss": 6.0977
|
| 22 |
+
},
|
| 23 |
+
{
|
| 24 |
+
"val_loss": 5.6509
|
| 25 |
+
},
|
| 26 |
+
{
|
| 27 |
+
"val_loss": 5.4433
|
| 28 |
+
}
|
| 29 |
+
]
|
| 30 |
+
}
|
result/translation_examples.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"source_en": "Hello, how are you today?",
|
| 4 |
+
"target_zh": "今天,你如何?"
|
| 5 |
+
},
|
| 6 |
+
{
|
| 7 |
+
"source_en": "Machine translation is an important field of natural language processing.",
|
| 8 |
+
"target_zh": "生物交流是自然语言处理的重要领域。"
|
| 9 |
+
},
|
| 10 |
+
{
|
| 11 |
+
"source_en": "The weather is beautiful and I want to go for a walk.",
|
| 12 |
+
"target_zh": "天气是美丽的,我想去。"
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"source_en": "Deep learning has revolutionized artificial intelligence research.",
|
| 16 |
+
"target_zh": "深度学习推动了人工智能情报研究。"
|
| 17 |
+
}
|
| 18 |
+
]
|
setup.py
CHANGED
|
@@ -14,16 +14,17 @@ setup(
|
|
| 14 |
package_dir={"": "src"},
|
| 15 |
python_requires=">=3.10",
|
| 16 |
install_requires=[
|
| 17 |
-
"torch>=2.1.0,<2.
|
| 18 |
"transformers>=4.36.0,<4.45.0",
|
| 19 |
"datasets>=2.16.0,<3.0.0",
|
| 20 |
"tokenizers>=0.15.0,<0.20.0",
|
| 21 |
-
"sentencepiece>=0.
|
| 22 |
"accelerate>=0.25.0,<0.35.0",
|
| 23 |
"peft>=0.7.0,<0.12.0",
|
| 24 |
"sacrebleu>=2.4.0,<3.0.0",
|
| 25 |
"unbabel-comet>=2.2.0,<2.3.0",
|
| 26 |
-
"numpy>=1.24.0,<
|
|
|
|
| 27 |
"omegaconf>=2.3.0,<3.0.0",
|
| 28 |
"rich>=13.0.0,<14.0.0",
|
| 29 |
"tqdm>=4.66.0,<5.0.0",
|
|
@@ -41,11 +42,12 @@ setup(
|
|
| 41 |
"transformers>=4.36.0,<4.45.0",
|
| 42 |
"datasets>=2.16.0,<3.0.0",
|
| 43 |
"tokenizers>=0.15.0,<0.20.0",
|
| 44 |
-
"sentencepiece>=0.
|
| 45 |
"accelerate>=0.25.0,<0.35.0",
|
| 46 |
"peft>=0.7.0,<0.12.0",
|
| 47 |
"sacrebleu>=2.4.0,<3.0.0",
|
| 48 |
"unbabel-comet>=2.2.0,<2.3.0",
|
|
|
|
| 49 |
"omegaconf>=2.3.0,<3.0.0",
|
| 50 |
"rich>=13.0.0,<14.0.0",
|
| 51 |
"tqdm>=4.66.0,<5.0.0",
|
|
|
|
| 14 |
package_dir={"": "src"},
|
| 15 |
python_requires=">=3.10",
|
| 16 |
install_requires=[
|
| 17 |
+
"torch>=2.1.0,<2.11.0",
|
| 18 |
"transformers>=4.36.0,<4.45.0",
|
| 19 |
"datasets>=2.16.0,<3.0.0",
|
| 20 |
"tokenizers>=0.15.0,<0.20.0",
|
| 21 |
+
"sentencepiece>=0.2.0,<0.3.0",
|
| 22 |
"accelerate>=0.25.0,<0.35.0",
|
| 23 |
"peft>=0.7.0,<0.12.0",
|
| 24 |
"sacrebleu>=2.4.0,<3.0.0",
|
| 25 |
"unbabel-comet>=2.2.0,<2.3.0",
|
| 26 |
+
"numpy>=1.24.0,<3.0.0",
|
| 27 |
+
"protobuf>=5.28.3,<7.0.0",
|
| 28 |
"omegaconf>=2.3.0,<3.0.0",
|
| 29 |
"rich>=13.0.0,<14.0.0",
|
| 30 |
"tqdm>=4.66.0,<5.0.0",
|
|
|
|
| 42 |
"transformers>=4.36.0,<4.45.0",
|
| 43 |
"datasets>=2.16.0,<3.0.0",
|
| 44 |
"tokenizers>=0.15.0,<0.20.0",
|
| 45 |
+
"sentencepiece>=0.2.0,<0.3.0",
|
| 46 |
"accelerate>=0.25.0,<0.35.0",
|
| 47 |
"peft>=0.7.0,<0.12.0",
|
| 48 |
"sacrebleu>=2.4.0,<3.0.0",
|
| 49 |
"unbabel-comet>=2.2.0,<2.3.0",
|
| 50 |
+
"protobuf>=5.28.3,<7.0.0",
|
| 51 |
"omegaconf>=2.3.0,<3.0.0",
|
| 52 |
"rich>=13.0.0,<14.0.0",
|
| 53 |
"tqdm>=4.66.0,<5.0.0",
|
src/easytranslate/evaluation/metrics.py
CHANGED
|
@@ -21,11 +21,20 @@ import logging
|
|
| 21 |
import time
|
| 22 |
from typing import Optional
|
| 23 |
|
| 24 |
-
import sacrebleu
|
| 25 |
-
|
| 26 |
logger = logging.getLogger(__name__)
|
| 27 |
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
def compute_bleu(
|
| 30 |
hypotheses: list[str],
|
| 31 |
references: list[str],
|
|
@@ -53,7 +62,8 @@ def compute_bleu(
|
|
| 53 |
f"hypotheses and references length mismatch: "
|
| 54 |
f"{len(hypotheses)} vs {len(references)}"
|
| 55 |
)
|
| 56 |
-
|
|
|
|
| 57 |
bleu = sacrebleu.corpus_bleu(hypotheses, [references], tokenize=tokenize)
|
| 58 |
return {
|
| 59 |
"bleu": round(float(bleu.score), 4),
|
|
@@ -144,7 +154,8 @@ def compute_chrf(
|
|
| 144 |
f"hypotheses and references length mismatch: "
|
| 145 |
f"{len(hypotheses)} vs {len(references)}"
|
| 146 |
)
|
| 147 |
-
|
|
|
|
| 148 |
chrf = sacrebleu.corpus_chrf(hypotheses, [references])
|
| 149 |
return {"chrf": round(float(chrf.score), 4)}
|
| 150 |
|
|
@@ -174,7 +185,8 @@ def compute_ter(
|
|
| 174 |
f"hypotheses and references length mismatch: "
|
| 175 |
f"{len(hypotheses)} vs {len(references)}"
|
| 176 |
)
|
| 177 |
-
|
|
|
|
| 178 |
ter = sacrebleu.corpus_ter(hypotheses, [references])
|
| 179 |
return {"ter": round(float(ter.score), 4)}
|
| 180 |
|
|
|
|
| 21 |
import time
|
| 22 |
from typing import Optional
|
| 23 |
|
|
|
|
|
|
|
| 24 |
logger = logging.getLogger(__name__)
|
| 25 |
|
| 26 |
|
| 27 |
+
def _require_sacrebleu():
|
| 28 |
+
try:
|
| 29 |
+
import sacrebleu
|
| 30 |
+
except ImportError as exc:
|
| 31 |
+
raise ImportError(
|
| 32 |
+
"sacrebleu is required for BLEU/chrF/TER evaluation. "
|
| 33 |
+
"Install it with `pip install sacrebleu`."
|
| 34 |
+
) from exc
|
| 35 |
+
return sacrebleu
|
| 36 |
+
|
| 37 |
+
|
| 38 |
def compute_bleu(
|
| 39 |
hypotheses: list[str],
|
| 40 |
references: list[str],
|
|
|
|
| 62 |
f"hypotheses and references length mismatch: "
|
| 63 |
f"{len(hypotheses)} vs {len(references)}"
|
| 64 |
)
|
| 65 |
+
|
| 66 |
+
sacrebleu = _require_sacrebleu()
|
| 67 |
bleu = sacrebleu.corpus_bleu(hypotheses, [references], tokenize=tokenize)
|
| 68 |
return {
|
| 69 |
"bleu": round(float(bleu.score), 4),
|
|
|
|
| 154 |
f"hypotheses and references length mismatch: "
|
| 155 |
f"{len(hypotheses)} vs {len(references)}"
|
| 156 |
)
|
| 157 |
+
|
| 158 |
+
sacrebleu = _require_sacrebleu()
|
| 159 |
chrf = sacrebleu.corpus_chrf(hypotheses, [references])
|
| 160 |
return {"chrf": round(float(chrf.score), 4)}
|
| 161 |
|
|
|
|
| 185 |
f"hypotheses and references length mismatch: "
|
| 186 |
f"{len(hypotheses)} vs {len(references)}"
|
| 187 |
)
|
| 188 |
+
|
| 189 |
+
sacrebleu = _require_sacrebleu()
|
| 190 |
ter = sacrebleu.corpus_ter(hypotheses, [references])
|
| 191 |
return {"ter": round(float(ter.score), 4)}
|
| 192 |
|