File size: 7,370 Bytes
70ba45f | 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 181 182 183 184 185 186 187 | ---
license: apache-2.0
language:
- es
tags:
- psychology
- clinical
- spanish
- sft
- axolotl
base_model:
- google/gemma-4-E4B-it
---
# ALIA-es-gemma-clinical-psychology-sft
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.
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.
> [!NOTE]
> This is a **pilot training run** for research purposes. It is not an official release and has not been validated for general deployment.
> [!WARNING]
> **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.
> 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.
---
## Model Details
### Description
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.
**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.
### Architecture
| | |
|-------------------------|:--------------|
| **Base Model** | google/gemma-4-E4B-it |
| **Architecture** | Dense + PLE (Parameter-Layer-Embedding) |
| **Total Parameters** | 8,000,000,000 (8B) |
| **Effective Parameters**| 4,500,000,000 (4.5B) |
| **Layers** | 42 |
| **Shared KV cache layers**| 18 |
| **Context length** | 4,096 (Configured) |
| **Attention Pattern** | Alternating local sliding-window (512 tokens) and global full-context |
| **Precision** | bfloat16 |
| **Flash attention** | ❌ (Disabled) |
### Hyperparameters
| Parameter | Value |
|---|---:|
| **Sequence length** | 4,096 |
| **Sample packing** | false |
| **Pad to sequence length** | true |
| **Num. epochs** | 20 |
| **Save steps** | 40 |
| **Eval steps** | 20 |
| **Logging steps** | 5 |
| **Optimizer** | adamw_torch |
| **Learning rate** | 5e-5 |
| **LR scheduler** | cosine |
| **Warmup ratio** | 0.05 |
| **Weight decay** | 0.01 |
| **Micro batch size** | 1 |
| **Gradient accumulation steps** | 2 |
| **Gradient checkpointing** | true |
| **Val set size** | 0.05 |
| **Seed** | 42 |
| **BF16** | true |
| **FP16** | false |
| **Fine-Tuning Method** | SFT (Supervised Fine-Tuning) |
| **Adapter** | LoRA |
| **LoRA R** | 16 |
| **LoRA Alpha** | 32 |
| **LoRA Dropout** | 0.05 |
| **LoRA Target Modules** | `model.language_model.layers.[\d]+.(_checkpoint_wrapped_module.)?(mlp|self_attn).(up|down|gate|q|k|v|o)_proj` |
---
## Intended Use
### Direct Use
The model is intended for research, development and support applications within **Spanish psychological counseling and active listening** contexts. Representative use cases include:
- Assisting mental health professionals with drafts or suggestions for empathetic response strategies.
- Role-playing and scenario training for psychology students.
- Analysis and study of automated fine-tuning in clinical-adjacent communication settings.
### Out-of-scope Use
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.
---
## How to use
### Python Example
```python
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
model_id = "SINAI/ALIA-es-gemma-clinical-psychology-sft"
# System prompt used to steer the model towards empathetic therapy
system_prompt = (
"Eres un terapeuta psicológico empático y profesional. "
"Escucha activamente al paciente y responde de forma apropiada, "
"validando sus emociones y explorando su experiencia."
)
# Example conversation structure (using the Gemma 4 chat template style)
messages = [
{"role": "system", "content": system_prompt},
{"role": "user", "content": "Hola. Pues llevo desde hace mucho sintiendome con mucha ansiedad por basicamente casi todo"}
]
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
device_map="auto",
torch_dtype=torch.bfloat16
)
# Apply the chat template
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
outputs = model.generate(**inputs, max_new_tokens=200)
# Decode the generated tokens (skipping the prompt part)
generated_tokens = outputs[0][inputs.input_ids.shape[1]:]
print(tokenizer.decode(generated_tokens, skip_special_tokens=True))
```
---
## Data
### SFT Fine-Tuning Data
> [!NOTE]
> **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).
To adapt the model to empathetic psychological counseling in Spanish we used the following resource:
* **Supervised Fine-Tuning (SFT)**
* **Dataset:** `ALIA-es-clinical-psychology-dialogues.jsonl` (containing 67 multi-turn sessions)
* **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.
---
## Additional Information
### License
[Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0)
### Citation
```bibtex
@misc{ALIA-es-gemma-clinical-psychology-sft,
title={ALIA-es-gemma-clinical-psychology-sft: Empathetic Psychology SFT Model for Spanish},
author={SINAI Research Group},
year={2026},
publisher={HuggingFace},
howpublished={\url{https://huggingface.co/SINAI/ALIA-es-gemma-clinical-psychology-sft}}
}
```
Please also cite the base model and family:
```bibtex
@misc{gemma4_2026,
title={Gemma 4: Open Weights Multimodal Models},
author={Google DeepMind},
year={2026},
url={https://deepmind.google/gemma}
}
```
### Funding
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).
---
**Contact:** [ALIA Project](https://www.alia.gob.es/) - [SINAI Research Group](https://sinai.ujaen.es) - [Universidad de Jaén](https://www.ujaen.es/)
**More Information:** [SINAI Research Group](https://sinai.ujaen.es) | [ALIA-UJA Project](https://github.com/sinai-uja)
|