haoranxu commited on
Commit
c1435ac
•
1 Parent(s): e45b2e8

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +22 -27
README.md CHANGED
@@ -1,38 +1,36 @@
1
  ---
2
  license: mit
3
  ---
4
- **ALMA** (**A**dvanced **L**anguage **M**odel-based tr**A**nslator) is an LLM-based translation model, which adopts a new translation model paradigm: it begins with fine-tuning on monolingual data and is further optimized using high-quality parallel data. This two-step fine-tuning process ensures strong translation performance.
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{xu2023paradigm,
11
- title={A Paradigm Shift in Machine Translation: Boosting Translation Performance of Large Language Models},
12
- author={Haoran Xu and Young Jin Kim and Amr Sharaf and Hany Hassan Awadalla},
13
- year={2023},
14
- eprint={2309.11674},
15
  archivePrefix={arXiv},
16
  primaryClass={cs.CL}
17
  }
18
  ```
 
 
19
  We release six translation models presented in the paper:
20
- - **ALMA-7B**: Full-weight Fine-tune LLaMA-2-7B on 20B monolingual tokens and then **Full-weight** fine-tune on human-written parallel data
21
- - **ALMA-7B-LoRA**: Full-weight Fine-tune LLaMA-2-7B on 20B monolingual tokens and then **LoRA** fine-tune on human-written parallel data
22
  - **ALMA-7B-R (NEW!)**: Further LoRA fine-tuning upon ALMA-7B-LoRA with contrastive preference optimization.
23
- - **ALMA-13B**: Full-weight Fine-tune LLaMA-2-7B on 12B monolingual tokens and then **Full-weight** fine-tune on human-written parallel data
24
- - **ALMA-13B-LoRA** (Our best system): Full-weight Fine-tune LLaMA-2-7B on 12B monolingual tokens and then **LoRA** fine-tune on human-written parallel data
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-Pretrain](https://huggingface.co/haoranxu/ALMA-7B-Pretrain) | [haoranxu/ALMA-7B-R](https://huggingface.co/haoranxu/ALMA-7B-R) |
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-Pretrain](https://huggingface.co/haoranxu/ALMA-13B-Pretrain) | [haoranxu/ALMA-13B-R](https://huggingface.co/haoranxu/ALMA-13B-R) |
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
- A quick start to use our best system (ALMA-13B-LoRA) for translation. An example of translating "我爱机器翻译。" into English:
 
46
  ```
47
  import torch
48
- from peft import PeftModel
49
  from transformers import AutoModelForCausalLM
50
- from transformers import LlamaTokenizer
51
 
52
  # Load base model and LoRA weights
53
- model = AutoModelForCausalLM.from_pretrained("haoranxu/ALMA-13B-Pretrain", torch_dtype=torch.float16, device_map="auto")
54
- model = PeftModel.from_pretrained(model, "haoranxu/ALMA-13B-Pretrain-LoRA")
55
- tokenizer = LlamaTokenizer.from_pretrained("haoranxu/ALMA-13B-Pretrain", padding_side='left')
56
 
57
- # Add the source setence into the prompt template
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
+ ```