readme; materials
Browse files- README.md +111 -1
- assets/phi_35_mini_ita.png +0 -0
- training_args.bin +0 -3
README.md
CHANGED
@@ -1,7 +1,117 @@
|
|
1 |
---
|
2 |
license: mit
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
library_name: transformers
|
4 |
pipeline_tag: text-generation
|
|
|
|
|
|
|
|
|
|
|
5 |
---
|
6 |
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
license: mit
|
3 |
+
datasets:
|
4 |
+
- mlabonne/FineTome-100k
|
5 |
+
- efederici/capybara-claude-15k-ita
|
6 |
+
language:
|
7 |
+
- it
|
8 |
+
- en
|
9 |
library_name: transformers
|
10 |
pipeline_tag: text-generation
|
11 |
+
base_model: microsoft/Phi-3.5-mini-instruct
|
12 |
+
tags:
|
13 |
+
- trl
|
14 |
+
- phi3
|
15 |
+
- spectrum
|
16 |
---
|
17 |
|
18 |
+
<img src="./assets/phi_35_mini_ita.png" width="450"></img>
|
19 |
+
# Phi-3.5-mini-ITA
|
20 |
+
|
21 |
+
Fine-tuned version of [Microsoft/Phi-3.5-mini-instruct](https://huggingface.co/microsoft/Phi-3.5-mini-instruct) optimized for better performance in Italian.
|
22 |
+
|
23 |
+
- Small yet powerful model with 3.82 billion parameters
|
24 |
+
- Supports 128k context length
|
25 |
+
|
26 |
+
[๐ฌ๐ฎ๐น Chat with the model on Hugging Face Spaces](https://huggingface.co/spaces/anakin87/Phi-3.5-mini-ITA)
|
27 |
+
|
28 |
+
## ๐ Evaluation
|
29 |
+
|
30 |
+
| Model | Parameters | Average | MMLU_IT | ARC_IT | HELLASWAG_IT |
|
31 |
+
| ------------------------------------- | ---------- | ------- | ------- | ------ | ------------ |
|
32 |
+
| **anakin87/Phi-3.5-mini-ITA** | **3.82 B** |**57.67** | 59.93 | 51.5 | 61.57 |
|
33 |
+
| meta-llama/Meta-Llama-3.1-8B-Instruct | 8.03 B | 56.97 | 58.43 | 48.42 | 64.07 |
|
34 |
+
| microsoft/Phi-3.5-mini-instruct | 3.82 B | 56.82 | 60.03 | 49.19 | 61.25 |
|
35 |
+
|
36 |
+
For a detailed comparison of model performance, check out the [Leaderboard for Italian Language Models](https://huggingface.co/spaces/FinancialSupport/open_ita_llm_leaderboard).
|
37 |
+
|
38 |
+
## ๐ฎ Model in action
|
39 |
+
### Demo
|
40 |
+
[๐ฌ๐ฎ๐น Chat with the model on Hugging Face Spaces](https://huggingface.co/spaces/anakin87/Phi-3.5-mini-ITA)
|
41 |
+
|
42 |
+
### Text generation with Transformers
|
43 |
+
The model is small, so it runs smoothly on Colab. It is also fine to load the model using quantization.
|
44 |
+
|
45 |
+
With `transformers==4.44.2`, `trust_remote_code=True` is needed to incorporate a minor bug fix in `Phi3ForCausalLM`.
|
46 |
+
Read [this discussion](https://huggingface.co/microsoft/Phi-3.5-mini-instruct/discussions/9) for more details.
|
47 |
+
|
48 |
+
โก *The model is compatible with Flash Attention 2, which accelerates inference. To enable it, uncomment the `attn_implementation` parameter in the code snippet below.*
|
49 |
+
|
50 |
+
```python
|
51 |
+
# pip install transformers accelerate
|
52 |
+
import torch
|
53 |
+
from transformers import pipeline
|
54 |
+
|
55 |
+
model_id="anakin87/Phi-3.5-mini-ITA"
|
56 |
+
|
57 |
+
model = AutoModelForCausalLM.from_pretrained(
|
58 |
+
model_id,
|
59 |
+
device_map="auto",
|
60 |
+
torch_dtype=torch.bfloat16,
|
61 |
+
trust_remote_code=True,
|
62 |
+
# attn_implementation="flash_attention_2", # UNCOMMENT TO USE FLASH ATTENTION 2
|
63 |
+
)
|
64 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
|
65 |
+
|
66 |
+
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
67 |
+
|
68 |
+
user_input = "Puoi spiegarmi brevemente la differenza tra imperfetto e passato prossimo in italiano e quando si usano?"
|
69 |
+
messages = [{"role": "user", "content": user_input}]
|
70 |
+
outputs = pipe(prompt, max_new_tokens=500, do_sample=True, temperature=0.001)
|
71 |
+
print(outputs[0]["generated_text"])
|
72 |
+
```
|
73 |
+
|
74 |
+
Example output:
|
75 |
+
```
|
76 |
+
Certamente! Imperfetto e passato prossimo sono due tempi verbali in italiano che si riferiscono a azioni passate, ma hanno sfumature diverse.
|
77 |
+
|
78 |
+
Imperfetto:
|
79 |
+
- L'imperfetto รจ usato per descrivere azioni o situazioni passate che erano continue o ripetute nel tempo.
|
80 |
+
- Indica un'azione senza una fine specifica o un'azione che si svolgeva abitualmente.
|
81 |
+
- ร spesso usato per descrivere situazioni, condizioni o stati passati.
|
82 |
+
- Esempio: "Quando ero bambino, giocavo spesso nel parco."
|
83 |
+
|
84 |
+
Passato Prossimo:
|
85 |
+
- Il passato prossimo รจ usato per descrivere azioni passate che sono state completate o che hanno avuto una durata specifica.
|
86 |
+
- Indica un'azione che รจ avvenuta in un momento specifico nel passato.
|
87 |
+
- ร spesso usato per descrivere eventi o azioni che hanno una durata definita o che si sono svolte in un momento specifico.
|
88 |
+
- Esempio: "Ieri ho finito il libro."
|
89 |
+
|
90 |
+
In sintesi, l'imperfetto si usa per azioni continue o abituali nel passato, mentre il passato prossimo si usa per azioni completate o avvenute in un momento specifico nel passato.
|
91 |
+
```
|
92 |
+
|
93 |
+
### Build AI applications
|
94 |
+
You can use the model to create a variety of AI applications.
|
95 |
+
|
96 |
+
I recommend using the [๐๏ธ Haystack LLM framework](https://haystack.deepset.ai/) for orchestration.
|
97 |
+
(spoiler: I work on it and it is open-source ๐)
|
98 |
+
|
99 |
+
This model is compatible with [`HuggingFaceLocalGenerator`](https://docs.haystack.deepset.ai/docs/huggingfacelocalgenerator) and [`HuggingFaceLocalChatGenerator`](https://docs.haystack.deepset.ai/docs/huggingfacelocalchatgenerator) components.
|
100 |
+
You can also deploy the model with a TGI container and then use it with [`HuggingFaceAPIGenerator`](https://docs.haystack.deepset.ai/docs/huggingfaceapigenerator) and the related Chat Generator.
|
101 |
+
|
102 |
+
Some examples you can keep inspiration from:
|
103 |
+
- [RAG with local open models](https://haystack.deepset.ai/blog/guide-to-using-zephyr-with-haystack2)
|
104 |
+
- [Summarization from a Website](https://github.com/deepset-ai/haystack-cookbook/blob/main/notebooks/hackernews-custom-component-rag.ipynb)
|
105 |
+
- [Multilingual RAG](https://github.com/deepset-ai/haystack-cookbook/blob/main/notebooks/multilingual_rag_podcast.ipynb)
|
106 |
+
|
107 |
+
|
108 |
+
## ๐ง Training details
|
109 |
+
This model was fine-tuned using HF TRL.
|
110 |
+
It underwent 2 epochs of instruction fine-tuning on the [FineTome-100k](https://huggingface.co/datasets/mlabonne/FineTome-100k) and [Capybara-Claude-15k-ita](https://huggingface.co/datasets/efederici/capybara-claude-15k-ita) datasets. ๐ Thanks to the authors for providing these datasets.
|
111 |
+
|
112 |
+
I adopted a relatively new technique for parameter-efficient learning: [Spectrum](https://arxiv.org/abs/2406.06623).
|
113 |
+
The idea is to train only the layers of the model with high Signal-to-Noise Ratio (SNR) and โ๏ธ freeze the rest.
|
114 |
+
|
115 |
+
Training required about 14 hours on a single A40 GPU.
|
116 |
+
|
117 |
+
I may release a guide/tutorial soon. Stay tuned! ๐ป
|
assets/phi_35_mini_ita.png
ADDED
training_args.bin
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:f8db91a527df06f976282594514f37f0056bf1a300de53b246d08edc3bd90925
|
3 |
-
size 5432
|
|
|
|
|
|
|
|