h-j-han
commited on
Commit
•
e3c122a
1
Parent(s):
4d9e4f4
Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,66 @@
|
|
1 |
---
|
2 |
license: mit
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
license: mit
|
3 |
+
datasets:
|
4 |
+
- allenai/MADLAD-400
|
5 |
+
language:
|
6 |
+
- en
|
7 |
+
- ko
|
8 |
+
- el
|
9 |
+
- ru
|
10 |
+
- bg
|
11 |
+
base_model:
|
12 |
+
- meta-llama/Llama-2-7b-hf
|
13 |
---
|
14 |
+
VocADT is a solution for vocabulary adaptation using adapter modules that are trained to learn the optimal linear combination of existing embeddings while keeping the model’s weights fixed.
|
15 |
+
VocADT offers a flexible and scalable solution without requiring external resources or language constraints.
|
16 |
+
|
17 |
+
|
18 |
+
## New Vocabulary Adapted Models
|
19 |
+
Only the input/output embeddings are replaced, while all other original weights of base model remain fixed.
|
20 |
+
These are the merged version: after training the adapters, we merge the original embeddings with the adapter to generate the new embeddings.
|
21 |
+
| Name | Adapted Model | Base Model | New Vocab Size | Focused Languages |
|
22 |
+
|---|---|---|---|---|
|
23 |
+
| VocADT-Latin-Mistral | [h-j-han/Mistral-7B-VocADT-50k-Latin](https://huggingface.co/h-j-han/Mistral-7B-VocADT-50k-Latin) | [Mistral](https://huggingface.co/mistralai/Mistral-7B-v0.1) | 50k | Swahili (sw), Indonesian (id), Estonian (et), Haitian Creole (ht), English (en)|
|
24 |
+
| VocADT-Mixed-Mistral | [h-j-han/Mistral-7B-VocADT-50k-Mixed](https://huggingface.co/h-j-han/Mistral-7B-VocADT-50k-Mixed) | [Mistral](https://huggingface.co/mistralai/Mistral-7B-v0.1) | 50k | Korean (ko), Greek (el), Russian (ru), Bulgarian (bg), English (en) |
|
25 |
+
| VocADT-Cyrillic-Mistral | [h-j-han/Mistral-7B-VocADT-50k-Cyrillic](https://huggingface.co/h-j-han/Mistral-7B-VocADT-50k-Cyrillic) | [Mistral](https://huggingface.co/mistralai/Mistral-7B-v0.1) | 50k | Russian (ru), Bulgarian (bg), Ukrainian (uk), Kazakh (kk), English (en) |
|
26 |
+
|||||
|
27 |
+
| VocADT-Latin-LLama | [h-j-han/Llama2-7B-VocADT-50k-Latin](https://huggingface.co/h-j-han/Llama2-7B-VocADT-50k-Latin) | [Llama](https://huggingface.co/meta-llama/Llama-2-7b-hf) | 50k | Swahili (sw), Indonesian (id), Estonian (et), Haitian Creole (ht), English (en)|
|
28 |
+
| VocADT-Mixed-LLama | [h-j-han/Llama2-7B-VocADT-50k-Mixed](https://huggingface.co/h-j-han/Llama2-7B-VocADT-50k-Mixed) | [Llama](https://huggingface.co/meta-llama/Llama-2-7b-hf) | 50k | Korean (ko), Greek (el), Russian (ru), Bulgarian (bg), English (en) |
|
29 |
+
| VocADT-Cyrillic-LLama | [h-j-han/Llama2-7B-VocADT-50k-Cyrillic](https://huggingface.co/h-j-han/Llama2-7B-VocADT-50k-Cyrillic) | [Llama](https://huggingface.co/meta-llama/Llama-2-7b-hf) | 50k | Russian (ru), Bulgarian (bg), Ukrainian (uk), Kazakh (kk), English (en) |
|
30 |
+
|
31 |
+
|
32 |
+
## Quick Start
|
33 |
+
```python
|
34 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
35 |
+
|
36 |
+
# model_name = "meta-llama/Llama-2-7b-hf" # Base Model
|
37 |
+
model_name = "h-j-han/Llama2-7B-VocADT-50k-Mixed" # Vocabulary Adapted Model
|
38 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
39 |
+
model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto")
|
40 |
+
|
41 |
+
prefix = "\nEnglish: Hello \nKorean: 안녕하세요 \nEnglish: Thank you\nKorean: 고맙습니다\nEnglish: "
|
42 |
+
line = "I'm a student."
|
43 |
+
suffix = f"\nKorean:"
|
44 |
+
prompt = prefix + line + suffix
|
45 |
+
|
46 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
47 |
+
for item in inputs:
|
48 |
+
inputs[item] = inputs[item].cuda()
|
49 |
+
outputs = model.generate(**inputs, max_new_tokens=4)
|
50 |
+
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
51 |
+
```
|
52 |
+
|
53 |
+
## Reference
|
54 |
+
We provide code in Github repo : https://github.com/h-j-han/VocADT
|
55 |
+
Also, please find details in this paper :
|
56 |
+
```
|
57 |
+
@misc{han2024vocadt,
|
58 |
+
title={Adapters for Altering LLM Vocabularies: What Languages Benefit the Most?},
|
59 |
+
author={HyoJung Han and Akiko Eriguchi and Haoran Xu and Hieu Hoang and Marine Carpuat and Huda Khayrallah},
|
60 |
+
year={2024},
|
61 |
+
eprint={2410.09644},
|
62 |
+
archivePrefix={arXiv},
|
63 |
+
primaryClass={cs.CL},
|
64 |
+
url={https://arxiv.org/abs/2410.09644},
|
65 |
+
}
|
66 |
+
```
|