File size: 3,244 Bytes
6c43123
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37e824f
6c43123
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6ce2dca
 
 
 
 
 
 
 
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
---
license: llama3
datasets:
- swap-uniba/the_cauldron_ita
language:
- it
base_model:
- meta-llama/Meta-Llama-3-8B
- openai/clip-vit-large-patch14-336
pipeline_tag: text-generation
---

# Model Card for LLaVA-NDiNO_pt_short_it

## Model description

<!-- Provide a quick summary of what the model is/does. -->

**LLaVA-NDiNO** is a family of *Large Vision Language Models (LVLMs)* that have been trained for the Italian language. 

The model was trained by instruction-tuning [**LLaMA 3 8B Base**](https://huggingface.co./meta-llama/Meta-Llama-3-8B) and [**CLIP Large 336**](https://huggingface.co./openai/clip-vit-large-patch14-336) on an Italian machine-translated version of [The Cauldron](HuggingFaceM4/the_cauldron).

If you are interested in more details regarding the training procedure, you can find the code we used at the following link:
- **Repository:** https://github.com/swapUniba/LLaVA-NDiNO

- **Developed by:** Elio Musacchio, Lucia Siciliani, Pierpaolo Basile, Giovanni Semeraro
- **Funded by:** PNRR project FAIR - Future AI Research
- **Compute infrastructure:** [Leonardo](https://www.hpc.cineca.it/systems/hardware/leonardo/) supercomputer
- **Model type:** LLaMA 3 + CLIP
- **Language(s) (NLP):** Italian
- **License:** Llama 3 Community License 
- **Finetuned from model:** [swap-uniba/LLaVA-NDiNO_pt](https://huggingface.co./swap-uniba/LLaVA-NDiNO_pt)


## Example Usage

```python
import torch
import requests

from PIL import Image
from transformers import LlavaNextProcessor, LlavaNextForConditionalGeneration, set_seed

model_name = "swap-uniba/LLaVA-NDiNO_short_it"

processor = LlavaNextProcessor.from_pretrained(model_name)
model = LlavaNextForConditionalGeneration.from_pretrained(model_name, torch_dtype=torch.bfloat16, low_cpu_mem_usage=True, device_map="auto") 

url = "https://www.barnorama.com/wp-content/uploads/2016/12/03-Confusing-Pictures.jpg"
image = Image.open(requests.get(url, stream=True).raw)

chat_template = "{% set loop_messages = messages %}{% for message in loop_messages %}{% set content = '<|start_header_id|>' + message['role'] + '<|end_header_id|>\n\n'+ message['content'] | trim + '<|eot_id|>' %}{% if loop.index0 == 0 %}{% set content = bos_token + content %}{% endif %}{{ content }}{% endfor %}{% if add_generation_prompt %}{{ '<|start_header_id|>assistant<|end_header_id|>\n\n' }}{% endif %}"

conversation = [
    {
        "role": "user",
        "content": "<image>\nCosa c'è di strano in questa immagine?"
    },
]

prompt = processor.apply_chat_template(conversation, chat_template, add_generation_prompt=True)
inputs = processor(prompt, image, return_tensors="pt")

set_seed(42)
output = model.generate(**inputs, max_new_tokens=4096)

print(processor.decode(output[0][inputs.input_ids.shape[1]:]))
```

## Citation

```
@inproceedings{musacchioLLaVANDiNO,
  title={LLaVA-NDiNO: Empowering LLMs with Multimodality for the Italian Language},
  author={Musacchio, Elio and Siciliani, Lucia and Basile, Pierpaolo and Semeraro, Giovanni},
  booktitle={Proceedings of the Eighth Workshop on Natural Language for Artificial Intelligence (NL4AI 2024) co-located with 23th International Conference of the Italian Association for Artificial Intelligence (AI*IA 2024)},
  year={2024}
}
```