File size: 4,343 Bytes
92e3d0d
 
2a408a5
 
92e3d0d
2a408a5
 
05cceac
2a408a5
 
 
 
 
 
 
 
 
 
 
 
 
7c8c7e2
2a408a5
ed52f5b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26cc4d0
 
 
 
 
 
 
 
 
 
 
 
3f06f13
e2d7b27
 
3f06f13
26cc4d0
3f06f13
26cc4d0
 
 
 
 
 
 
 
 
 
 
 
ed52f5b
d40e334
 
 
 
 
 
d317869
d40e334
 
4e19440
37e5262
d40e334
2a408a5
 
ea7d3da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
---
license: cc-by-sa-4.0
language:
- pl
---
# Model Card for Krakowiak-v2-7b

Krakowiak-v2-7b is a state of the art 7.3 billion parameters LLM based on Mistral-7B. It was finetuned for Polish text generation using custom created large corpus of 300K Polish instructions. It uses novel techniques e.g. LORA, adding noise to the embeddings for greater preformance. For full details of this model please read our [paper to be released soon](www.example.come)

## Model Architecture

Krakowiak-v2-7b is a huge update to [Krakowiak-7b](https://huggingface.co/szymonrucinski/krakowiak-7b) bringing the following improvements:
- Grouped-Query Attention
- Sliding-Window Attention
- Byte-fallback BPE tokenizer
- Significantly larger training corpus of better quality
- Improved training pipeline
- Faster inference
- No random token generation (generating Russian or Czech text alongside Polish)
- Significantly higher quality of generated text

Krakowiak does not have any censorship mechanisms implemented.

## Instruction format

In order to leverage instruction fine-tuning, your prompt should be surrounded by `[INST]` and `[/INST]` tokens. The very first instruction should begin with a begin of sentence id. The next instructions should not. The assistant generation will be ended by the end-of-sentence token id.

E.g.
```
text = "<s>[INST] Czy warto się uczyć? [/INST]"
"Jako model języka AI nie mam osobistych opinii ani przekonań. Jednak uczanie się jest ogólnie cenione i angażuje długoterminowe korzyści dla jednostki i społeczeństwa. Dzięki nauce można opracować umiejętności, zdobąć wiedzę i zwiększyć potencjał osobisty i zawodowy. Ponadto nauka promuje otwartość na innowacje i może zapewnić lepszą perspektywę życia. Dlatego uczanie się jest ogólnie cenione i wartościowe dla osób, które chcą osiągnąć cel lub rozwinąć swoją wiedzę. Jednak każda sytuacja może być inna i niektóre osoby mogą mieć różne cele lub okoliczności, które wpływają na ich podejście do nauki. Ostatecznie zależy to od indywidualnych preferencji i celów.</s> "
"[INST] Gdzie warto się uczyć? [/INST]"
```

## Model parameters

From my experience the temperature value of 0.7 is the best baseline value.

## Optimal text generation
```
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
import torch
torch_device = "cuda" if torch.cuda.is_available() else "cpu"

chat_tokenizer = AutoTokenizer.from_pretrained("mistralai/Mistral-7B-Instruct-v0.1")
messages = [
    {"role": "user", "content": "Czy warto nauczyć się jeździć na nartach w wieku 25 lat?"},
]
chat_tokenized = tokenizer.apply_chat_template(messages, tokenize=False)

model = AutoModelForCausalLM.from_pretrained("szymonrucinski/Krakowiak-7B-v2")
model.config.pad_token_id = model.config.eos_token_id

tokenizer = AutoTokenizer.from_pretrained("szymonrucinski/Krakowiak-7B-v2",add_eos_token=True)
tokenizer.pad_token = tokenizer.eos_token
model_inputs = tokenizer(chat_tokenized, return_tensors='pt').to(torch_device)

beam_outputs = model.generate(
    **model_inputs,
    max_new_tokens=1024,
    num_beams=5,
    no_repeat_ngram_size=2,
    num_return_sequences=1,
    early_stopping=True
)
print(tokenizer.decode(beam_outputs[0], skip_special_tokens=True))

```

## Use a pipeline as a high-level helper
```
from transformers import pipeline

pipe = pipeline("text-generation", model="szymonrucinski/krakowiak-v2-7b")

pipe("<s>[INST] Też lubisz jeździć na rowerze? [/INST]")
```

## Demo
You can play with Krakowiak-v2-7b [here](https://huggingface.co/spaces/szymonrucinski/krakowiak). This model uses 4-bit quantization technique and CPU inference that negatively influence the quality of the output but are more cost effective. You can run Krakowiak on your CPU using its quantized version availabe [here](https://huggingface.co/szymonrucinski/krakowiak-v2-7b-gguf)

## Krakowiak team
 
[Szymon Franciszek Ruciński](https://szymonrucinski.pl)


## Citation

If you find the content of this repo useful in your work, please cite it as follows:

```bibtex
@misc{Krakowiak-V2-7B,
  author = {Szymon Ruciński},
  title = {Krakowiak-V2-7B},
  year = {2023},
  publisher = {Huggingface},
  journal = {Huggingface repository},
  howpublished = {\url{https://huggingface.co/szymonrucinski/krakowiak-v2-7b/}}
}