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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
language:
|
| 4 |
+
- es
|
| 5 |
+
tags:
|
| 6 |
+
- psychology
|
| 7 |
+
- clinical
|
| 8 |
+
- spanish
|
| 9 |
+
- sft
|
| 10 |
+
- axolotl
|
| 11 |
+
base_model:
|
| 12 |
+
- google/gemma-4-E4B-it
|
| 13 |
+
---
|
| 14 |
+
# ALIA-es-gemma-clinical-psychology-sft
|
| 15 |
+
|
| 16 |
+
This repository contains a supervised fine-tuned (SFT) version of the **Gemma 4 E4B IT** model, optimized for Spanish psychological counseling and empathetic therapeutic dialogue.
|
| 17 |
+
|
| 18 |
+
This model is the result of a **Supervised Fine-Tuning (SFT)** process on the [google/gemma-4-E4B-it](https://huggingface.co/google/gemma-4-E4B-it) base model, using a curated multi-turn psychology dataset in Spanish containing professional therapist dialogues.
|
| 19 |
+
|
| 20 |
+
> [!NOTE]
|
| 21 |
+
> This is a **pilot training run** for research purposes. It is not an official release and has not been validated for general deployment.
|
| 22 |
+
|
| 23 |
+
> [!WARNING]
|
| 24 |
+
> **DISCLAIMER:** This model is a domain-specific proof-of-concept for therapeutic guidance and research. It has *NOT* been clinically validated and has not undergone regulatory review.
|
| 25 |
+
> It may produce incorrect, unsafe, or misleading psychological advice. Do not use this model as a substitute for professional therapy, diagnosis, or psychiatric treatment. Always consult a qualified psychologist or healthcare professional.
|
| 26 |
+
|
| 27 |
+
---
|
| 28 |
+
|
| 29 |
+
## Model Details
|
| 30 |
+
|
| 31 |
+
### Description
|
| 32 |
+
This model is a Transformer-based decoder-only language model that builds on the **Gemma 4 E4B IT** architecture through SFT alignment targeted to psychological support in Spanish.
|
| 33 |
+
|
| 34 |
+
**SFT Fine-Tuning:** The model was fine-tuned using Supervised Fine-Tuning (SFT) to align responses with empathetic, active listening strategies. The dataset consists of multi-turn dialogues between patients and therapists, reinforcing safe, validating, and explorative conversational practices.
|
| 35 |
+
|
| 36 |
+
### Architecture
|
| 37 |
+
| | |
|
| 38 |
+
|-------------------------|:--------------|
|
| 39 |
+
| **Base Model** | google/gemma-4-E4B-it |
|
| 40 |
+
| **Architecture** | Dense + PLE (Parameter-Layer-Embedding) |
|
| 41 |
+
| **Total Parameters** | 8,000,000,000 (8B) |
|
| 42 |
+
| **Effective Parameters**| 4,500,000,000 (4.5B) |
|
| 43 |
+
| **Layers** | 42 |
|
| 44 |
+
| **Shared KV cache layers**| 18 |
|
| 45 |
+
| **Context length** | 4,096 (Configured) |
|
| 46 |
+
| **Attention Pattern** | Alternating local sliding-window (512 tokens) and global full-context |
|
| 47 |
+
| **Precision** | bfloat16 |
|
| 48 |
+
| **Flash attention** | ❌ (Disabled) |
|
| 49 |
+
|
| 50 |
+
### Hyperparameters
|
| 51 |
+
| Parameter | Value |
|
| 52 |
+
|---|---:|
|
| 53 |
+
| **Sequence length** | 4,096 |
|
| 54 |
+
| **Sample packing** | false |
|
| 55 |
+
| **Pad to sequence length** | true |
|
| 56 |
+
| **Num. epochs** | 20 |
|
| 57 |
+
| **Save steps** | 40 |
|
| 58 |
+
| **Eval steps** | 20 |
|
| 59 |
+
| **Logging steps** | 5 |
|
| 60 |
+
| **Optimizer** | adamw_torch |
|
| 61 |
+
| **Learning rate** | 5e-5 |
|
| 62 |
+
| **LR scheduler** | cosine |
|
| 63 |
+
| **Warmup ratio** | 0.05 |
|
| 64 |
+
| **Weight decay** | 0.01 |
|
| 65 |
+
| **Micro batch size** | 1 |
|
| 66 |
+
| **Gradient accumulation steps** | 2 |
|
| 67 |
+
| **Gradient checkpointing** | true |
|
| 68 |
+
| **Val set size** | 0.05 |
|
| 69 |
+
| **Seed** | 42 |
|
| 70 |
+
| **BF16** | true |
|
| 71 |
+
| **FP16** | false |
|
| 72 |
+
| **Fine-Tuning Method** | SFT (Supervised Fine-Tuning) |
|
| 73 |
+
| **Adapter** | LoRA |
|
| 74 |
+
| **LoRA R** | 16 |
|
| 75 |
+
| **LoRA Alpha** | 32 |
|
| 76 |
+
| **LoRA Dropout** | 0.05 |
|
| 77 |
+
| **LoRA Target Modules** | `model.language_model.layers.[\d]+.(_checkpoint_wrapped_module.)?(mlp|self_attn).(up|down|gate|q|k|v|o)_proj` |
|
| 78 |
+
|
| 79 |
+
---
|
| 80 |
+
|
| 81 |
+
## Intended Use
|
| 82 |
+
|
| 83 |
+
### Direct Use
|
| 84 |
+
The model is intended for research, development and support applications within **Spanish psychological counseling and active listening** contexts. Representative use cases include:
|
| 85 |
+
- Assisting mental health professionals with drafts or suggestions for empathetic response strategies.
|
| 86 |
+
- Role-playing and scenario training for psychology students.
|
| 87 |
+
- Analysis and study of automated fine-tuning in clinical-adjacent communication settings.
|
| 88 |
+
|
| 89 |
+
### Out-of-scope Use
|
| 90 |
+
This model is not approved for clinical use or autonomous deployment. It must not be used as a primary source for psychological diagnosis, psychiatric treatment decisions, or crisis intervention. Any deployment that impacts patient safety requires extensive validation, risk assessment and regulatory clearance.
|
| 91 |
+
|
| 92 |
+
---
|
| 93 |
+
|
| 94 |
+
## How to use
|
| 95 |
+
|
| 96 |
+
### Python Example
|
| 97 |
+
|
| 98 |
+
```python
|
| 99 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 100 |
+
import torch
|
| 101 |
+
|
| 102 |
+
model_id = "SINAI/ALIA-es-gemma-clinical-psychology-sft"
|
| 103 |
+
|
| 104 |
+
# System prompt used to steer the model towards empathetic therapy
|
| 105 |
+
system_prompt = (
|
| 106 |
+
"Eres un terapeuta psicológico empático y profesional. "
|
| 107 |
+
"Escucha activamente al paciente y responde de forma apropiada, "
|
| 108 |
+
"validando sus emociones y explorando su experiencia."
|
| 109 |
+
)
|
| 110 |
+
|
| 111 |
+
# Example conversation structure (using the Gemma 4 chat template style)
|
| 112 |
+
messages = [
|
| 113 |
+
{"role": "system", "content": system_prompt},
|
| 114 |
+
{"role": "user", "content": "Hola. Pues llevo desde hace mucho sintiendome con mucha ansiedad por basicamente casi todo"}
|
| 115 |
+
]
|
| 116 |
+
|
| 117 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 118 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 119 |
+
model_id,
|
| 120 |
+
device_map="auto",
|
| 121 |
+
torch_dtype=torch.bfloat16
|
| 122 |
+
)
|
| 123 |
+
|
| 124 |
+
# Apply the chat template
|
| 125 |
+
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
| 126 |
+
|
| 127 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 128 |
+
outputs = model.generate(**inputs, max_new_tokens=200)
|
| 129 |
+
|
| 130 |
+
# Decode the generated tokens (skipping the prompt part)
|
| 131 |
+
generated_tokens = outputs[0][inputs.input_ids.shape[1]:]
|
| 132 |
+
print(tokenizer.decode(generated_tokens, skip_special_tokens=True))
|
| 133 |
+
```
|
| 134 |
+
|
| 135 |
+
---
|
| 136 |
+
|
| 137 |
+
## Data
|
| 138 |
+
|
| 139 |
+
### SFT Fine-Tuning Data
|
| 140 |
+
> [!NOTE]
|
| 141 |
+
> **Data Availability:** The dataset used for training is publicly available on Hugging Face at [SINAI/ALIA-es-clinical-psychology-dialogues](https://huggingface.co/datasets/SINAI/ALIA-es-clinical-psychology-dialogues).
|
| 142 |
+
|
| 143 |
+
To adapt the model to empathetic psychological counseling in Spanish we used the following resource:
|
| 144 |
+
|
| 145 |
+
* **Supervised Fine-Tuning (SFT)**
|
| 146 |
+
* **Dataset:** `ALIA-es-clinical-psychology-dialogues.jsonl` (containing 67 multi-turn sessions)
|
| 147 |
+
* **Description:** A multi-turn dataset structured with a `conversations` history. The target responses (`assistant`) are human-curated/edited therapist dialogues that prioritize validation, empathy, active listening, and safe, explorative therapeutic interaction in Spanish.
|
| 148 |
+
|
| 149 |
+
---
|
| 150 |
+
|
| 151 |
+
## Additional Information
|
| 152 |
+
|
| 153 |
+
### License
|
| 154 |
+
[Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0)
|
| 155 |
+
|
| 156 |
+
### Citation
|
| 157 |
+
```bibtex
|
| 158 |
+
@misc{ALIA-es-gemma-clinical-psychology-sft,
|
| 159 |
+
title={ALIA-es-gemma-clinical-psychology-sft: Empathetic Psychology SFT Model for Spanish},
|
| 160 |
+
author={SINAI Research Group},
|
| 161 |
+
year={2026},
|
| 162 |
+
publisher={HuggingFace},
|
| 163 |
+
howpublished={\url{https://huggingface.co/SINAI/ALIA-es-gemma-clinical-psychology-sft}}
|
| 164 |
+
}
|
| 165 |
+
```
|
| 166 |
+
|
| 167 |
+
Please also cite the base model and family:
|
| 168 |
+
|
| 169 |
+
```bibtex
|
| 170 |
+
@misc{gemma4_2026,
|
| 171 |
+
title={Gemma 4: Open Weights Multimodal Models},
|
| 172 |
+
author={Google DeepMind},
|
| 173 |
+
year={2026},
|
| 174 |
+
url={https://deepmind.google/gemma}
|
| 175 |
+
}
|
| 176 |
+
```
|
| 177 |
+
|
| 178 |
+
### Funding
|
| 179 |
+
This work is funded by the Ministerio para la Transformación Digital y de la Función Pública - Funded by EU – NextGenerationEU within the framework of the project [ALIA](https://alia.gob.es).
|
| 180 |
+
|
| 181 |
+
---
|
| 182 |
+
|
| 183 |
+
**Contact:** [ALIA Project](https://www.alia.gob.es/) - [SINAI Research Group](https://sinai.ujaen.es) - [Universidad de Jaén](https://www.ujaen.es/)
|
| 184 |
+
|
| 185 |
+
**More Information:** [SINAI Research Group](https://sinai.ujaen.es) | [ALIA-UJA Project](https://github.com/sinai-uja)
|
| 186 |
+
|