Upload TRAINING.md with huggingface_hub
Browse files- TRAINING.md +81 -0
TRAINING.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ContextFlow RL Training Guide
|
| 2 |
+
|
| 3 |
+
This guide explains how to train the RL model and upload it to Hugging Face.
|
| 4 |
+
|
| 5 |
+
## Quick Start
|
| 6 |
+
|
| 7 |
+
### 1. Install Dependencies
|
| 8 |
+
|
| 9 |
+
```bash
|
| 10 |
+
cd research-app/backend
|
| 11 |
+
pip install torch numpy pickle
|
| 12 |
+
pip install huggingface_hub # For uploading
|
| 13 |
+
```
|
| 14 |
+
|
| 15 |
+
### 2. Generate Training Data & Train
|
| 16 |
+
|
| 17 |
+
```bash
|
| 18 |
+
python train_rl.py --mode train --epochs 10 --samples 1000
|
| 19 |
+
```
|
| 20 |
+
|
| 21 |
+
### 3. Upload to Hugging Face
|
| 22 |
+
|
| 23 |
+
```bash
|
| 24 |
+
python train_rl.py --mode upload --hf_token YOUR_TOKEN --repo_name your-username/contextflow-rl
|
| 25 |
+
```
|
| 26 |
+
|
| 27 |
+
### 4. Or Do Both at Once
|
| 28 |
+
|
| 29 |
+
```bash
|
| 30 |
+
python train_rl.py --mode full --epochs 10 --hf_token YOUR_TOKEN --repo_name your-username/contextflow-rl
|
| 31 |
+
```
|
| 32 |
+
|
| 33 |
+
## Training Options
|
| 34 |
+
|
| 35 |
+
| Parameter | Description | Default |
|
| 36 |
+
|-----------|-------------|---------|
|
| 37 |
+
| `--epochs` | Number of training epochs | 10 |
|
| 38 |
+
| `--samples` | Number of training samples to generate | 1000 |
|
| 39 |
+
| `--batch_size` | Training batch size | 32 |
|
| 40 |
+
| `--checkpoint_path` | Path to save/load checkpoint | checkpoint.pkl |
|
| 41 |
+
|
| 42 |
+
## Model Architecture
|
| 43 |
+
|
| 44 |
+
The RL model uses:
|
| 45 |
+
- **Q-Network**: 3-layer neural network (64 → 128 → 128 → 10)
|
| 46 |
+
- **State Dimension**: 64 features
|
| 47 |
+
- **Action Dimension**: 10 doubt prediction actions
|
| 48 |
+
- **Training Algorithm**: GRPO (Group Relative Policy Optimization)
|
| 49 |
+
|
| 50 |
+
## Hugging Face Upload
|
| 51 |
+
|
| 52 |
+
After training, the model is uploaded as:
|
| 53 |
+
- **Repository**: `your-username/contextflow-rl`
|
| 54 |
+
- **Files**:
|
| 55 |
+
- `checkpoint.pkl` - Model weights
|
| 56 |
+
- `README.md` - Model documentation
|
| 57 |
+
- `training_stats.json` - Training history
|
| 58 |
+
|
| 59 |
+
## Using the Model
|
| 60 |
+
|
| 61 |
+
```python
|
| 62 |
+
import pickle
|
| 63 |
+
|
| 64 |
+
# Load checkpoint
|
| 65 |
+
with open("checkpoint.pkl", "rb") as f:
|
| 66 |
+
checkpoint = pickle.load(f)
|
| 67 |
+
|
| 68 |
+
print(f"Policy version: {checkpoint.policy_version}")
|
| 69 |
+
print(f"Training samples: {checkpoint.training_stats['total_samples']}")
|
| 70 |
+
```
|
| 71 |
+
|
| 72 |
+
## Citation
|
| 73 |
+
|
| 74 |
+
```bibtex
|
| 75 |
+
@software{contextflow_rl,
|
| 76 |
+
title={ContextFlow RL Doubt Predictor},
|
| 77 |
+
author={ContextFlow Team},
|
| 78 |
+
year={2026},
|
| 79 |
+
url={https://github.com/contextflow/research-app}
|
| 80 |
+
}
|
| 81 |
+
```
|