# 🧠STJ — Tri-Agent Reinforcement Learning for Low-Resource English→Arabic Translation
This repository introduces **STJ**, a *Student–Teacher–Judge* (tri-agent) reinforcement learning framework that enables a model to **learn Arabic meaning, grammar, and fluency** through **self-play** — without large supervised datasets.
---
## 🔍 Overview
**Core Idea:**
Three interacting agents form a closed training loop:
| Agent | Role | Goal |
|--------|------|------|
| **A (Student)** | Generates Arabic words or sentences. | Maximize correctness reward from the Judge. |
| **B (Teacher / Adversary)** | Provides increasingly difficult or misleading English examples. | Minimize Student’s success rate. |
| **C (Judge / Grounded Evaluator)** | Scores each translation based on accuracy, grammar, and fluency. | Provide stable, fair rewards (+1 / 0 / –1). |
Figure: STJ Tri-Agent Reinforcement Learning System
Training phases:
1. **Supervised Warm-Up:** A learns basic English→Arabic mappings from a bilingual lexicon.
2. **Reinforcement Phase:** A and B self-play while C evaluates correctness.
3. **Curriculum Growth:** Tasks scale from single words → phrases → sentences.
---
## ⚙️ Code Structure
| File | Description |
|------|--------------|
| `teacher.py` | Adversarial teacher (B) — generates English words, adjusts difficulty, adds fakes. |
| `student.py` | Simple baseline student (A). |
| `student_rl.py` | RL-based student (A) — GRU policy trained with REINFORCE + imitation warm-up. |
| `judge_translation.py` | Rule-based judge (C) for one-word translation. |
| `judge.py` | Transformer-based judge (C) with multi-component rubric scoring. |
| `env_rl.py` | RL environment connecting A, B, and C. |
| `loop.py` | Main tri-agent training loop with logging. |
---
## đź§ Conceptual Inspiration
The **STJ** architecture combines:
- *Knowledge distillation* (Hinton et al., 2015)
- *Sequence-level RL* (Ranzato et al., 2016)
- *Adversarial training* (Goodfellow et al., 2014)
- *AI s …