--- base_model: google/gemma-3-1b-it library_name: peft license: gemma language: - it pipeline_tag: text-generation tags: - lira - lora - peft - gguf - personal-finance - retrieval-augmented-generation - readability - italian --- # LIRA — Gemma 3 1B, Italian Italian personal-finance question answering, grounded in material published by CONSOB, that **writes the same answer at three different reading levels**. Design label: `gemma3-1b_ita_siaddestr_sipar_3reg` — trained with the retrieved paragraphs in the prompt and with all three registers. This is the deployed configuration of the LIRA system. ## What is in this repository | file | what it is | size | |---|---|---| | `adapter_model.safetensors` + `adapter_config.json` | the LoRA adapter for `google/gemma-3-1b-it` | 26 MB | | `lira-gemma3-1b-ita-sipar-3reg-Q8_0.gguf` | base model with the adapter merged in, 8-bit | 1069 MB | | `lira-gemma3-1b-ita-sipar-3reg-Q4_K_M.gguf` | the same, 4-bit — about half the space, for phones | 806 MB | The two GGUF files are the same model, only quantised differently. Pick Q8_0 unless memory is tight. ## How to prompt it — read this first The adapter is trained for retrieval-augmented use and **will not behave correctly without the retrieved passages**. Every training example carries six passages in the system prompt, so it has to be prompted the same way: ``` Sei un assistente di finanza personale. L'utente ha conoscenze di finanza intermedie. Puoi introdurre alcuni termini tecnici, ma sempre accompagnati da una spiegazione. REGOLE: Rispondi SOLO usando i documenti seguenti. Non inventare. Non dare consigli specifici di investimento. Rispondi in italiano in modo conciso. DOCUMENTO []: DOCUMENTO []: ... sei in tutto ... ``` followed by the user's question as a normal user turn. The sentence about the reader's level is what selects the register. There are three, and they are the exact strings the model was trained on: | register | sentence | |---|---| | `base` | L'utente ha conoscenze base di finanza. Usa spiegazioni semplici e esempi pratici. Evita termini tecnici o complessi. | | `intermediate` | L'utente ha conoscenze di finanza intermedie. Puoi introdurre alcuni termini tecnici, ma sempre accompagnati da una spiegazione. | | `advanced` | L'utente ha conoscenze avanzate di finanza personale. Evita spiegazioni eccessivamente basilari, puoi usare termini tecnici e spiegazioni più approfondite. | Swap that sentence and the same question comes back rewritten for that reader — shorter and plainer for `base`, roughly three times longer for `advanced`. ## Quick start With `llama.cpp` (4-bit): ```bash llama-server -hf Stee201/lira-gemma3-1b-ita-sipar-3reg:Q4_K_M ``` With `transformers` + `peft` (the adapter on top of the base model): ```python from transformers import AutoModelForCausalLM, AutoTokenizer from peft import PeftModel base = "google/gemma-3-1b-it" model = AutoModelForCausalLM.from_pretrained(base, dtype="float16", device_map="auto") model = PeftModel.from_pretrained(model, "Stee201/lira-gemma3-1b-ita-sipar-3reg") tok = AutoTokenizer.from_pretrained(base) messages = [ {"role": "system", "content": system_prompt_with_six_passages}, {"role": "user", "content": question}, ] ids = tok.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt") print(tok.decode(model.generate(ids.to(model.device), max_new_tokens=512)[0])) ``` Retrieval in the paper is plain BM25 Okapi over 522 CONSOB paragraphs, top 6 — the same retriever at training and at serving time. ## How well it does | register | correctness | groundedness | |---|---|---| | base | 2.83 | 4.21 | | intermediate | 3.35 | 4.77 | | advanced | 2.86 | 3.95 | Judge: `Unbabel/M-Prometheus-14B`, 1–5, on 174 held-out questions that appear nowhere in training. Without the retrieved passages, correctness at `intermediate` drops to **1.92** (from 3.35): the model is trained to compose its answer out of the documents, so it depends on them. Groundedness at `advanced` is lower than at `intermediate` across all six models. That is a property of the register, not invention: of the words used in the answers the judge marked down, only ~1.6% appear in none of the six passages — the same share as in the answers it approved. ## Training LoRA rank 8, alpha 16, dropout 0.05, on the attention and feed-forward projections, loss on the answer tokens only. 4 epochs, learning rate 5e-5, checkpoint chosen by lowest validation loss. Passage order is shuffled per example and per epoch. Training examples are byte-for-byte identical in shape to what the server sends (persona + level instruction + six documents + question); the `base` and `advanced` variants of each answer were generated by a language model constrained to rephrase only the aligned source paragraph, then filtered by six automatic checks. ## Limitations - **It needs its passages.** Correctness without them is far below the numbers above. - It is grounded in CONSOB material only, and answers nothing outside it. - It gives no specific investment advice, by construction, and must not be used as financial advice. - The judge is a model (`M-Prometheus-14B`), not a human panel. ## The other five models - [`Stee201/lira-gemma3-270m-ita-sipar-3reg`](https://huggingface.co/Stee201/lira-gemma3-270m-ita-sipar-3reg) — Gemma 3 270M, Italian - [`Stee201/lira-gemma3-270m-ing-sipar-3reg`](https://huggingface.co/Stee201/lira-gemma3-270m-ing-sipar-3reg) — Gemma 3 270M, English - [`Stee201/lira-gemma3-1b-ing-sipar-3reg`](https://huggingface.co/Stee201/lira-gemma3-1b-ing-sipar-3reg) — Gemma 3 1B, English - [`Stee201/lira-smollm3-3b-ita-sipar-3reg`](https://huggingface.co/Stee201/lira-smollm3-3b-ita-sipar-3reg) — SmolLM3 3B, Italian - [`Stee201/lira-smollm3-3b-ing-sipar-3reg`](https://huggingface.co/Stee201/lira-smollm3-3b-ing-sipar-3reg) — SmolLM3 3B, English The GGUF files contain Gemma 3 weights with the adapter merged in, so they are governed by the [Gemma Terms of Use](https://ai.google.dev/gemma/terms) and the [Prohibited Use Policy](https://ai.google.dev/gemma/prohibited_use_policy), which carry over to anyone who downloads them. The LoRA adapter alone is our own work. Replaces [`Stee201/gemma3-1b-finance-it`](https://huggingface.co/Stee201/gemma3-1b-finance-it), which held the same adapter under the older naming and only the 8-bit file.