Text Generation
Transformers
PyTorch
Italian
Inference Endpoints
File size: 5,573 Bytes
3d675db
 
82d6f1a
f22b3d4
 
 
 
92a070a
cfe9269
92a070a
 
d0c39e4
92a070a
 
 
 
d0c39e4
 
8be35b4
92a070a
d0c39e4
92a070a
 
d0c39e4
 
 
8e3327b
8be35b4
92a070a
 
 
 
 
ab03ec0
92a070a
 
 
ab03ec0
92a070a
ab03ec0
 
92a070a
 
ab03ec0
 
92a070a
ab03ec0
 
92a070a
ab03ec0
 
92a070a
ab03ec0
 
92a070a
ab03ec0
 
92a070a
ab03ec0
 
 
 
 
 
 
92a070a
ab03ec0
 
 
 
92a070a
ab03ec0
 
 
92a070a
ab03ec0
 
92a070a
ab03ec0
 
92a070a
ab03ec0
 
 
92a070a
ab03ec0
 
 
 
92a070a
ab03ec0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92a070a
 
 
 
 
 
8be35b4
92a070a
 
 
 
 
d0c39e4
92a070a
 
 
 
d0c39e4
 
92a070a
d0c39e4
92a070a
d0c39e4
92a070a
d0c39e4
92a070a
d0c39e4
 
 
 
 
 
92a070a
d0c39e4
 
 
 
 
 
92a070a
 
 
 
 
 
 
 
d0c39e4
 
 
 
92a070a
 
cfe9269
ab03ec0
92a070a
d0c39e4
92a070a
 
 
d0c39e4
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
---
license: other
pipeline_tag: text-generation
datasets:
- cosimoiaia/Loquace-102k
language:
- it
---
# Model Card for Model raicrits/OpenLLama13b_Loquace_ITA

<!-- Provide a quick summary of what the model is/does. -->
An open-source LLaMa language model of 13b parameters fine-tuned to follow instructions in italian.


### Model Description

This model is an open-source LLM of 13b parameters based on [OpenLLaMA](https://github.com/openlm-research/open_llama), an open-source replica of Meta AI's LLaMA.
The model was fine-tuned in order to follow instructions, as proposed in [Alpaca](https://github.com/tatsu-lab/stanford_alpaca), 
but using [LoRA](https://arxiv.org/pdf/2106.09685.pdf) technique and a bigger dataset of instruction/answers in italian, [cosimoiaia/Loquace-102k](https://huggingface.co/datasets/cosimoiaia/Loquace-102k/viewer/cosimoiaia--Loquace-102k).

This repository contains the model merged with the LoRA adapters obtained in the fine-tuning procedure.


- **Developed by:** Stefano Scotta (stefano.scotta@rai.it)
- **Model type:** LLM fine-tuned to follow instructions
- **Language(s) (NLP):** Italian
- **License:** Other
- **Finetuned from model:** [openlm-research/open_llama_13b](https://huggingface.co/openlm-research/open_llama_13b)


## Uses

<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
The model can be used as is to respond to simple instructions in Italian or can be further fine-tuned to perform specific tasks.



## Bias, Risks, and Limitations

<!-- This section is meant to convey both technical and sociotechnical limitations. -->
As any other LLM it is possible that the model generates content which does not correspond to the reality as well as wrong, biased, offensive and inappropriate answers.


## How to Get Started with the Model
 **Prompt template:**

 ``` python
"Di seguito è riportata un'istruzione che descrive un compito, abbinata a un input che fornisce un ulteriore contesto. Scrivete una risposta che completi in modo appropriato la richiesta.

### Istruzione:
{instruction}

### Input:
{input}

### Risposta:"
```

 **Usage:**
Use the code below to get started with the model.
 ``` python
import os
import torch
import sys
from transformers import LlamaTokenizer, LlamaForCausalLM

if torch.cuda.is_available():
    device = "cuda"
else:
    device = "cpu"

def generate_prompt(instruction, input=None):
    if input:
        return f"""Di seguito è riportata un'istruzione che descrive un compito, abbinata a un input che fornisce un ulteriore contesto. Scrivete una risposta che completi in modo appropriato la richiesta.

### Istruzione:
{instruction}

### Input:
{input}

### Risposta:"""
    else:
        return f"""Di seguito è riportata un'istruzione che descrive un compito. Scrivete una risposta che completi in modo appropriato la richiesta..

### Istruzione:
{instruction}

### Risposta:"""

model_name = "raicrits/OpenLLama13b_Loquace_ITA"

model = LlamaForCausalLM.from_pretrained(
    model_name,
    torch_dtype=torch.float16,
    device_map="auto"
)

tokenizer = LlamaTokenizer.from_pretrained(model_name)

instruction = "qual'è la relazione tra i seguenti oggetti"
input = "sedia, tavolo, divano"
prompt = generate_prompt("instruction", input)
inputs = tokenizer(prompt, return_tensors="pt")
input_ids = inputs["input_ids"].to(device)

generation_output = model.generate(
    input_ids=input_ids,
    max_new_tokens=256,
)


output = tokenizer.decode(generation_output[0])
output = output.split("### Risposta:")[1].strip().replace("</s>","")
print(output)
```
``` python
"Sedia, tavolo e divano sono tutti oggetti che possono essere utilizzati per creare un'atmosfera rilassante in una stanza."
```

## Training Details

### Training Data

<!-- This should link to a Data Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
The model was fine-tinuned on [cosimoiaia/Loquace-102k](https://huggingface.co/datasets/cosimoiaia/Loquace-102k/viewer/cosimoiaia--Loquace-102k), a dataset of 102k question/answer pairs in italian.


### Training Procedure 

<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
The fine-tuning procedure was done using [LoRA](https://arxiv.org/pdf/2106.09685.pdf) approach following closely what done for fine-tuning models like [Alpaca-LoRA](https://github.com/tloen/alpaca-lora).


#### Training Hyperparameters

 **Training setting:**
- train epochs=3,

- learning_rate=3e-4,

- optimizer="adamw_hf"

- mixed precision training: float16 

 **LoRA configuration:**
-  r= 8
  
- lora_alpha=16
  
- target_modules=["q_proj","v_proj"]

- lora_dropout=0.05
  
- bias="none"
  
- task_type=TaskType.CAUSAL_LM
  


## Environmental Impact

<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->

Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).

- **Hardware Type:** 1 NVIDIA A100/40Gb
- **Hours used:** 68
- **Cloud Provider:** Private Infrastructure
- **Carbon Emitted:** 7.34 kg eq. CO2



## Model Card Authors

Stefano Scotta (stefano.scotta@rai.it)

## Model Card Contact

stefano.scotta@rai.it