用本地 Gemma 3 为朋友打造的摩洛哥达里贾语导师 Darija Buddy
Darija Buddy: A Local Gemma-Powered Tutor for a Friend
开发者用 Google Gemma 3(4B)配合 Ollama 本地推理和 Gradio 界面,为在摩洛哥留学的朋友搭建了达里贾语对话练习工具 Darija Buddy。该工具完全离线运行,量化后 4B 权重仅需约 4 GB 内存、可在纯 CPU 消费级硬件上运行,支持 Arabizi、法语和标准阿拉伯语输入,并在达里贾语回复后附法语词汇讲解。代码已开源。
The Friend & The Problem
Moving to Morocco as an international student comes with a unique linguistic hurdle: Moroccan Darija. While formal Arabic (MSA) or French might get you through official paperwork, everyday social life happens in Darija.
My university classmate, Alex, has been struggling to fit into group banter and daily conversations. He understands some basics, but when people talk fast or switch between Arabizi (Latin-script Darija using numbers like 3, 7, 9) and spoken phrases, he freezes.
Traditional language apps don't support Moroccan Darija well—they usually default to Modern Standard Arabic, which locals rarely speak on the street. Human tutoring is expensive, and practicing with friends can feel intimidating when you're afraid of making mistakes.
He needed a safe, patient, and conversational practice partner that speaks genuine Darija, understands phonetically typed Arabizi, and explains nuances in French.
What I Built: Darija Buddy 🇲🇦
Darija Buddy is a lightweight, local conversational tutor designed to help non-Moroccan beginners practice real-life Darija speech.
Key Capabilities:
- Speaks authentic Darija: It avoids rigid Modern Standard Arabic and replies in natural Moroccan expressions.
- Multilingual input handling: It comprehends Latin-script Darija (Arabizi), French, and standard Arabic.
- Bilingual feedback loop: Whenever it introduces colloquial vocabulary or idioms, it appends concise pedagogical explanations in French.
- Gentle error correction: If the learner makes a grammar or lexical slip, Darija Buddy reformulates the phrase constructively before keeping the conversation flowing.
Technical Architecture & How It Works
The whole project runs entirely offline on a personal laptop — no expensive cloud infrastructure needed.
+-----------------------------------------------------------+
| Local Machine |
| |
| +-------------------+ +--------------------+ |
| | Gradio Web UI | <------> | Ollama Runtime | |
| | (darija_buddy.py) | | (gemma3:4b Model) | |
| +-------------------+ +--------------------+ |
+-----------------------------------------------------------+
1. The Core Model: Google Gemma 3 (4B)
I selected Gemma 3 (4B) as the reasoning engine. For a compact 4B-parameter open-weight model, Gemma 3 showcases remarkable multilingual understanding, easily deciphering transliterated Arabizi and grasping cultural Moroccan idioms.
2. Local Inference with Ollama
Instead of relying on remote APIs with variable latency and pay-per-token pricing, the model runs via Ollama. The quantized 4B weights run smoothly on consumer hardware (CPU-only), keeping RAM consumption under ~4 GB.
3. Gradio Interface
The frontend is encapsulated in a single Python script using gradio.ChatInterface, making it instantly accessible in any local browser window at http://127.0.0.1:7860.
4. Pedagogical System Prompt Engineering
The behavior is strictly governed by a system prompt enforcing colloquial vocabulary and French explanations:
SYSTEM_PROMPT = """You are "Darija Buddy", a friendly Moroccan Darija tutor for a
non-Moroccan beginner who wants to learn to SPEAK Darija.
Rules:
- Always reply mainly in authentic Moroccan Darija (Arabic script).
Use real Darija (e.g. لاباس، شنو، ديال), NEVER Modern Standard Arabic.
- After your Darija reply, add a short explanation IN FRENCH
(never English) of any new or difficult words.
- The user may write in Latin-script Darija (Arabizi), French or
English. Understand all of them.
- If the user writes in French or English, gently translate
their sentence into Darija, then continue in Darija.
- If the user tries Darija and makes mistakes, kindly correct:
show the corrected sentence, then briefly explain in French.
- Keep replies short (2-4 sentences) — speaking practice,
not a lecture.
- Be encouraging and patient. Ask follow-up questions to keep
the conversation going.
- Never switch fully to French or English; Darija first.
"""
## Demo & Interaction
Here is a practice session where the user initiates in Arabizi, receives natural conversational responses, and gets immediate French vocabulary breakdowns:



Why Open Innovation Matters for This Project
This project highlights why open-weight models and local inference triumph over proprietary closed APIs:
Zero Operational Cost: Language practice requires repetitive, daily micro-conversations. Running Gemma 3 locally means zero token costs, no API credits expiring, and no credit card requirements for students.
Total Privacy for the Learner: Practicing a new language involves vulnerability and personal conversations. All inference happens in-memory on the laptop; no conversation logs or personal data are ever uploaded to remote commercial servers.
Offline Reliability: University Wi-Fi and mobile data can be unpredictable. Darija Buddy works entirely on a plane, on a train, or in a cafe without an active internet connection.
Customizability: With open weights, I'm not locked into proprietary censorship or forced model upgrades. I can easily fine-tune Gemma on dialectal corpora or swap weights as newer open models release.
What My Friend Said
When I showed it to Alex on a video call:
"C'est magnifique... et ça va beaucoup m'aider à apprendre le Darija."
Code Repository
The code is completely open-source and easy to reproduce:
GitHub Repository: https://github.com/SoufianeZaari/darija-buddy
来源:Google AI:DEV 作者专属(RSS) · dev.to