Update README.md
Browse files
README.md
CHANGED
@@ -1,38 +1,36 @@
|
|
1 |
---
|
2 |
license: mit
|
3 |
---
|
4 |
-
**ALMA
|
5 |
-
Please find more details in our [paper](https://arxiv.org/abs/2309.11674).
|
6 |
-
|
7 |
-
**[ALMA-R](https://arxiv.org/abs/2401.08417) (NEW!) is released now!** ALMA-R builds upon ALMA models, with further LoRA fine-tuning with our proposed **Contrastive Preference Optimization (CPO)** as opposed to the Supervised Fine-tuning used in ALMA. CPO fine-tuning requires our [triplet preference data](https://huggingface.co/datasets/haoranxu/ALMA-R-Preference) for preference learning. ALMA-R now can matches or even exceeds GPT-4 or WMT winners!
|
8 |
-
|
9 |
```
|
10 |
-
@misc{
|
11 |
-
title={
|
12 |
-
author={Haoran Xu and
|
13 |
-
year={
|
14 |
-
eprint={
|
15 |
archivePrefix={arXiv},
|
16 |
primaryClass={cs.CL}
|
17 |
}
|
18 |
```
|
|
|
|
|
19 |
We release six translation models presented in the paper:
|
20 |
-
-
|
21 |
-
-
|
22 |
- **ALMA-7B-R (NEW!)**: Further LoRA fine-tuning upon ALMA-7B-LoRA with contrastive preference optimization.
|
23 |
-
-
|
24 |
-
-
|
25 |
-
- **ALMA-13B-R (NEW!)**: Further LoRA fine-tuning upon ALMA-13B-LoRA with contrastive preference optimization.
|
26 |
|
27 |
Model checkpoints are released at huggingface:
|
28 |
| Models | Base Model Link | LoRA Link |
|
29 |
|:-------------:|:---------------:|:---------:|
|
30 |
| ALMA-7B | [haoranxu/ALMA-7B](https://huggingface.co/haoranxu/ALMA-7B) | - |
|
31 |
| ALMA-7B-LoRA | [haoranxu/ALMA-7B-Pretrain](https://huggingface.co/haoranxu/ALMA-7B-Pretrain) | [haoranxu/ALMA-7B-Pretrain-LoRA](https://huggingface.co/haoranxu/ALMA-7B-Pretrain-LoRA) |
|
32 |
-
| **ALMA-7B-R (NEW!)** | [haoranxu/ALMA-7B-
|
33 |
| ALMA-13B | [haoranxu/ALMA-13B](https://huggingface.co/haoranxu/ALMA-13B) | - |
|
34 |
| ALMA-13B-LoRA | [haoranxu/ALMA-13B-Pretrain](https://huggingface.co/haoranxu/ALMA-13B-Pretrain) | [haoranxu/ALMA-13B-Pretrain-LoRA](https://huggingface.co/haoranxu/ALMA-13B-Pretrain-LoRA) |
|
35 |
-
| **ALMA-13B-R (NEW!)** | [haoranxu/ALMA-13B-
|
36 |
|
37 |
**Note that `ALMA-7B-Pretrain` and `ALMA-13B-Pretrain` are NOT translation models. They only experience stage 1 monolingual fine-tuning (20B tokens for the 7B model and 12B tokens for the 13B model), and should be utilized in conjunction with their LoRA models.**
|
38 |
|
@@ -42,19 +40,18 @@ Datasets used by ALMA and ALMA-R are also released at huggingface now (NEW!)
|
|
42 |
| Human-Written Parallel Data (ALMA) | [train and validation](https://huggingface.co/datasets/haoranxu/ALMA-Human-Parallel) | [WMT'22](https://huggingface.co/datasets/haoranxu/WMT22-Test) |
|
43 |
| Triplet Preference Data | [train](https://huggingface.co/datasets/haoranxu/ALMA-R-Preference) | [WMT'22](https://huggingface.co/datasets/haoranxu/WMT22-Test) and [WMT'23](https://huggingface.co/datasets/haoranxu/WMT23-Test) |
|
44 |
|
45 |
-
|
|
|
46 |
```
|
47 |
import torch
|
48 |
-
from peft import PeftModel
|
49 |
from transformers import AutoModelForCausalLM
|
50 |
-
from transformers import
|
51 |
|
52 |
# Load base model and LoRA weights
|
53 |
-
model = AutoModelForCausalLM.from_pretrained("haoranxu/ALMA-13B-
|
54 |
-
|
55 |
-
tokenizer = LlamaTokenizer.from_pretrained("haoranxu/ALMA-13B-Pretrain", padding_side='left')
|
56 |
|
57 |
-
# Add the source
|
58 |
prompt="Translate this from Chinese to English:\nChinese: 我爱机器翻译。\nEnglish:"
|
59 |
input_ids = tokenizer(prompt, return_tensors="pt", padding=True, max_length=40, truncation=True).input_ids.cuda()
|
60 |
|
@@ -63,6 +60,4 @@ with torch.no_grad():
|
|
63 |
generated_ids = model.generate(input_ids=input_ids, num_beams=5, max_new_tokens=20, do_sample=True, temperature=0.6, top_p=0.9)
|
64 |
outputs = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)
|
65 |
print(outputs)
|
66 |
-
```
|
67 |
-
|
68 |
-
Please find more details in our [GitHub repository](https://github.com/fe1ixxu/ALMA)
|
|
|
1 |
---
|
2 |
license: mit
|
3 |
---
|
4 |
+
**[ALMA-R](https://arxiv.org/abs/2401.08417)** builds upon [ALMA models](https://arxiv.org/abs/2309.11674), with further LoRA fine-tuning with our proposed **Contrastive Preference Optimization (CPO)** as opposed to the Supervised Fine-tuning used in ALMA. CPO fine-tuning requires our [triplet preference data](https://huggingface.co/datasets/haoranxu/ALMA-R-Preference) for preference learning. ALMA-R now can matches or even exceeds GPT-4 or WMT winners!
|
|
|
|
|
|
|
|
|
5 |
```
|
6 |
+
@misc{xu2024contrastive,
|
7 |
+
title={Contrastive Preference Optimization: Pushing the Boundaries of LLM Performance in Machine Translation},
|
8 |
+
author={Haoran Xu and Amr Sharaf and Yunmo Chen and Weiting Tan and Lingfeng Shen and Benjamin Van Durme and Kenton Murray and Young Jin Kim},
|
9 |
+
year={2024},
|
10 |
+
eprint={2401.08417},
|
11 |
archivePrefix={arXiv},
|
12 |
primaryClass={cs.CL}
|
13 |
}
|
14 |
```
|
15 |
+
# Download ALMA(-R) Models and Dataset 🚀
|
16 |
+
|
17 |
We release six translation models presented in the paper:
|
18 |
+
- ALMA-7B
|
19 |
+
- ALMA-7B-LoRA
|
20 |
- **ALMA-7B-R (NEW!)**: Further LoRA fine-tuning upon ALMA-7B-LoRA with contrastive preference optimization.
|
21 |
+
- ALMA-13B
|
22 |
+
- ALMA-13B-LoRA
|
23 |
+
- **ALMA-13B-R (NEW!)**: Further LoRA fine-tuning upon ALMA-13B-LoRA with contrastive preference optimization (BEST MODEL!).
|
24 |
|
25 |
Model checkpoints are released at huggingface:
|
26 |
| Models | Base Model Link | LoRA Link |
|
27 |
|:-------------:|:---------------:|:---------:|
|
28 |
| ALMA-7B | [haoranxu/ALMA-7B](https://huggingface.co/haoranxu/ALMA-7B) | - |
|
29 |
| ALMA-7B-LoRA | [haoranxu/ALMA-7B-Pretrain](https://huggingface.co/haoranxu/ALMA-7B-Pretrain) | [haoranxu/ALMA-7B-Pretrain-LoRA](https://huggingface.co/haoranxu/ALMA-7B-Pretrain-LoRA) |
|
30 |
+
| **ALMA-7B-R (NEW!)** | [haoranxu/ALMA-7B-R (LoRA merged)](https://huggingface.co/haoranxu/ALMA-7B-R) | - |
|
31 |
| ALMA-13B | [haoranxu/ALMA-13B](https://huggingface.co/haoranxu/ALMA-13B) | - |
|
32 |
| ALMA-13B-LoRA | [haoranxu/ALMA-13B-Pretrain](https://huggingface.co/haoranxu/ALMA-13B-Pretrain) | [haoranxu/ALMA-13B-Pretrain-LoRA](https://huggingface.co/haoranxu/ALMA-13B-Pretrain-LoRA) |
|
33 |
+
| **ALMA-13B-R (NEW!)** | [haoranxu/ALMA-13B-R (LoRA merged)](https://huggingface.co/haoranxu/ALMA-13B-R) | - |
|
34 |
|
35 |
**Note that `ALMA-7B-Pretrain` and `ALMA-13B-Pretrain` are NOT translation models. They only experience stage 1 monolingual fine-tuning (20B tokens for the 7B model and 12B tokens for the 13B model), and should be utilized in conjunction with their LoRA models.**
|
36 |
|
|
|
40 |
| Human-Written Parallel Data (ALMA) | [train and validation](https://huggingface.co/datasets/haoranxu/ALMA-Human-Parallel) | [WMT'22](https://huggingface.co/datasets/haoranxu/WMT22-Test) |
|
41 |
| Triplet Preference Data | [train](https://huggingface.co/datasets/haoranxu/ALMA-R-Preference) | [WMT'22](https://huggingface.co/datasets/haoranxu/WMT22-Test) and [WMT'23](https://huggingface.co/datasets/haoranxu/WMT23-Test) |
|
42 |
|
43 |
+
|
44 |
+
A quick start to use our best system (ALMA-13B-R) for translation. An example of translating "我爱机器翻译。" into English:
|
45 |
```
|
46 |
import torch
|
|
|
47 |
from transformers import AutoModelForCausalLM
|
48 |
+
from transformers import AutoTokenizer
|
49 |
|
50 |
# Load base model and LoRA weights
|
51 |
+
model = AutoModelForCausalLM.from_pretrained("haoranxu/ALMA-13B-R", torch_dtype=torch.float16, device_map="auto")
|
52 |
+
tokenizer = AutoTokenizer.from_pretrained("haoranxu/ALMA-13B-R", padding_side='left')
|
|
|
53 |
|
54 |
+
# Add the source sentence into the prompt template
|
55 |
prompt="Translate this from Chinese to English:\nChinese: 我爱机器翻译。\nEnglish:"
|
56 |
input_ids = tokenizer(prompt, return_tensors="pt", padding=True, max_length=40, truncation=True).input_ids.cuda()
|
57 |
|
|
|
60 |
generated_ids = model.generate(input_ids=input_ids, num_beams=5, max_new_tokens=20, do_sample=True, temperature=0.6, top_p=0.9)
|
61 |
outputs = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)
|
62 |
print(outputs)
|
63 |
+
```
|
|
|
|