davda54 commited on
Commit
aca8cfd
1 Parent(s): 4fa652a

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +301 -0
README.md CHANGED
@@ -1,3 +1,304 @@
1
  ---
 
 
 
 
 
 
 
 
 
2
  license: cc-by-4.0
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ language:
3
+ - 'no'
4
+ - nb
5
+ - nn
6
+ inference: true
7
+ tags:
8
+ - mistral
9
+ - gpt
10
+ - generative
11
  license: cc-by-4.0
12
+ pipeline_tag: text-generation
13
+ datasets:
14
+ - uonlp/CulturaX
15
+ - NbAiLab/NCC
16
+ - vikp/starcoder_filtered
17
  ---
18
+
19
+ # **NorMistral-7b-scratch**
20
+
21
+ <img align="center" src="https://huggingface.co/ltg/norbert3-base/resolve/main/norbert.png" width=12.5%>
22
+
23
+ NorMistral-7b-scratch is a large Norwegian language model pretrained from scratch on a total of 260 billion tokens (using six repetitions of open Norwegian texts).
24
+
25
+ This model is a part of the NORA-LLM family developed in collaboration between [the Language Technology Group at the University of Oslo](https://huggingface.co/ltg), [the High Performance Language Technologies (HPLT) project team](https://hplt-project.org/), [the National Library of Norway](https://huggingface.co/NbAiLab), and [the University of Turku](https://huggingface.co/TurkuNLP).
26
+ All the models are pre-trained on the same dataset and with the same tokenizer.
27
+ NorMistral-7b-scratch has over 7 billion parameters and is based on [the Mistral architecture](https://huggingface.co/mistralai/Mistral-7B-v0.1).
28
+
29
+ The NORA-LLM language model family includes (as of now):
30
+ - [**NorMistral-7b-warm**](https://huggingface.co/norallm/normistral-7b-warm) -- an LLM initialized from [Mistral-7b-v0.1](https://huggingface.co/mistralai/Mistral-7B-v0.1) and continuously pretrained on Norwegian data;
31
+ - [**NorMistral-7b-scratch**](https://huggingface.co/norallm/normistral-7b-scratch) -- a Mistral-based LLM pretrained from scratch on Norwegian data;
32
+ - [**NorBLOOM-7b-scratch**](https://huggingface.co/norallm/NorBLOOM-7b-scratch) -- a BLOOM-based LLM pretrained from scratch on Norwegian data.
33
+
34
+
35
+ *Disclaimer: This model is pretrained on raw (mostly web-based) textual data.
36
+ It is not finetuned to follow instructions, and it can generate harmful completions after inappropriate user prompts.
37
+ It is primarily intended for research purposes.*
38
+
39
+ _____
40
+ ## Pretraining corpus
41
+
42
+ The model is pretrained exclusively on publicly available data. We combine the resources from [the public part of the NCC corpus](https://huggingface.co/datasets/NbAiLab/NCC), from [the cleaned HPLT corpus](https://hplt-project.org/datasets/v1.2), and from [CulturaX](https://huggingface.co/datasets/uonlp/CulturaX).
43
+ This resulted in over 34B tokens of Norwegian (Bokmål or Nynorsk) in total.
44
+ We also augment the corpus with [Starcoder](https://huggingface.co/datasets/vikp/starcoder_filtered); 20% of the 260B tokens are sampled from this code corpus.
45
+ The Norwegian data is repeated six times to get the pretraining budget of 260B tokens, in accordance with findings from [Muennighoff et al. (2023)](https://neurips.cc/virtual/2023/poster/70706).
46
+
47
+
48
+
49
+ _____
50
+ ## Model details
51
+
52
+ **Model Developers:** Language Technology Group at the University of Oslo.
53
+
54
+ **Variations:** NorMistral is currently published as two 7B variants: one trained entirely from *scratch* and one *warm*-started from the Mistral model.
55
+
56
+ **Input:** Textual input.
57
+
58
+ **Output:** Generated text.
59
+
60
+ **Model Architecture:** NorMistral is an auto-regressive language model that uses an optimized transformer architecture based on the Mistral/Llama language models.
61
+
62
+ ||Training Data|Params|Context Length|Tokens|LR|
63
+ |---|---|---|---|---|---|
64
+ |NorMistral-7b-warm|NCC+HPLT+CulturaX+Starcoder|7B|2k|260B|1.0 x 10<sup>-4</sup>|
65
+ |NorMistral-7b-scratch|NCC+HPLT+CulturaX+Starcoder|7B|2k|260B|3.0 x 10<sup>-4</sup>|
66
+ |NorBLOOM-7b-scratch|NCC+HPLT+CulturaX+Starcoder|7B|2k|260B|1.2 x 10<sup>-4</sup>|
67
+
68
+ **Tokenizer:** Byte-based BPE tokenizer trained on the same Norwegian corpus as this model. The vocabulary size is 32,768 tokens.
69
+
70
+ **Training FLOPs** The approximate amount is 1.22e+22 FLOPs; calculated as in [Chowdhery et al. (2022)](https://arxiv.org/abs/2204.02311).
71
+
72
+ **Model Dates:** The models were pretrained between December 2023 and January 2024.
73
+
74
+ **Status:** These are only pretrained language models; instruction-finetuned models will follow soon.
75
+
76
+ **License:** Creative Commons Attribution 4.0
77
+
78
+ **Research Paper:** Forthcoming
79
+
80
+ _____
81
+ ## Initial evaluation
82
+
83
+ *Disclaimer: our model evaluation is an ongoing phase and is not claimed to be exhaustive. We provide our initial evaluation results on standard natural language understanding and generation tasks, and our evaluation design will be extended.
84
+ The user should perform evaluation for their particular model application scenario, including safety and bias evaluations.*
85
+
86
+ The perplexity on the heldout [validation set from the Norwegian Colossal Corpus (NCC)](https://huggingface.co/datasets/NbAiLab/NCC) is 6.58 and the final training perplexity is 3.95.
87
+
88
+ Our initial downstream evaluation is conducted on reading comprehension, sentiment analysis and machine translation tasks using open-source peer-reviewed datasets and benchmarks in native Norwegian.
89
+ We release [our codebase here](https://github.com/ltgoslo/norallm). We compare against other pretrained generative language models that officially support Norwegian: [NB-GPT-J](https://huggingface.co/NbAiLab/nb-gpt-j-6B), [GPT-Sw3 6.7B](https://huggingface.co/AI-Sweden-Models/gpt-sw3-6.7b), [GPT-Sw3 6.7B v2](https://huggingface.co/AI-Sweden-Models/gpt-sw3-6.7b-v2), and [Falcon-7B](https://huggingface.co/tiiuae/falcon-7b).
90
+
91
+
92
+ ### Reading comprehension
93
+
94
+ [NorQuAD](https://huggingface.co/datasets/ltg/norquad) ([Ivanova et al., 2023](https://aclanthology.org/2023.nodalida-1.17/)) is a dataset for extractive question answering in Norwegian designed similarly to [SQuAD (Rajpurkar et al., 2016)](https://aclanthology.org/D16-1264/).
95
+
96
+ <details>
97
+ <summary>Method</summary>
98
+
99
+ * Evaluation setting: zero-shot and few-shot settings via natural language generation using the greedy decoding strategy.
100
+ * Prompt: ```"Tittel: {title}\n\nTekst: {text}\n\nSpørsmål: {question}\n\nSvar:{answer}"```
101
+ * Few-shot results show the average scores across 5 repetitions
102
+ * Evaluation script: https://github.com/ltgoslo/norallm/blob/main/initial_evaluation/norquad.py
103
+ * Performance metrics: macro-averaged F1-score and exact match (EM).
104
+
105
+ </details>
106
+
107
+ <details open>
108
+ <summary>Performance results on the extractive question answering task (NorQuAD)</summary>
109
+
110
+ |Model|0-shot (F1/EM)|1-shot (F1/EM)|2-shot (F1/EM)|
111
+ |---|---|---|---|
112
+ |NorMistral-7b-warm|**48.6**/**24.8**|**63.6**/**40.0**|**66.5**/43.8|
113
+ |NorMistral-7b-scratch|34.0/15.7|46.5/25.8|48.5/27.8|
114
+ |NorBLOOM-7b|35.0/13.3|47.7/28.0|49.3/30.1|
115
+ |NB-GPT-J|24.4/6.8|32.8/11.6|35.0/12.3|
116
+ |Falcon-7B|15.8/7.0|27.3/13.9|27.4/13.1|
117
+ |GPT-Sw3-6.7B|46.5/22.0|55.9/32.0|58.1/34.3|
118
+ |GPT-Sw3-6.7B-v2|46.9/22.5|61.1/38.9|66.0/**44.5**|
119
+
120
+ </details>
121
+
122
+
123
+ ### Sentiment analysis
124
+
125
+ [NoReC](https://huggingface.co/datasets/ltg/norec_sentence) ([Øvrelid et al., 2020](https://aclanthology.org/2020.lrec-1.618/)) is a dataset for sentence-level sentiment analysis derived from the Norwegian Review Corpus [(Veldall et al., 2018)](https://aclanthology.org/L18-1661/).
126
+ We use the binary formulation of this task (positive vs. negative).
127
+
128
+ <details>
129
+ <summary>Method</summary>
130
+
131
+ * Evaluation setting: zero-shot and few-shot perplexity-based evaluation.
132
+ * Prompt: ```"Tekst: {text}\nSentiment:{label}"```, where the ```label``` is either "positiv" or "negativ".
133
+ * Few-shot results show the average scores across 5 repetitions
134
+ * Evaluation script: https://github.com/ltgoslo/norallm/blob/main/initial_evaluation/sentiment_analysis.py
135
+ * Performance metric: macro-averaged F1-score.
136
+
137
+ </details>
138
+
139
+ <details open>
140
+ <summary>Macro-averaged F1-scores on the sentence-level sentiment analysis task (NoReC)</summary>
141
+
142
+ |Model|0-shot (macro F1)|1-shot (macro F1)|16-shot (macro F1)|
143
+ |---|---|---|---|
144
+ |NorMistral-7b-warm|60.6|**77.8**|**87.3**|
145
+ |NorMistral-7b-scratch|47.3|62.2|80.1|
146
+ |NorBLOOM-7b|**75.7**|73.8|65.5|
147
+ |NB-GPT-J|48.4|56.5|65.2|
148
+ |Falcon-7B|53.3|61.6|74.9|
149
+ |GPT-Sw3-6.7B|61.5|72.2|76.5|
150
+ |GPT-Sw3-6.7B-v2|42.4|69.1|83.4|
151
+
152
+ </details>
153
+
154
+ ### Machine translation
155
+
156
+ [Tatoeba](https://huggingface.co/datasets/Helsinki-NLP/tatoeba_mt) [(Tiedemann, 2020)](https://aclanthology.org/2020.wmt-1.139/) is a benchmark for machine translation, which includes hundreds of language pairs. We consider six language pairs (English <-> Bokmål, English <-> Nynorsk, and Bokmål <-> Nynorsk).
157
+
158
+ <details>
159
+ <summary>Method</summary>
160
+
161
+ * Evaluation setting: zero-shot and few-shot settings via natural language generation using the greedy decoding strategy.
162
+ * Prompt: ```"{source_language}: {source_text}\n{target_language}:{target_text}"```, where the ```source_language``` and ```target_language``` are ```Engelsk```, ```Bokmål```, or ```Nynorsk```.
163
+ * Few-shot results show the average scores across 5 repetitions
164
+ * Evaluation script: https://github.com/ltgoslo/norallm/blob/main/initial_evaluation/machine_translation.py
165
+ * Performance metrics: BLEU ([Papineni et al., 2002](https://aclanthology.org/P02-1040/)) and chrF++ ([Popović, 2015](https://aclanthology.org/W15-3049/)).
166
+
167
+ </details>
168
+
169
+ <details open>
170
+ <summary>English → Norwegian Bokmål</summary>
171
+
172
+ |Model|0-shot (BLEU/chrF++)|1-shot (BLEU/chrF++)|5-shot (BLEU/chrF++)|
173
+ |---|---|---|---|
174
+ |NorMistral-7b-warm|**55.8**/**70.7**|**56.7**/**71.5**|57.7/72.4|
175
+ |NorMistral-7b-scratch|46.4/62.9|50.4/66.3|52.1/67.6|
176
+ |NorBLOOM-7b|37.1/53.6|50.1/65.8|52.0/67.6|
177
+ |NB-GPT-J|8.6/39.1|35.9/64.5|47.2/68.7|
178
+ |Falcon-7B|19.1/40.1|20.6/41.8|22.1/43.6|
179
+ |GPT-Sw3-6.7B|21.8/55.2|54.5/69.6|**58.6**/**73.2**|
180
+ |GPT-Sw3-6.7B-v2|20.6/53.2|51.2/66.6|58.4/73.0|
181
+
182
+ </details>
183
+
184
+ <details open>
185
+ <summary>English → Norwegian Nynorsk</summary>
186
+
187
+ |Model|0-shot (BLEU/chrF++)|1-shot (BLEU/chrF++)|5-shot (BLEU/chrF++)|
188
+ |---|---|---|---|
189
+ |NorMistral-7b-warm|**43.6**/**62.0**|**44.2**/**63.2**|44.3/**63.7**|
190
+ |NorMistral-7b-scratch|38.0/56.9|39.2/57.9|40.7/59.3|
191
+ |NorBLOOM-7b|35.6/54.7|36.6/56.3|38.1/57.4|
192
+ |NB-GPT-J|1.7/14.7|6.3/34.1|35.2/60.4|
193
+ |Falcon-7B|6.4/28.6|8.3/30.5|9.3/32.1|
194
+ |GPT-Sw3-6.7B|13.4/44.3|43.6/62.5|**44.5**/63.5|
195
+ |GPT-Sw3-6.7B-v2|14.8/45.5|43.7/62.3|44.0/63.6|
196
+
197
+ </details>
198
+
199
+
200
+ <details open>
201
+ <summary>Norwegian Bokmål → English</summary>
202
+
203
+ |Model|0-shot (BLEU/chrF++)|1-shot (BLEU/chrF++)|5-shot (BLEU/chrF++)|
204
+ |---|---|---|---|
205
+ |NorMistral-7b-warm|**55.1**/**68.4**|**55.5**/**69.5**|56.0/69.8|
206
+ |NorMistral-7b-scratch|47.1/61.9|49.4/64.2|52.3/66.2|
207
+ |NorBLOOM-7b|45.0/59.3|48.3/64.0|49.0/64.7|
208
+ |NB-GPT-J|9.8/41.4|24.8/58.3|47.6/67.7|
209
+ |Falcon-7B|21.6/40.6|31.7/47.4|36.6/51.7|
210
+ |GPT-Sw3-6.7B|47.8/66.2|49.1/68.1|49.6/69.4|
211
+ |GPT-Sw3-6.7B-v2|46.3/67.5|48.9/69.3|**58.2**/**72.8**|
212
+
213
+ </details>
214
+
215
+ <details open>
216
+ <summary>Norwegian Nynorsk → English</summary>
217
+
218
+ |Model|0-shot (BLEU/chrF++)|1-shot (BLEU/chrF++)|5-shot (BLEU/chrF++)|
219
+ |---|---|---|---|
220
+ |NorMistral-7b-warm|**55.1**/**68.4**|**55.5**/**69.5**|56.0/69.8|
221
+ |NorMistral-7b-scratch|47.1/61.9|49.4/64.2|52.3/66.2|
222
+ |NorBLOOM-7b|45.0/59.3|48.3/64.0|49.0/64.7|
223
+ |NB-GPT-J|2.9/19.5|10.1/41.0|44.4/66.9|
224
+ |Falcon-7B|21.6/40.6|31.7/47.4|36.6/57.1|
225
+ |GPT-Sw3-6.7B|47.8/66.2|49.1/68.1|49.6/69.4|
226
+ |GPT-Sw3-6.7B-v2|46.3/67.5|48.9/69.3|**58.2**/**72.8**|
227
+
228
+ </details>
229
+
230
+
231
+ <details open>
232
+ <summary>Norwegian Bokmål → Norwegian Nynorsk</summary>
233
+
234
+ |Model|0-shot (BLEU/chrF++)|1-shot (BLEU/chrF++)|5-shot (BLEU/chrF++)|
235
+ |---|---|---|---|
236
+ |NorMistral-7b-warm|**75.8**/**87.5**|74.0/**86.9**|75.3/87.5|
237
+ |NorMistral-7b-scratch|38.0/56.9|39.2/57.9|40.7/59.3|
238
+ |NorBLOOM-7b|71.5/84.4|70.1/84.1|71.9/85.1|
239
+ |NB-GPT-J|6.6/35.5|9.6/41.0|26.0/64.7|
240
+ |Falcon-7B|28.7/59.2|29.8/60.8|32.1/62.3|
241
+ |GPT-Sw3-6.7B|63.6/82.8|74.7/86.0|75.8/86.9|
242
+ |GPT-Sw3-6.7B-v2|57.5/81.1|**75.3**/86.7|**76.7**/**87.6**|
243
+
244
+ </details>
245
+
246
+ <details open>
247
+ <summary>Norwegian Nynorsk → Norwegian Bokmål</summary>
248
+
249
+ |Model|0-shot (BLEU/chrF++)|1-shot (BLEU/chrF++)|5-shot (BLEU/chrF++)|
250
+ |---|---|---|---|
251
+ |NorMistral-7b-warm|**88.1**/**93.6**|**89.2**/**94.3**|**89.3**/**94.6**|
252
+ |NorMistral-7b-scratch|85.1/91.4|86.6/92.4|87.4/93.0|
253
+ |NorBLOOM-7b|78.7/88.5|84.2/90.7|87.4/93.0|
254
+ |NB-GPT-J|2.7/18.5|6.9/35.6|52.9/84.3|
255
+ |Falcon-7B|36.7/61.6|38.3/63.5|45.8/68.1|
256
+ |GPT-Sw3-6.7B|652.3/82.4|86.1/92.5|87.8/93.6|
257
+ |GPT-Sw3-6.7B-v2|72.0/88.6|86.1/92.5|88.2/93.9|
258
+
259
+ </details>
260
+
261
+
262
+ _____
263
+ ## Hardware and Software
264
+
265
+ **Training Factors:** The models were pretrained using the Megatron-DeepSpeed library on [the LUMI cluster in Finland](https://lumi-supercomputer.eu/).
266
+
267
+ **Carbon Footprint:** Pretraining one model took approximately 70k GPU hours of computation on AMD MI250X GPUs (assuming 2 GPUs per one AMD MI250X device), each of which draws 500W.
268
+ LUMI is [one of the most eco-efficient data centers in the world](https://www.lumi-supercomputer.eu/sustainable-future/), and its energy consumption is covered 100% with renewable electricity.
269
+
270
+
271
+
272
+ _____
273
+ ## Example usage
274
+
275
+ Let's try to use this model for English-to-Norwegian machine translation using simple zero-shot prompting:
276
+
277
+ ```python
278
+ from transformers import AutoTokenizer, AutoModelForCausalLM
279
+
280
+ # First, we will have to import the tokenizer and the language model
281
+ tokenizer = AutoTokenizer.from_pretrained("norallm/normistral-7b-scratch")
282
+ model = AutoModelForCausalLM.from_pretrained("norallm/normistral-7b-scratch").cuda().eval()
283
+
284
+ # Now we will define the zero-shot prompt template
285
+ prompt = """Engelsk: {0}
286
+ Bokmål:"""
287
+
288
+ # A function that will take care of generating the output
289
+ @torch.no_grad()
290
+ def generate(text):
291
+ text = prompt.format(text)
292
+ input_ids = tokenizer(text, return_tensors='pt').input_ids.cuda()
293
+ prediction = model.generate(
294
+ input_ids,
295
+ max_new_tokens=64,
296
+ do_sample=False,
297
+ eos_token_id=tokenizer('\n').input_ids
298
+ )
299
+ return tokenizer.decode(prediction[0, input_ids.size(1):]).strip()
300
+
301
+ # Now you can simply call the generate function with an English text you want to translate:
302
+ generate("I'm super excited about this Norwegian NORA model! Can it translate these sentences?")
303
+ # > this should output: 'Jeg er super spent på denne norske NORA modellen! Kan den oversette disse setningene?'
304
+ ```