--- language: - pt license: apache-2.0 library_name: mlx tags: - gemma3 - fine-tuned - lora-fused - mlx - brazilian-portuguese - dialect - periferia - financial-education - cpt - sft - dpo base_model: mlx-community/gemma-3-1b-it-bf16 pipeline_tag: text-generation model-index: - name: MLK-de-Vila-1.0-1.3B results: - task: type: text-generation name: Financial Education in Brazilian Periferia Dialect metrics: - name: Functional Responses type: accuracy value: 100 verified: false - name: Dialect Usage (DPO) type: accuracy value: 100 verified: false --- # MLK de Vila 1.0-1.3B

LLM de educação financeira que fala a língua da periferia brasileira

**MLK de Vila** é um modelo de linguagem fine-tuned para ser um educador financeiro que compreende e responde no dialeto da periferia brasileira. Treinado inteiramente em hardware acessível (8GB de memória, GPU integrada, processador ARM). ## Model Details | Attribute | Value | |-----------|-------| | **Base Model** | [mlx-community/gemma-3-1b-it-bf16](https://huggingface.co/mlx-community/gemma-3-1b-it-bf16) (Gemma 3 1B IT) | | **Architecture** | Gemma3ForCausalLM | | **Parameters** | 1,301,875,840 (~1.3B) | | **Format** | bf16 (safetensors) | | **Framework** | MLX (Apple Silicon) | | **Size** | ~2.6 GB | | **Training Pipeline** | CPT → fuse → SFT → fuse → DPO → fuse | | **Training Data** | ~842,000 tokens | | **Peak Memory** | 5.08 GB | | **Total Training Time** | ~4 hours | | **Hardware** | 8GB RAM, GPU integrada, ARM | ## Training Pipeline ``` Gemma 3 1B IT ──CPT──→ Dialeto bruto ──SFT──→ Dialeto + Conteúdo ──DPO──→ Modelo Final ↓ ↓ ↓ ↓ Vocabulário Como falar O que falar Qual estilo e estruturas da periferia sobre finanças preferir ``` ### Continuous Pre-Training (CPT) - **Data:** 302k tokens — 99 transcrições YouTube, artigos, textos sintéticos em dialeto - **Config:** LoRA rank 32, scale 20.0, 10 layers, LR 2e-5, 500 iters - **Result:** Val loss 4.362 → 3.258 (25% reduction) ### Supervised Fine-Tuning (SFT) - **Data:** 180k tokens — 558 instruction-response pairs (94 financial topics, 64 slang terms) - **Config:** LoRA rank 16, scale 10.0, 12 layers, LR 1e-5, 1950 iters - **Result:** Val loss 4.518 → 1.587 ### Direct Preference Optimization (DPO) - **Data:** 360k tokens — 564 preference pairs (dialect chosen vs formal rejected) - **Config:** LoRA rank 4, 4 layers, 479K params, beta 0.3, LR 1e-6, 300 iters - **Result:** Loss 0.693 → 0.495 ## Results ### Benchmark (16 questions: 8 formal + 8 dialect) | Stage | Functional Responses | Uses Dialect | |-------|---------------------|-------------| | Base (Gemma 3 1B IT) | 16/16 | 0/16 | | After CPT | 16/16 | Partial | | After SFT | 16/16 | 14/16 | | **After DPO (this model)** | **16/16** | **16/16** | ### Interpretability Test Input (100% slang): > "Ae parceiro, to no busão chegando na quebrada, mano esse bagulho de grana é embaçado, você dá mó trampo e essa parada de inflação engole sua grana. Na moral, papo reto memo, você precisa pegar a visão de investir." **Model response:** > "Vou te **passar a visão** de investir, mas é importante entender que não é pra ser feito no seu bolso. Se você é um estudante, um jovem de 17 anos, tem que ter um plano. O dinheiro que você ganha no mês é pra ser usado com responsabilidade. Por exemplo, se você é MEI e tem R$ 1.200 por mês, é melhor que você anote cada centavo que recebe e distribua para despesas fixas, como aluguel, contas, e depois deixar um monte pra investir." The model: (1) understood the intent, (2) responded in dialect ("passar a visão"), (3) provided concrete financial advice contextualized for a young person. ## How to Use ### With MLX (recommended for Apple Silicon) ```python from mlx_lm import load, generate model, tokenizer = load("lbertolino/MLK-de-Vila-1.0-1.3B") # IMPORTANT: is NOT EOS in Gemma 3 — must add manually tokenizer.add_eos_token("") messages = [{"role": "user", "content": "Mano, como organizar a grana do mês?"}] prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True) response = generate(model, tokenizer, prompt=prompt, max_tokens=500) print(response) ``` ### Gradio Demo ```bash git clone https://github.com/LeviBertolino/MLK-De-Vila.git cd MLK-De-Vila pip install mlx-lm gradio python app.py ``` ## Important Notes 1. **`` is NOT EOS in Gemma 3.** You MUST add `tokenizer.add_eos_token("")` or the model will generate infinitely after the end of turn. 2. **Do NOT use system messages.** The model was trained with `mask_prompt=True`, which means it never learned to associate system messages with response style. Including a system message causes immediate `` generation. 3. **This model is optimized for MLX on Apple Silicon.** For other frameworks, you may need to convert the weights. ## Training Data | Stage | Tokens | Proportion | |-------|--------|-----------| | CPT | ~302,000 | 36% | | SFT | ~180,000 | 21% | | DPO | ~360,000 | 43% | | **Total** | **~842,000** | **100%** | The 64 slang terms used include: mano, parceiro, trampo, grana, bico, quebrada, padoca, busão, corre, maloca, perrengue, rolê, bagulho, embaçado, suave, de boa, na moral, pode crer, é nóis, tá ligado, passa a visão, papo reto, correria, among others. ## Key Technical Discoveries - **Aggressive CPT is essential** to break the alignment resistance of instruction-tuned models - **6 bad examples (1% of dataset) corrupted the entire SFT** — data quality > quantity - **RAG cannot achieve dialect adaptation** — it operates on content, not style - **`alpha` parameter is ignored by mlx-lm** — only `rank`, `scale`, `dropout` are effective - **System message + mask_prompt = broken** — model generates immediate `` ## Limitations - Small CPT corpus (~302k tokens) — more authentic speech data could deepen comprehension - Qualitative benchmark with 16 questions — automatic dialect metrics are needed - Aggressive CPT can introduce undesirable associations (e.g., periferia → crime) corrected by SFT/DPO - Some SFT/DPO responses show repetitions, suggesting incomplete fluency internalization - Deep/uncommon slang (e.g., "goma" = work) still has limited comprehension ## Paper & Code - **Paper:** [GitHub README](https://github.com/LeviBertolino/MLK-De-Vila) - **Code:** [GitHub Repository](https://github.com/LeviBertolino/MLK-De-Vila) - **Datasets:** Included in the GitHub repository under `data/` ## Citation ```bibtex @misc{bertolino2025mlkdevila, title={Mlk de Vila: Fine-Tuning de LLMs para Educação Financeira no Dialeto da Periferia Brasileira}, author={Bertolino, Levi}, year={2025}, url={https://github.com/LeviBertolino/MLK-De-Vila} } ``` ## License Apache 2.0 — Same as the base model (Gemma 3). ---

"Quando o jovem da quebrada pergunta 'Mano, como organizar a grana do mês?' e o modelo responde com orientação financeira concreta no dialeto dele — isso não é tradução. É comunicação."