Ahma-3B-Instruct is a instruct/chat-tuned version of Ahma-3B trained to follow instructions in Finnish. The base Ahma 3B parameter model is decoder-only transformer model based on Meta's Llama (v1) architecture pretrained from scratch on Finnish language. Original Llama model architecture was introduced in
this paper
and first released at this page.
What does Ahma mean? Ahma is the Finnish word for wolverine! In the Finnish Lapland, wolverines are the biggest cause of reindeer damage.
There are two different sized base Ahma models, all pretrained from scratch for 139B tokens:
This model was fine-tuned for instruction following. Instruction-tuned models are intended for assistant-like chat, whereas pretrained models can be adapted for a variety of natural language generation tasks.
How to use
If you want to use this model for instruction-following, you need to use the same prompt format we used in the fine-tuning process (basically the same format what Meta used in their Llama2 models). Note: do not use "LlamaTokenizer" from transformers library but always use the AutoTokenizer instead, or use the plain sentencepiece tokenizer.
Looking for GGUF-versions?
Those can be found from here for now: GGUF-versions
Here is an example using the instruction-following prompt format with the tokenizer's built-in chat template feature which makes it easy to format your potential multi-turn chats too, with some generation arguments you can modify for your use:
python
1from transformers import AutoTokenizer, AutoModelForCausalLM
23system_prompt ="Olet tekoälyavustaja. Vastaat aina mahdollisimman avuliaasti. Vastauksesi eivät saa sisältää mitään haitallista, epäeettistä, rasistista, seksististä, vaarallista tai laitonta sisältöä. Jos kysymyksessä ei ole mitään järkeä tai se ei ole asiasisällöltään johdonmukainen, selitä miksi sen sijaan, että vastaisit jotain väärin. Jos et tiedä vastausta kysymykseen, älä kerro väärää tietoa."456tokenizer = AutoTokenizer.from_pretrained("Finnish-NLP/Ahma-3B-Instruct")7model = AutoModelForCausalLM.from_pretrained("Finnish-NLP/Ahma-3B-Instruct")8model = model.to("cuda")910# use the chat template feature in the tokenizer to format your (multi-turn) inputs1112messages =[13{14"role":"system",15"content": system_prompt,16},17{"role":"user","content":"Kerro kolme hyötyä, joita pienet avoimen lähdekoodin kielimallit tuovat?"},18]19inputs = tokenizer.apply_chat_template(20 messages, tokenize=True, add_generation_prompt=True, return_tensors="pt"21)22inputs = inputs.to("cuda")2324generated_ids = model.generate(25 inputs,26 temperature=0.6,27 penalty_alpha=0.6,28 top_k=4,29 do_sample=True,30 repetition_penalty=1.2,31 min_length=5,32 max_length=2048,33)34generated_text = tokenizer.batch_decode(35 generated_ids, skip_special_tokens=False36)[0]3738'''
391) Parantuneet keskustelutaidot: Pienet, hyvin koulutetut kielimallit voidaan kouluttaa ymmärtämään ja tuottamaan ihmisen kaltaista kieltä, mikä johtaa luonnollisempaan keskusteluun. Tämä voi olla erityisen hyödyllistä sovelluksissa, kuten chat-roboteissa, virtuaaliavustajissa ja kielenkääntämisessä.
40412) Lisääntynyt luovuus kirjoittamisessa: Kielimallit voivat auttaa kirjoittajia tuottamalla ideoita, lauseita ja virkkeitä, jotka ovat hiottuja ja merkityksellisiä. Tämä voi johtaa parempaan kirjoituslaatuun, parempaan organisointiin ja tehokkaampaan viestintään.
42433) Parempi tietojenkäsittely ja -tallennus: Pienemmät ja edullisemmat kielimallit voivat mullistaa tietojenkäsittelyn ja tallennuksen. Ne voivat säästää tilaa ja resursseja, koska ne pystyvät suorittamaan tiettyjä tehtäviä tehokkaammin kuin perinteiset koneoppimisalgoritmit. Lisäksi kielimallien avoimen lähdekoodin luonne mahdollistaa sen, että tutkijat, kehittäjät ja yritykset voivat tehdä niihin parannuksia ja lisäyksiä, mikä voi johtaa entistä kehittyneempiin ja monipuolisempiin ratkaisuihin.
44'''
You may experiment with different system prompt instructions too if you like.
Limitations and bias
This model was trained only with Finnish texts excluding code so it should not be used for multilingual and code generation use cases.
The training data used for this model contains a lot of content from the internet, which is far from neutral. Therefore, the model can have biased predictions. This bias will also affect all fine-tuned versions of this model.
Training data
To better reflect the data distribution of the training set and balance the common samples and rare samples during training, we implemented the "ClusterClip Sampling" method by Shao et al. (2024) using BAAI/bge-m3 embeddings and KMeans clustering of 30 clusters. The training datasets mentioned below were created using this sampling method.
There has also been some indication that gradually increasing the training example lengths during the training could be beneficial. Thus, the training dataset was splitted to 4 bins based on example lengths, and then examples were sampled from the bins so that the example lengths are gradually increasing towards the end of the training while a little amount of the shorter examples are still present too.
This model was first supervised fine-tuned (SFT) on the combination of the following datasets:
Dataset
Dataset type
Upsampling
Words
Ratio
Average words per example
Aya Finnish
Finnish single-turn
2.9X
55K
0.54%
83
OASST
Translated single-turn
2.9X
507K
5.01%
139
ai2_arc
Translated single-turn
2.9X
12K
0.12%
39
chatbot_arena
Translated single-turn
2.8X
554K
5.48%
147
dibt10k
Translated single-turn
2.9X
363K
3.58%
262
dolly
Translated single-turn
2.9X
221K
2.19%
71
Aya Dutch
Translated single-turn
2.9X
13K
0.12%
36
Aya English
Translated single-turn
2.9X
97K
0.96%
61
Aya French
Translated single-turn
3.7X
75K
0.74%
58
intel_dpo
Translated single-turn
2.9X
539K
5.33%
163
lmsys_1m
Translated single-turn
2.8X
2187K
21.61%
246
news_qa
Translated single-turn
2.9X
297K
2.94%
152
orca_math
Translated single-turn
2.9X
1165K
11.51%
196
Aya Portuguese
Translated single-turn
2.9X
97K
0.96%
27
Aya Spanish
Translated single-turn
2.8X
52K
0.51%
54
Aya Swedish
Translated single-turn
2.9X
5K
0.05%
41
ultrachat
Translated single-turn
2.8X
2199K
21.73%
221
lmsys_multiturn
Translated multi-turn
2.9X
490K
4.84%
379
oaast2_multiturn
Translated multi-turn
2.8X
593K
5.86%
307
suomitrivia_synthetic
Synthetic single-turn
1.0X
4K
0.04%
16
wikipedia_multitask_synthetic_qa
Synthetic single-turn
1.0X
206K
2.03%
499
wikipedia_synthetic_qa_reasoning
Synthetic single-turn
1.0X
201K
1.98%
477
wikipedia_synthetic_person_discussions_multiturn
Synthetic multi-turn
1.0X
188K
1.85%
194
TOTAL
10121K
100%
168
After tokenization, the SFT training dataset had 23 million tokens and 5% of the dataset was splitted for evaluation during the training.
The SFT model was then further fine-tuned with Direct Preference Optimization (DPO) on the combination of the following datasets:
Dataset
Dataset type
Upsampling
Words
Ratio
Average words per example
intel_dpo
Translated single-turn
1.3X
467K
39.75%
153
ultrachat
Translated single-turn
1.2X
1017K
57.24%
220
suomitrivia_dpo
Synthetic single-turn
1.0X
5K
3.01%
16
TOTAL
1489K
100%
130
After tokenization, the DPO training dataset had 3 million tokens and 5% of the dataset was splitted for evaluation during the training.
Training procedure
Preprocessing
Texts are tokenized using Byte Pair Encoding (BPE) using the implementation from SentencePiece splitting all numbers into individual digits and using bytes to decompose unknown UTF-8 characters. The total
vocabulary size is 64k tokens. Inputs are sequences of 2048 consecutive tokens. Texts are not lower cased so this model is case-sensitive: it makes a difference between finnish and Finnish. Both BOS and EOS tokens were used in the fine-tuning.
Supervised fine-tuning (SFT)
This model was first supervised fine-tuned (SFT) using the unsloth framework with a single NVIDIA GeForce RTX 4080 GPU. The model was fine-tuned for 1 epoch with a learning rate of 5e-05, weight decay of 5e-03, learning rate warmup ratio of 0.1 with cosine decay, batch size of 4 and gradient accumulation of 8 totalling the batch size to 32, max sequence lenght of 2048, and with NEFTune noise alpha of 5. The used optimizer was "paged_adamw_8bit" and the model was loaded with 4bit quantization. Training was done using the Rank-Stabilized LoRA (RSLora) with a rank of 256 and alpha of 128, LoRA dropout of 0.02, target modules of "q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj" and modules_to_save "lm_head", "embed_tokens".
Direct Preference Optimization (DPO) fine-tuning
The SFT model was then further fine-tuned with Direct Preference Optimization (DPO) using the unsloth framework with a single NVIDIA GeForce RTX 4080 GPU. The model was fine-tuned for 1 epoch with a learning rate of 2e-05, weight decay of 0.0, learning rate warmup ratio of 0.1 with cosine decay, batch size of 2 and gradient accumulation of 8 totalling the batch size to 16, and with max sequence lenght of 2048. The used optimizer was "paged_adamw_8bit". Training was done using the Rank-Stabilized LoRA (RSLora) with a rank of 64 and alpha of 32, LoRA dropout of 0.05, and target modules of "q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj".
As we can see, Ahma-3B-Instruct model outperforms 2X larger models like the FinGPT 8B and Viking 7B, especially in non-arithmetic tasks in 0-shot usage. Even the 10X larger Poro 34B model, which is generally better, doesn't show a huge performance difference considering its size, and Ahma-3B-Instruct actually surpasses it in some tasks.
In a 3-shot setting, we can see that the Ahma-3B-Instruct model has better few-shot example following performance compared to the base Ahma 3B model. This could be due to the inclusion of multi-turn examples in the fine-tuning dataset.
MTBench Finnish
This Ahma-3B-Instruct model was primarily evaluated using MTBench Finnish by LumiOpen since this model is fine-tuned for chat and instruction following. Since the MTBench evaluates also multi-turn chats while Ahma base models were only pretrained with single-turn instruction following examples, we have reported MTBench Finnish results separately for their single-turn and multi-turn evaluation examples. This enables us to evaluate how well this Ahma-3B-Instruct model improves on multi-turn chats since its fine-tuning dataset included some multi-turn examples too. Poro 34B Chat by SiloGen, TurkuNLP and HPLT model's presumably multi-turn results are copied from their model card for the comparison.
Single-turn results:
Benchmark
Ahma 3B base (instruct prompt format)
Ahma 3B Instruct
Ahma 7B base (instruct prompt format)
Ahma 7B Instruct
Coding
1.00
1.00
TBA
TBA
Extraction
2.00
1.30
TBA
TBA
Humanities
4.05
6.20
TBA
TBA
Math
3.00
3.20
TBA
TBA
Reasoning
2.90
4.60
TBA
TBA
Roleplay
4.80
6.50
TBA
TBA
STEM
5.10
5.95
TBA
TBA
Writing
6.60
9.00
TBA
TBA
Overall Average
3.68
4.72
TBA
TBA
Multi-turn results:
Benchmark
Ahma 3B base (instruct prompt format)
Ahma 3B Instruct
Ahma 7B base (instruct prompt format)
Ahma 7B Instruct
Poro 34B Chat
Coding
1.00
1.00
TBA
TBA
3.70
Extraction
1.55
1.15
TBA
TBA
6.37
Humanities
3.25
6.20
TBA
TBA
9.25
Math
2.20
2.70
TBA
TBA
1.20
Reasoning
2.45
3.50
TBA
TBA
4.35
Roleplay
4.90
6.40
TBA
TBA
7.35
STEM
4.20
4.78
TBA
TBA
7.80
Writing
3.80
6.65
TBA
TBA
8.50
Overall Average
2.92
4.05
TBA
TBA
6.06
As we can see, the Ahma-3B-Instruct model significantly improves upon the base Ahma-3B model, especially in tasks like writing. It's also worth noting that the Ahma-3B-Instruct model shows enhanced performance in multi-turn tasks compared to the base model, which highlights the value of the multi-turn training examples used in the fine-tuning process. The Ahma-3B-Instruct model lost 14% of its single-turn overall score in a multi-turn setting, while the base Ahma-3B model lost 21%. Therefore, this instruct model might be better suited for chat use cases as well. As expected, coding performance was poor since the Ahma models aren't trained on code data.
Ahma models also seemed to have problems with the fact that they started to constantly repeat the generated text in some evaluation examples, which affected the scoring. With the addition of a repetition penalty setting to the evaluation script generation method, the scores already improved significantly, so Ahma models should be used with better generation settings in real-world use compared to the settings used in this benchmark.
Acknowledgements
This project would not have been possible without compute generously provided by Google through the
TPU Research Cloud.