|
--- |
|
language: |
|
- fi |
|
license: apache-2.0 |
|
tags: |
|
- finnish |
|
- llama |
|
datasets: |
|
- Finnish-NLP/CulturaX_fi_cleaned |
|
- Finnish-NLP/HPLT_1.2_fi_cleaned |
|
- Finnish-NLP/wikipedia_20231101_fi_cleaned |
|
- Finnish-NLP/Reddit_fi_2006_2022 |
|
- intfloat/multilingual_cc_news |
|
inference: false |
|
base_model: Finnish-NLP/Ahma-3B |
|
pipeline_tag: text-generation |
|
|
|
--- |
|
|
|
# QuantFactory/Ahma-3B-GGUF |
|
This is quantized version of [Finnish-NLP/Ahma-3B](https://huggingface.co/Finnish-NLP/Ahma-3B) created using llama.cpp |
|
|
|
# Ahma-3B for Finnish |
|
|
|
Ahma is 3B parameter decoder-only transformer model based on Meta's Llama (v1) architecture pretrained on Finnish language. Original Llama model architecture was introduced in |
|
[this paper](https://arxiv.org/abs/2302.13971) |
|
and first released at [this page](https://github.com/facebookresearch/llama). |
|
|
|
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 Ahma models, all pretrained from scratch for 139B tokens: |
|
|
|
| Model | Context length | Layers | Dim | Heads | Params | |
|
|:--------------------------------------------------------------------------------|:---------------|:-------|:-----|:------|:-------| |
|
| [Ahma-3B](https://huggingface.co/Finnish-NLP/Ahma-3B) | 2048 | 26 | 3200 | 32 | 3.6B | |
|
| [Ahma-7B](https://huggingface.co/Finnish-NLP/Ahma-7B) | 2048 | 32 | 4096 | 32 | 7.0B | |
|
|
|
## Intended uses & limitations |
|
|
|
This model was pretrained only in a self-supervised way, without any supervised training. You can use this model for text generation or fine-tune it for a downstream task. This model followed a 2-stage pretraining approach where single-turn instruction-following examples were mixed in with the other training data in the second stage (explained more later in this readme). Thanks to this approach, this pretrained model is already capable of instruction following, but you might get even better results if you specifically fine-tune it for instruction following or other use cases. For instruction-following fine-tuning, you should use the same prompt format showcased below. |
|
|
|
### 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 second stage of the pretraining (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.** Here is an example using the instruction-following prompt format, with some generation arguments you can modify for your use: |
|
|
|
```python |
|
from transformers import AutoTokenizer, AutoModelForCausalLM |
|
|
|
system_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." |
|
|
|
|
|
def format_prompt(prompt: str) -> str: |
|
prompt = f" [INST] <<SYS>>\n{system_prompt.strip()}\n<</SYS>>\n\n{prompt.strip()} [/INST] " |
|
return prompt |
|
|
|
|
|
tokenizer = AutoTokenizer.from_pretrained("Finnish-NLP/Ahma-3B") |
|
model = AutoModelForCausalLM.from_pretrained("Finnish-NLP/Ahma-3B") |
|
|
|
# use the custom prompt format function or the chat template feature in the tokenizer to format your inputs |
|
|
|
# prompt = format_prompt("Mitä hyötyjä pienet avoimen lähdekoodin kielimallit tuovat?") |
|
# inputs = tokenizer(prompt, return_tensors="pt") |
|
|
|
messages = [ |
|
{ |
|
"role": "system", |
|
"content": system_prompt, |
|
}, |
|
{"role": "user", "content": "Mitä hyötyjä pienet avoimen lähdekoodin kielimallit tuovat?"}, |
|
] |
|
inputs = tokenizer.apply_chat_template( |
|
messages, tokenize=True, add_generation_prompt=True, return_tensors="pt" |
|
) |
|
|
|
generated_ids = model.generate( |
|
inputs, |
|
temperature=0.6, |
|
penalty_alpha=0.6, |
|
top_k=4, |
|
do_sample=True, |
|
repetition_penalty=1.2, |
|
min_length=5, |
|
max_length=2048, |
|
) |
|
generated_text = tokenizer.batch_decode( |
|
generated_ids, skip_special_tokens=False |
|
)[0] |
|
|
|
# Pienillä avoimen lähdekoodin kielimalleilla on lukuisia etuja, kuten parempi tarkkuus, nopeampi käsittelyaika ja parempi skaalautuvuus. Ne ovat myös usein edullisempia käyttää kuin kaupalliset mallit, joten ne ovat hyvä valinta pienemmille organisaatioille ja yksityishenkilöille, joilla on rajoitettu budjetti. Lisäksi ne voivat tarjota paremman joustavuuden ja mukauttamisen, koska käyttäjät voivat räätälöidä malleja vastaamaan omia tarpeitaan. Kaiken kaikkiaan pienet avoimen lähdekoodin kielimallit tarjoavat merkittäviä etuja, kuten paremman suorituskyvyn, paremman tarkkuuden, nopeamman käsittelyajan ja paremman skaalautuvuuden. |
|
``` |
|
|
|
You may experiment with different system prompt instructions too if you like. |
|
|
|
### Limitations and bias |
|
|
|
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. |
|
|
|
To reduce toxic content, training data was filtered with a toxicity classifier but it cannot truly eliminate all toxic text. |
|
|
|
## Training data |
|
|
|
This model was pretrained on the combination of 14 datasets: |
|
- [CulturaX_fi_cleaned](https://huggingface.co/datasets/Finnish-NLP/CulturaX_fi_cleaned), we cleaned Finnish split from the original [CulturaX](https://huggingface.co/datasets/uonlp/CulturaX) dataset |
|
- [HPLT_1.2_fi_cleaned](https://huggingface.co/datasets/Finnish-NLP/HPLT_1.2_fi_cleaned), we cleaned Finnish split from the original [HPLT v1.2](https://hplt-project.org/datasets/v1.2) dataset |
|
- [wikipedia_20231101_fi_cleaned](https://huggingface.co/datasets/Finnish-NLP/wikipedia_20231101_fi_cleaned), we used the Finnish subset of the wikipedia (November 2023) dataset |
|
- [Reddit_fi_2006_2022](https://huggingface.co/datasets/Finnish-NLP/Reddit_fi_2006_2022), filtered and post-processed dataset of Finnish Reddit |
|
- [Yle Finnish News Archive 2011-2018](http://urn.fi/urn:nbn:fi:lb-2017070501) |
|
- [Yle Finnish News Archive 2019-2020](http://urn.fi/urn:nbn:fi:lb-2021050401) |
|
- [Finnish News Agency Archive (STT)](http://urn.fi/urn:nbn:fi:lb-2018121001) |
|
- [The Suomi24 Sentences Corpus](http://urn.fi/urn:nbn:fi:lb-2020021803) |
|
- [Project Lönnrot](http://www.lonnrot.net/) |
|
- [Finnish parliament speeches](https://avoindata.eduskunta.fi) |
|
- [multilingual_cc_news](https://huggingface.co/datasets/intfloat/multilingual_cc_news), we used the Finnish subset of the multilingual CC-News dataset |
|
- [fi-news-corpus](https://github.com/nkrusch/fi-news-corpus) |
|
- Finnish higher education public theses |
|
- Finnish single-turn instruction-following datasets, combination of multiple originally openly licensed English datasets translated to Finnish. For example, [Ultrachat, Aya, Capybara, etc](https://huggingface.co/collections/Finnish-NLP/sft-dpo-dataset-65f55dde1139c3cd683ff035) |
|
|
|
|
|
Raw datasets were automatically cleaned to filter out bad quality and non-Finnish examples. Also, a [perplexity](https://huggingface.co/course/chapter7/3#perplexity-for-language-models) score was calculated for all texts with a KenLM model which was trained with very clean Finnish texts only. This perplexity score can then be used to determine how "clean" Finnish language the text contains. To reduce toxic text, we used Finnish toxicity classifier [TurkuNLP/bert-large-finnish-cased-toxicity](https://huggingface.co/TurkuNLP/bert-large-finnish-cased-toxicity) released by TurkuNLP to classify all text examples. Classified toxicity label scores can then be used to determine how toxic the text is. |
|
|
|
All datasets were concatenated and the whole dataset near deduplicated using MinHashLSH from [text-dedup](https://github.com/ChenghaoMou/text-dedup). Top 95% perplexity score was used as a filtering threshold to filter out the worst quality 5% of texts. To reduce amount of toxic content, the dataset was filtered to include text examples having lower than 80% score for the toxicity labels "label_identity_attack", "label_insult", "label_threat" and "label_severe_toxicity". |
|
|
|
Finally, 20,000 text examples from each of the CulturaX, Wikipedia, Yle, STT, Suomi24, and Reddit datasets were randomly selected for evaluation dataset. |
|
|
|
The final training dataset had 23 billion words (calculated with regex "\w+") and the evaluation dataset had 23 million words. After tokenization, the training dataset had 41 billion tokens and the evaluation dataset had 40 million tokens. For the 2-stage pretraining, training datasets are divided as follows: |
|
|
|
The first stage: |
|
|Dataset | Words | Ratio | |
|
|:-----------------------------|:------------|:-------------| |
|
|CulturaX | 12.820B | 59.88\% | |
|
|HPLT v1.2 | 5.034B | 23.51\% | |
|
|Suomi24 | 3.018B | 14.09\% | |
|
|Reddit | 0.141B | 0.66\% | |
|
|CC-News | 0.311B | 1.45\% | |
|
|FI news corpus | 0.004B | 0.02\% | |
|
|Project Lönnrot | 0.083B | 0.39\% | |
|
|**TOTAL** | **21.410B** | **100.0\%** | |
|
|
|
|
|
The second stage: |
|
|Dataset | Words | Ratio | |
|
|:--------------------------------------------------------------|:------------|:------------| |
|
|CulturaX (cleaner sample using KenLM perplexity score) | 2.252B | 55.48\% | |
|
|Wikipedia | 0.095B | 2.34\% | |
|
|STT | 0.253B | 6.23\% | |
|
|Yle | 0.212B | 5.22\% | |
|
|Finnish parliament speeches | 0.021B | 0.52\% | |
|
|Finnish higher education public theses | 0.855B | 21.07\% | |
|
|Finnish instruction-following datasets (note: 2X upsampled) | 0.371B | 9.14\% | |
|
|**TOTAL** | **4.059B** | **100.0\%** | |
|
|
|
## 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 pretraining. |
|
|
|
### 2-stage pretraining |
|
|
|
The model was trained on TPUv4-32 VM, sponsored by the [Google TPU Research Cloud](https://sites.research.google/trc/about/). Training was conducted with a slightly modified Jax/Flax based [EasyLM](https://github.com/young-geng/EasyLM) framework, and inspired by the [OpenLLaMA](https://github.com/openlm-research/open_llama) project. The optimizer used was a [Lion](https://arxiv.org/abs/2302.06675). |
|
|
|
The 2-stage pretraining approach was inspired by [MiniCPM](https://shengdinghu.notion.site/MiniCPM-Unveiling-the-Potential-of-End-side-Large-Language-Models-d4d3a8c426424654a4e80e42a711cb20) findings. For the first stage (85% of the entire training), we used noisier web-scraped datasets. For the second stage (15% of the entire training), we primarily used cleaner datasets and instruction-following datasets shuffled together, like in MiniCPM. The learning rate schedule for the 2-stage pretraining was Warmup-Stable-Decay (WSD). During the first stage, the learning rate schedule had a linear warmup for about 8 billion tokens to a peak learning rate of 1e-4 (note: with the Lion optimizer, the learning rate had to be about 10 times smaller than with the commonly used AdamW), followed by a stable phase where the rate of 1e-4 was kept constant. During the second stage, the learning rate schedule had a linear decay from 1e-4 to 1e-5 for the first 13 billion tokens, followed by a stable phase for the remaining tokens. |
|
|
|
In the first stage, the model was trained for 118 billion tokens, which is about three epochs of the first-stage training data, inspired by the findings of [this paper](https://arxiv.org/abs/2305.16264). In the second stage, the model was trained for 21 billion tokens, which is about three epochs of the second-stage training data. |
|
|
|
Thanks to the WSD learning rate schedule, you can more easily experiment with different first-stage model checkpoints. For example, you could apply the second-stage training on an earlier checkpoint or continue pretraining further before the second stage. Model checkpoints were pushed to this repository every 100,000 training steps (approximately 13 billion tokens). |
|
|
|
- [900K](https://huggingface.co/Finnish-NLP/Ahma-3B/tree/916632fe707a7fbe341a1902ac9eacf6e5872ec9) |
|
- [800K](https://huggingface.co/Finnish-NLP/Ahma-3B/tree/a18d46e62823b19b4a97332c0a5a62b14372a3e2) |
|
- [700K](https://huggingface.co/Finnish-NLP/Ahma-3B/tree/2d16e05820af108582dbfcd3d25e51c6f1d5076b) |
|
- [600K](https://huggingface.co/Finnish-NLP/Ahma-3B/tree/949f4bfba406882d5ce0343aa1242bcf901202e2) |
|
- [500K](https://huggingface.co/Finnish-NLP/Ahma-3B/tree/359812c02839d4085d890c6db0e57796b7e48bfc) |
|
- [400K](https://huggingface.co/Finnish-NLP/Ahma-3B/tree/62468680cb84579a7d1885f60abe6d6607f59f45) |
|
- [300K](https://huggingface.co/Finnish-NLP/Ahma-3B/tree/0424dcc0b3dbf505f7b20cf02cb80233289ef125) |
|
- [200K](https://huggingface.co/Finnish-NLP/Ahma-3B/tree/e415206d791aad108bed8578009bf255c1f22c91) |
|
- [100K](https://huggingface.co/Finnish-NLP/Ahma-3B/tree/8085f7c3fba46cfdbf95a01b7a1da1587b757f8b) |
|
|
|
## Evaluation results |
|
|
|
### FIN-bench |
|
|
|
This Ahma model was primarily evaluated using [FIN-bench by TurkuNLP](https://github.com/TurkuNLP/FIN-bench), and the same evaluation was carried out for other relevant Finnish models for comparison. Below are the results with 0-shot and 3-shot settings in FIN-bench: |
|
|
|
| Benchmark | Ahma 3B (instruct prompt format) 0-shot | Ahma 7B (instruct prompt format) 0-shot | FinGPT 8B 0-shot | Viking 7B 0-shot | Poro 34B (8bit quant) 0-shot | |
|
|:---------------------------|:----------------------------------------|:----------------------------------------|:-----------------|:-----------------|:-----------------------------| |
|
| Analogies | 50.77 | TBA | 49.23 | 40.00 | 54.62 | |
|
| Arithmetic | 27.64 | TBA | 33.15 | 30.16 | 30.34 | |
|
| Cause and Effect | 59.48 | TBA | 66.01 | 58.82 | 62.74 | |
|
| Emotions | 36.25 | TBA | 22.50 | 26.25 | 35.63 | |
|
| Empirical Judgements | 33.33 | TBA | 27.27 | 33.33 | 49.49 | |
|
| General Knowledge | 44.29 | TBA | 40.00 | 24.29 | 51.43 | |
|
| HHH Alignment | 42.09 | TBA | 41.81 | 42.51 | 42.92 | |
|
| Intent Recognition | 24.42 | TBA | 17.49 | 22.40 | 68.35 | |
|
| Misconceptions | 46.27 | TBA | 53.73 | 53.73 | 52.24 | |
|
| Paraphrase | 59.50 | TBA | 51.00 | 50.00 | 51.00 | |
|
| Sentence Ambiguity | 53.33 | TBA | 51.67 | 48.33 | 50.00 | |
|
| Similarities Abstraction | 65.79 | TBA | 60.53 | 65.79 | 60.53 | |
|
| **Non-Arithmetic Average** | **47.55** | TBA | **46.17** | **44.42** | **52.08** | |
|
| **Overall Average** | **36.49** | TBA | **38.93** | **36.50** | **40.00** | |
|
|
|
|
|
| Benchmark | Ahma 3B (instruct prompt format) 3-shot | Ahma 7B (instruct prompt format) 3-shot | FinGPT 8B 3-shot | Viking 7B 3-shot | Poro 34B (8bit quant) 3-shot | |
|
|:---------------------------|:----------------------------------------|:----------------------------------------|:-----------------|:-----------------|:-----------------------------| |
|
| Analogies | 52.31 | TBA | 40.77 | 54.62 | 76.92 | |
|
| Arithmetic | 44.59 | TBA | 43.63 | 45.78 | 53.68 | |
|
| Cause and Effect | 61.44 | TBA | 64.05 | 58.17 | 67.32 | |
|
| Emotions | 14.37 | TBA | 44.37 | 48.13 | 56.87 | |
|
| Empirical Judgements | 38.38 | TBA | 32.32 | 43.43 | 63.64 | |
|
| General Knowledge | 38.57 | TBA | 54.29 | 28.57 | 74.29 | |
|
| HHH Alignment | 42.94 | TBA | 45.39 | 44.80 | 46.07 | |
|
| Intent Recognition | 24.28 | TBA | 51.45 | 58.82 | 83.67 | |
|
| Misconceptions | 46.27 | TBA | 52.99 | 46.27 | 52.99 | |
|
| Paraphrase | 58.50 | TBA | 53.00 | 54.50 | 55.00 | |
|
| Sentence Ambiguity | 53.33 | TBA | 51.67 | 53.33 | 66.67 | |
|
| Similarities Abstraction | 72.37 | TBA | 64.47 | 73.68 | 75.00 | |
|
| **Non-Arithmetic Average** | **47.15** | TBA | **51.19** | **50.94** | **61.96** | |
|
| **Overall Average** | **45.73** | TBA | **46.99** | **48.07** | **57.36** | |
|
|
|
|
|
As we can see, Ahma 3B 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 actually surpasses it in some tasks. This result might be attributed to Ahma's 2-stage pretraining and the inclusion of instruct-following examples during the pretraining phase. |
|
|
|
In a 3-shot setting, the results are more mixed. The poorer performance of Ahma 3B in 3-shot settings might be due to the use of the instruct prompt format and having only single-turn instruction-following training examples. |
|
|
|
|
|
### MTBench Finnish |
|
|
|
This Ahma model was also evaluated using [MTBench Finnish by LumiOpen](https://github.com/LumiOpen/FastChat/tree/main/fastchat/llm_judge) even though this Ahma model is not fine-tuned for chat. Since the MTBench evaluates also multi-turn chats while Ahma 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. [Poro 34B Chat](https://huggingface.co/LumiOpen/Poro-34B-chat) model's results are copied from their model card for comparison. |
|
|
|
| Benchmark | Ahma 3B (instruct prompt format) single-turn | Ahma 3B (instruct prompt format) multi-turn | Ahma 7B (instruct prompt format) single-turn | Ahma 7B (instruct prompt format) multi-turn | Poro 34B Chat multi-turn | |
|
|:--------------------|:---------------------------------------------|:--------------------------------------------|:---------------------------------------------|:--------------------------------------------|:-------------------------| |
|
| Coding | 1.00 | 1.00 | TBA | TBA | 3.05 | |
|
| Extraction | 2.00 | 1.55 | TBA | TBA | 6.05 | |
|
| Humanities | 4.05 | 3.25 | TBA | TBA | 9.6 | |
|
| Math | 3.00 | 2.20 | TBA | TBA | 1.25 | |
|
| Reasoning | 2.90 | 2.45 | TBA | TBA | 3.65 | |
|
| Roleplay | 4.80 | 4.90 | TBA | TBA | 7.0 | |
|
| STEM | 5.10 | 4.20 | TBA | TBA | 7.65 | |
|
| Writing | 6.60 | 3.80 | TBA | TBA | 7.6 | |
|
| **Overall Average** | **3.68** | **2.92** | TBA | TBA | **5.73** | |
|
|
|
As we can see, Ahma 3B model struggles with multi-turn examples, as expected, since it has only been pretrained with single-turn instruction following examples. In addition, coding performance was expectedly poor because the Ahma 3B model is not trained with code data. Ahma 3B also seemed to have problems with the fact that it 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 the Ahma 3B model should be used with better generation settings in real-world use compared to the settings used in this benchmark. |
|
|
|
## Team Members |
|
|
|
- Aapo Tanskanen, [Hugging Face profile](https://huggingface.co/aapot), [LinkedIn profile](https://www.linkedin.com/in/aapotanskanen/) |
|
- Rasmus Toivanen, [Hugging Face profile](https://huggingface.co/RASMUS), [LinkedIn profile](https://www.linkedin.com/in/rasmustoivanen/) |
|
|
|
## Acknowledgements |
|
|
|
This project would not have been possible without compute generously provided by Google through the |
|
[TPU Research Cloud](https://sites.research.google/trc/). |
|
|
|
|
|
|