Duplicate from facebook/xglm-7.5B
Browse filesCo-authored-by: Suraj Patil <[email protected]>
- .gitattributes +27 -0
- README.md +174 -0
- config.json +25 -0
- generation_config.json +8 -0
- pytorch_model.bin +3 -0
- sentencepiece.bpe.model +3 -0
- special_tokens_map.json +1 -0
- tokenizer.json +0 -0
- tokenizer_config.json +1 -0
.gitattributes
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bin.* filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
20 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
26 |
+
*.zstandard filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,174 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language:
|
3 |
+
- multilingual
|
4 |
+
- en
|
5 |
+
- ru
|
6 |
+
- zh
|
7 |
+
- de
|
8 |
+
- es
|
9 |
+
- fr
|
10 |
+
- ja
|
11 |
+
- it
|
12 |
+
- pt
|
13 |
+
- el
|
14 |
+
- ko
|
15 |
+
- fi
|
16 |
+
- id
|
17 |
+
- tr
|
18 |
+
- ar
|
19 |
+
- vi
|
20 |
+
- th
|
21 |
+
- bg
|
22 |
+
- ca
|
23 |
+
- hi
|
24 |
+
- et
|
25 |
+
- bn
|
26 |
+
- ta
|
27 |
+
- ur
|
28 |
+
- sw
|
29 |
+
- te
|
30 |
+
- eu
|
31 |
+
- my
|
32 |
+
- ht
|
33 |
+
- qu
|
34 |
+
license: mit
|
35 |
+
thumbnail: https://huggingface.co/front/thumbnails/facebook.png
|
36 |
+
inference: false
|
37 |
+
---
|
38 |
+
|
39 |
+
# XGLM-7.5B
|
40 |
+
|
41 |
+
XGLM-7.5B is a multilingual autoregressive language model (with 7.5 billion parameters) trained on a balanced corpus of a diverse set of languages totaling 500 billion sub-tokens. It was introduced in the paper [Few-shot Learning with Multilingual Language Models](https://arxiv.org/abs/2112.10668) by Xi Victoria Lin\*, Todor Mihaylov, Mikel Artetxe, Tianlu Wang, Shuohui Chen, Daniel Simig, Myle Ott, Naman Goyal, Shruti Bhosale, Jingfei Du, Ramakanth Pasunuru, Sam Shleifer, Punit Singh Koura, Vishrav Chaudhary, Brian O'Horo, Jeff Wang, Luke Zettlemoyer, Zornitsa Kozareva, Mona Diab, Veselin Stoyanov, Xian Li\* (\*Equal Contribution). The original implementation was released in [this repository](https://github.com/pytorch/fairseq/tree/main/examples/xglm).
|
42 |
+
|
43 |
+
## Training Data Statistics
|
44 |
+
|
45 |
+
The training data statistics of XGLM-7.5B is shown in the table below.
|
46 |
+
|
47 |
+
| ISO-639-1| family | name | # tokens | ratio | ratio w/ lowRes upsampling |
|
48 |
+
|:--------|:-----------------|:------------------------|-------------:|------------:|-------------:|
|
49 |
+
| en | Indo-European | English | 803526736124 | 0.489906 | 0.3259 |
|
50 |
+
| ru | Indo-European | Russian | 147791898098 | 0.0901079 | 0.0602 |
|
51 |
+
| zh | Sino-Tibetan | Chinese | 132770494630 | 0.0809494 | 0.0483 |
|
52 |
+
| de | Indo-European | German | 89223707856 | 0.0543992 | 0.0363 |
|
53 |
+
| es | Indo-European | Spanish | 87303083105 | 0.0532282 | 0.0353 |
|
54 |
+
| fr | Indo-European | French | 77419639775 | 0.0472023 | 0.0313 |
|
55 |
+
| ja | Japonic | Japanese | 66054364513 | 0.040273 | 0.0269 |
|
56 |
+
| it | Indo-European | Italian | 41930465338 | 0.0255648 | 0.0171 |
|
57 |
+
| pt | Indo-European | Portuguese | 36586032444 | 0.0223063 | 0.0297 |
|
58 |
+
| el | Indo-European | Greek (modern) | 28762166159 | 0.0175361 | 0.0233 |
|
59 |
+
| ko | Koreanic | Korean | 20002244535 | 0.0121953 | 0.0811 |
|
60 |
+
| fi | Uralic | Finnish | 16804309722 | 0.0102455 | 0.0681 |
|
61 |
+
| id | Austronesian | Indonesian | 15423541953 | 0.00940365 | 0.0125 |
|
62 |
+
| tr | Turkic | Turkish | 12413166065 | 0.00756824 | 0.0101 |
|
63 |
+
| ar | Afro-Asiatic | Arabic | 12248607345 | 0.00746791 | 0.0099 |
|
64 |
+
| vi | Austroasiatic | Vietnamese | 11199121869 | 0.00682804 | 0.0091 |
|
65 |
+
| th | Tai–Kadai | Thai | 10842172807 | 0.00661041 | 0.044 |
|
66 |
+
| bg | Indo-European | Bulgarian | 9703797869 | 0.00591635 | 0.0393 |
|
67 |
+
| ca | Indo-European | Catalan | 7075834775 | 0.0043141 | 0.0287 |
|
68 |
+
| hi | Indo-European | Hindi | 3448390110 | 0.00210246 | 0.014 |
|
69 |
+
| et | Uralic | Estonian | 3286873851 | 0.00200399 | 0.0133 |
|
70 |
+
| bn | Indo-European | Bengali, Bangla | 1627447450 | 0.000992245 | 0.0066 |
|
71 |
+
| ta | Dravidian | Tamil | 1476973397 | 0.000900502 | 0.006 |
|
72 |
+
| ur | Indo-European | Urdu | 1351891969 | 0.000824241 | 0.0055 |
|
73 |
+
| sw | Niger–Congo | Swahili | 907516139 | 0.000553307 | 0.0037 |
|
74 |
+
| te | Dravidian | Telugu | 689316485 | 0.000420272 | 0.0028 |
|
75 |
+
| eu | Language isolate | Basque | 105304423 | 6.42035e-05 | 0.0043 |
|
76 |
+
| my | Sino-Tibetan | Burmese | 101358331 | 6.17976e-05 | 0.003 |
|
77 |
+
| ht | Creole | Haitian, Haitian Creole | 86584697 | 5.27902e-05 | 0.0035 |
|
78 |
+
| qu | Quechuan | Quechua | 3236108 | 1.97304e-06 | 0.0001 |
|
79 |
+
|
80 |
+
## Model card
|
81 |
+
|
82 |
+
For intended usage of the model, please refer to the [model card](https://github.com/pytorch/fairseq/blob/main/examples/xglm/model_card.md) released by the XGLM-7.5B development team.
|
83 |
+
|
84 |
+
## Example (COPA)
|
85 |
+
The following snippet shows how to evaluate our models (GPT-3 style, zero-shot) on the Choice of Plausible Alternatives (COPA) task, using examples in English, Chinese and Hindi.
|
86 |
+
|
87 |
+
```python
|
88 |
+
import torch
|
89 |
+
import torch.nn.functional as F
|
90 |
+
|
91 |
+
from transformers import XGLMTokenizer, XGLMForCausalLM
|
92 |
+
|
93 |
+
tokenizer = XGLMTokenizer.from_pretrained("facebook/xglm-7.5B")
|
94 |
+
model = XGLMForCausalLM.from_pretrained("facebook/xglm-7.5B")
|
95 |
+
|
96 |
+
data_samples = {
|
97 |
+
'en': [
|
98 |
+
{
|
99 |
+
"premise": "I wanted to conserve energy.",
|
100 |
+
"choice1": "I swept the floor in the unoccupied room.",
|
101 |
+
"choice2": "I shut off the light in the unoccupied room.",
|
102 |
+
"question": "effect",
|
103 |
+
"label": "1"
|
104 |
+
},
|
105 |
+
{
|
106 |
+
"premise": "The flame on the candle went out.",
|
107 |
+
"choice1": "I blew on the wick.",
|
108 |
+
"choice2": "I put a match to the wick.",
|
109 |
+
"question": "cause",
|
110 |
+
"label": "0"
|
111 |
+
}
|
112 |
+
],
|
113 |
+
'zh': [
|
114 |
+
{
|
115 |
+
"premise": "我想节约能源。",
|
116 |
+
"choice1": "我在空着的房间里扫了地板。",
|
117 |
+
"choice2": "我把空房间里的灯关了。",
|
118 |
+
"question": "effect",
|
119 |
+
"label": "1"
|
120 |
+
},
|
121 |
+
{
|
122 |
+
"premise": "蜡烛上的火焰熄灭了。",
|
123 |
+
"choice1": "我吹灭了灯芯。",
|
124 |
+
"choice2": "我把一根火柴放在灯芯上。",
|
125 |
+
"question": "cause",
|
126 |
+
"label": "0"
|
127 |
+
}
|
128 |
+
],
|
129 |
+
'hi': [
|
130 |
+
{
|
131 |
+
"premise": "M te vle konsève enèji.",
|
132 |
+
"choice1": "Mwen te fin baleye chanm lib la.",
|
133 |
+
"choice2": "Mwen te femen limyè nan chanm lib la.",
|
134 |
+
"question": "effect",
|
135 |
+
"label": "1"
|
136 |
+
},
|
137 |
+
{
|
138 |
+
"premise": "Flam bouji a te etenn.",
|
139 |
+
"choice1": "Mwen te soufle bouji a.",
|
140 |
+
"choice2": "Mwen te limen mèch bouji a.",
|
141 |
+
"question": "cause",
|
142 |
+
"label": "0"
|
143 |
+
}
|
144 |
+
]
|
145 |
+
}
|
146 |
+
|
147 |
+
def get_logprobs(prompt):
|
148 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
149 |
+
input_ids, output_ids = inputs["input_ids"], inputs["input_ids"][:, 1:]
|
150 |
+
outputs = model(**inputs, labels=input_ids)
|
151 |
+
logits = outputs.logits
|
152 |
+
logprobs = torch.gather(F.log_softmax(logits, dim=2), 2, output_ids.unsqueeze(2))
|
153 |
+
return logprobs
|
154 |
+
|
155 |
+
# Zero-shot evaluation for the Choice of Plausible Alternatives (COPA) task.
|
156 |
+
# A return value of 0 indicates that the first alternative is more plausible,
|
157 |
+
# while 1 indicates that the second alternative is more plausible.
|
158 |
+
def COPA_eval(prompt, alternative1, alternative2):
|
159 |
+
lprob1 = get_logprobs(prompt + "\n" + alternative1).sum()
|
160 |
+
lprob2 = get_logprobs(prompt + "\n" + alternative2).sum()
|
161 |
+
return 0 if lprob1 > lprob2 else 1
|
162 |
+
|
163 |
+
for lang in data_samples_long:
|
164 |
+
for idx, example in enumerate(data_samples_long[lang]):
|
165 |
+
predict = COPA_eval(example["premise"], example["choice1"], example["choice2"])
|
166 |
+
print(f'{lang}-{idx}', predict, example['label'])
|
167 |
+
|
168 |
+
# en-0 1 1
|
169 |
+
# en-1 0 0
|
170 |
+
# zh-0 1 1
|
171 |
+
# zh-1 0 0
|
172 |
+
# hi-0 1 1
|
173 |
+
# hi-1 0 0
|
174 |
+
```
|
config.json
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"activation_dropout": 0.0,
|
3 |
+
"activation_function": "gelu",
|
4 |
+
"architectures": [
|
5 |
+
"XGLMForCausalLM"
|
6 |
+
],
|
7 |
+
"attention_dropout": 0.1,
|
8 |
+
"attention_heads": 32,
|
9 |
+
"bos_token_id": 0,
|
10 |
+
"d_model": 4096,
|
11 |
+
"decoder_start_token_id": 2,
|
12 |
+
"dropout": 0.1,
|
13 |
+
"eos_token_id": 2,
|
14 |
+
"ffn_dim": 16384,
|
15 |
+
"init_std": 0.02,
|
16 |
+
"layerdrop": 0.0,
|
17 |
+
"max_position_embeddings": 2048,
|
18 |
+
"model_type": "xglm",
|
19 |
+
"num_layers": 32,
|
20 |
+
"pad_token_id": 1,
|
21 |
+
"scale_embedding": true,
|
22 |
+
"transformers_version": "4.16.0.dev0",
|
23 |
+
"use_cache": true,
|
24 |
+
"vocab_size": 256008
|
25 |
+
}
|
generation_config.json
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_from_model_config": true,
|
3 |
+
"bos_token_id": 0,
|
4 |
+
"decoder_start_token_id": 2,
|
5 |
+
"eos_token_id": 2,
|
6 |
+
"pad_token_id": 1,
|
7 |
+
"transformers_version": "4.27.0.dev0"
|
8 |
+
}
|
pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e20979b9115b9c744b4a57a26f2662197cac95d0d0ae01e0487ab079e796d50f
|
3 |
+
size 14985725891
|
sentencepiece.bpe.model
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c49dc7e82c10227af764e518924cf2f9d50c00462750d184fa74697bba65eef8
|
3 |
+
size 4920706
|
special_tokens_map.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"bos_token": "<s>", "eos_token": "</s>", "unk_token": "<unk>", "sep_token": "</s>", "pad_token": "<pad>", "cls_token": "<s>", "additional_special_tokens": ["<madeupword0>", "<madeupword1>", "<madeupword2>", "<madeupword3>", "<madeupword4>", "<madeupword5>", "<madeupword6>"]}
|
tokenizer.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
tokenizer_config.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"bos_token": "<s>", "eos_token": "</s>", "sep_token": "</s>", "cls_token": "<s>", "unk_token": "<unk>", "pad_token": "<pad>", "sp_model_kwargs": {}, "special_tokens_map_file": "hf_models/xglm-564M/special_tokens_map.json", "additional_special_tokens": ["<madeupword0>", "<madeupword1>", "<madeupword2>", "<madeupword3>", "<madeupword4>", "<madeupword5>", "<madeupword6>"], "name_or_path": "hf_models/xglm-564M/", "tokenizer_class": "XGLMTokenizer"}
|