RichardErkhov commited on
Commit
c62f833
1 Parent(s): 1d84375

uploaded readme

Browse files
Files changed (1) hide show
  1. README.md +155 -0
README.md ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Quantization made by Richard Erkhov.
2
+
3
+ [Github](https://github.com/RichardErkhov)
4
+
5
+ [Discord](https://discord.gg/pvy7H8DZMG)
6
+
7
+ [Request more models](https://github.com/RichardErkhov/quant_request)
8
+
9
+
10
+ xglm-4.5B - bnb 8bits
11
+ - Model creator: https://huggingface.co/facebook/
12
+ - Original model: https://huggingface.co/facebook/xglm-4.5B/
13
+
14
+
15
+
16
+
17
+ Original model description:
18
+ ---
19
+ language:
20
+ - multilingual
21
+ - en
22
+ - ru
23
+ - zh
24
+ - de
25
+ - es
26
+ - fr
27
+ - ja
28
+ - it
29
+ - pt
30
+ - el
31
+ - ko
32
+ - fi
33
+ - id
34
+ - tr
35
+ - ar
36
+ - vi
37
+ - th
38
+ - bg
39
+ - ca
40
+ - hi
41
+ - et
42
+ - bn
43
+ - ta
44
+ - ur
45
+ - sw
46
+ - te
47
+ - eu
48
+ - my
49
+ - ht
50
+ - qu
51
+ license: mit
52
+ thumbnail: https://huggingface.co/front/thumbnails/facebook.png
53
+ inference: false
54
+ ---
55
+
56
+ # XGLM-4.5B
57
+
58
+ XGLM-4.5B is a multilingual autoregressive language model (with 4.5 billion parameters) trained on a balanced corpus of a diverse set of 134 languages. 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).
59
+
60
+ ## Model card
61
+
62
+ 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-4.5B development team.
63
+
64
+ ## Example (COPA)
65
+ 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.
66
+
67
+ ```python
68
+ import torch
69
+ import torch.nn.functional as F
70
+
71
+ from transformers import XGLMTokenizer, XGLMForCausalLM
72
+
73
+ tokenizer = XGLMTokenizer.from_pretrained("facebook/xglm-4.5B")
74
+ model = XGLMForCausalLM.from_pretrained("facebook/xglm-4.5B")
75
+
76
+ data_samples = {
77
+ 'en': [
78
+ {
79
+ "premise": "I wanted to conserve energy.",
80
+ "choice1": "I swept the floor in the unoccupied room.",
81
+ "choice2": "I shut off the light in the unoccupied room.",
82
+ "question": "effect",
83
+ "label": "1"
84
+ },
85
+ {
86
+ "premise": "The flame on the candle went out.",
87
+ "choice1": "I blew on the wick.",
88
+ "choice2": "I put a match to the wick.",
89
+ "question": "cause",
90
+ "label": "0"
91
+ }
92
+ ],
93
+ 'zh': [
94
+ {
95
+ "premise": "我想节约能源。",
96
+ "choice1": "我在空着的房间里扫了地板。",
97
+ "choice2": "我把空房间里的灯关了。",
98
+ "question": "effect",
99
+ "label": "1"
100
+ },
101
+ {
102
+ "premise": "蜡烛上的火焰熄灭了。",
103
+ "choice1": "我吹灭了灯芯。",
104
+ "choice2": "我把一根火柴放在灯芯上。",
105
+ "question": "cause",
106
+ "label": "0"
107
+ }
108
+ ],
109
+ 'hi': [
110
+ {
111
+ "premise": "M te vle konsève enèji.",
112
+ "choice1": "Mwen te fin baleye chanm lib la.",
113
+ "choice2": "Mwen te femen limyè nan chanm lib la.",
114
+ "question": "effect",
115
+ "label": "1"
116
+ },
117
+ {
118
+ "premise": "Flam bouji a te etenn.",
119
+ "choice1": "Mwen te soufle bouji a.",
120
+ "choice2": "Mwen te limen mèch bouji a.",
121
+ "question": "cause",
122
+ "label": "0"
123
+ }
124
+ ]
125
+ }
126
+
127
+ def get_logprobs(prompt):
128
+ inputs = tokenizer(prompt, return_tensors="pt")
129
+ input_ids, output_ids = inputs["input_ids"], inputs["input_ids"][:, 1:]
130
+ outputs = model(**inputs, labels=input_ids)
131
+ logits = outputs.logits
132
+ logprobs = torch.gather(F.log_softmax(logits, dim=2), 2, output_ids.unsqueeze(2))
133
+ return logprobs
134
+
135
+ # Zero-shot evaluation for the Choice of Plausible Alternatives (COPA) task.
136
+ # A return value of 0 indicates that the first alternative is more plausible,
137
+ # while 1 indicates that the second alternative is more plausible.
138
+ def COPA_eval(prompt, alternative1, alternative2):
139
+ lprob1 = get_logprobs(prompt + "\n" + alternative1).sum()
140
+ lprob2 = get_logprobs(prompt + "\n" + alternative2).sum()
141
+ return 0 if lprob1 > lprob2 else 1
142
+
143
+ for lang in data_samples_long:
144
+ for idx, example in enumerate(data_samples_long[lang]):
145
+ predict = COPA_eval(example["premise"], example["choice1"], example["choice2"])
146
+ print(f'{lang}-{idx}', predict, example['label'])
147
+
148
+ # en-0 1 1
149
+ # en-1 0 0
150
+ # zh-0 1 1
151
+ # zh-1 0 0
152
+ # hi-0 1 1
153
+ # hi-1 0 0
154
+ ```
155
+