Downloads · 30 days
13
6% of all-time downloads
popkek00/flan-t5-base-valutazione-cadute-flat
flan-t5-base-valutazione-cadute-flat is a machine learning model from popkek00. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
Downloads · 30 days
13
6% of all-time downloads
All-time downloads
214
Public
Parameters
248M
20.8 GB on disk
Likes
0
Public
Click a slice to open those files.
.pt2 GB · 50%
From the Hugging Face model README
pip install accelerate transformers torch
import torch
from transformers import T5Tokenizer, T5ForConditionalGeneration
import json
# Load model and tokenizer
tokenizer = T5Tokenizer.from_pretrained("popkek00/flan-t5-base-valutazione-cadute-flat")
model = T5ForConditionalGeneration.from_pretrained(
"popkek00/flan-t5-base-valutazione-cadute-flat",
device_map="auto",
torch_dtype=torch.float16
)
# Inference function
MAX_LENGTH = 1024
def make_infer_fn(m):
def fn(text):
inputs = tokenizer(
text,
return_tensors="pt",
max_length=MAX_LENGTH,
truncation=True
).to(m.device)
with torch.no_grad():
out = m.generate(**inputs, max_new_tokens=MAX_LENGTH, do_sample=False)
return tokenizer.decode(out[0], skip_special_tokens=True)
return fn
fn = make_infer_fn(model)
# ------------------------------------------------------------------
# Example message (system + user + assistant)
# The system contains the empty schema, the assistant contains the filled one.
# ------------------------------------------------------------------
example = {
'messages': '[{"role": "system", "content": "{\\"sessione\\": \\"Valutazione infermieristica iniziale\\", \\"ambito\\": \\"Assistenza infermieristica\\", \\"dati_valutazione\\": {\\"atteggiamento\\": [], \\"respiro\\": {\\"valore\\": [], \\"descrizione_altro\\": \\"\\"}, \\"stato_coscienza\\": {\\"stato\\": [], \\"disorientamento\\": []}, \\"circolo_venoso_e_arterioso\\": {\\"valore\\": [], \\"descrizione_altro\\": \\"\\"}, \\"alvo\\": [], \\"diuresi\\": {\\"valore\\": [], \\"dispositivo\\": [], \\"catetere_fr\\": \\"\\", \\"ultima_sostituzione\\": \\"\\"}, \\"comunicazione\\": {\\"valore\\": [], \\"alterata_da\\": [], \\"lingua\\": []}, \\"alimentazione_idratazione\\": {\\"valore\\": [], \\"dieta\\": \\"\\"}, \\"mobilizzazione\\": [], \\"cute_e_mucose\\": {\\"valore\\": [], \\"lesioni_da_pressione\\": {\\"presenza\\": [], \\"sede\\": \\"\\", \\"stadio\\": \\"\\"}, \\"stomia\\": []}, \\"dolore\\": {\\"presenza\\": [], \\"sede\\": \\"\\", \\"intensita\\": []}, \\"condizioni_igieniche\\": [], \\"sonno_riposo\\": [], \\"situazione_sociale\\": {\\"vive_solo\\": [], \\"supporto\\": [], \\"caregiver\\": []}}}"}, {"role": "user", "content": "Paziente sofferente, confuso nella spazi, comunicazione alterata da patologia in lingua italiana, diuresi regolare, mobilizzazione totalmente dipendente, condizioni igieniche buone."}, {"role": "assistant", "content": "{\\"sessione\\": \\"Valutazione infermieristica iniziale\\", \\"ambito\\": \\"Assistenza infermieristica\\", \\"dati_valutazione\\": {\\"atteggiamento\\": [\\"SOFFERENTE\\"], \\"respiro\\": {\\"valore\\": [], \\"descrizione_altro\\": \\"\\"}, \\"stato_coscienza\\": {\\"stato\\": [\\"CONFUSO\\"], \\"disorientamento\\": [\\"SPAZIO\\"]}, \\"circolo_venoso_e_arterioso\\": {\\"valore\\": [], \\"descrizione_altro\\": \\"\\"}, \\"alvo\\": [], \\"diuresi\\": {\\"valore\\": [\\"REGOLARE\\"], \\"dispositivo\\": [], \\"catetere_fr\\": \\"\\", \\"ultima_sostituzione\\": \\"\\"}, \\"comunicazione\\": {\\"valore\\": [\\"ALTERATA\\"], \\"alterata_da\\": [\\"PATOLOGIA\\"], \\"lingua\\": [\\"ITALIANA\\"]}, \\"alimentazione_idratazione\\": {\\"valore\\": [], \\"dieta\\": \\"\\"}, \\"mobilizzazione\\": [\\"TOTALMENTE_DIPENDENTE\\"], \\"cute_e_mucose\\": {\\"valore\\": [], \\"lesioni_da_pressione\\": {\\"presenza\\": [], \\"sede\\": \\"\\", \\"stadio\\": \\"\\"}, \\"stomia\\": []}, \\"dolore\\": {\\"presenza\\": [], \\"sede\\": \\"\\", \\"intensita\\": []}, \\"condizioni_igieniche\\": [\\"BUONE\\"], \\"sonno_riposo\\": [], \\"situazione_sociale\\": {\\"vive_solo\\": [], \\"supporto\\": [], \\"caregiver\\": []}}}"}]',
'quality': 'perfect',
'user_token_count': 45,
'model': 'LongCat-Flash-Lite',
'generation_time_s': 49.21
}
# ------------------------------------------------------------------
# Helper: flatten nested JSON (dot notation)
# ------------------------------------------------------------------
def flatten_json(nested: dict) -> dict:
"""
{"dati_valutazione": {"respiro": {"valore": ["APNEA"]}}}
→ {"respiro.valore": ["APNEA"]}
"""
flat = {}
def _flatten(obj, prefix):
if isinstance(obj, dict):
for key, value in obj.items():
new_key = f"{prefix}.{key}" if prefix else key
if isinstance(value, dict):
_flatten(value, new_key)
else:
flat[new_key] = value
else:
flat[prefix] = obj
_flatten(nested, "")
return flat
# ------------------------------------------------------------------
# Parse example and build the exact input string the model expects
# ------------------------------------------------------------------
def parse_and_flatten(example):
"""
Extract system, user, assistant from the messages list,
flatten both schemas, and return:
input_text: "scheda: <flattened_system> input: <user_content>"
target_text: <flattened_assistant> (for reference)
"""
try:
msgs = json.loads(example["messages"])
if isinstance(msgs, dict) and "messages" in msgs:
msgs = msgs["messages"]
if not isinstance(msgs, list) or len(msgs) != 3:
return {"input_text": None, "target_text": None, "is_valid": False}
system_content = next(m["content"] for m in msgs if m["role"] == "system")
user_content = next(m["content"] for m in msgs if m["role"] == "user")
assistant_content = next(m["content"] for m in msgs if m["role"] == "assistant")
# The system content may have a prefix "Scheda attuale: " – strip it
prefix = "Scheda attuale: "
sys_json_str = system_content[system_content.index(prefix) + len(prefix):] if prefix in system_content else system_content
sys_json = json.loads(sys_json_str)
assist_json = json.loads(assistant_content)
# Extract the "dati_valutazione" part (or use whole if missing)
sys_dv = sys_json.get("dati_valutazione", sys_json)
assist_dv = assist_json.get("dati_valutazione", assist_json)
sys_flat = flatten_json(sys_dv)
assist_flat = flatten_json(assist_dv)
# Build the exact input for the model
input_text = f"scheda: {json.dumps(sys_flat, ensure_ascii=False)} input: {user_content}"
target_text = json.dumps(assist_flat, ensure_ascii=False)
return {"input_text": input_text, "target_text": target_text, "is_valid": True}
except Exception as e:
return {"input_text": None, "target_text": None, "is_valid": False}
# ------------------------------------------------------------------
# Run the model
# ------------------------------------------------------------------
inp = parse_and_flatten(example)
if inp["is_valid"]:
print("📝 Input to model:")
print(inp["input_text"])
print("\n🤖 Model output:")
print(fn(inp["input_text"]))
else:
print("Error parsing example.")
The model expects input in the format:
scheda: {<flattened JSON>} input: <free text>
where the flattened JSON uses dot notation (e.g., "respiro.valore": ["APNEA"]).
The parse_and_flatten function transforms your conversation example into that exact format. You can use it to prepare any new input as well.
The target output is the full flattened JSON (all fields, including empty ones) – the model is trained to output the complete schema.