Skip to content
Suraj-v23Public

About

A Neural Network That Learns From Its Mistakes

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

39 Commits

Folders and files

Repository files navigation

🧠 TrialNet β€” A Self-Learning AI That Learns From Its Mistakes

License: MIT Python Platform

TrialNet is a self-improving AI system with two layers:

  1. TrialNet Core β€” A neural network built from scratch with NumPy that uses a novel Try-and-Learn engine to remember and correct its mistakes.
  2. TrialNet LLM β€” A locally-running Large Language Model (Qwen2.5-1.5B) fine-tuned on Apple Silicon via MLX with a ChromaDB-backed mistake memory and an automated LLM-as-Judge for continuous self-correction.

πŸš€ What Makes This Different?

Feature Traditional Models TrialNet
Error handling Forgotten after weight update Error Memory Bank stores & prioritizes mistakes
Learning signal Loss gradient only Gradient + targeted mistake replay
Self-awareness None Mistake Pattern Analyzer discovers failure patterns
Weight updates Gradient descent only Gradient + Perturbation Explorer
LLM Memory Static weights ChromaDB RAG + continuous LoRA self-correction
Feedback Manual retraining Auto-judge scores every response, logs bad ones

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        TrialNet System                          β”‚
β”‚                                                                β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚   TrialNet Core      β”‚    β”‚   TrialNet LLM (Mac)       β”‚   β”‚
β”‚  β”‚   (NumPy from scratch)β”‚    β”‚   Qwen2.5-1.5B + MLX LoRA β”‚   β”‚
β”‚  β”‚                      β”‚    β”‚                            β”‚   β”‚
β”‚  β”‚  [Traditional SGD]   β”‚    β”‚  [ChromaDB Memory Bank]    β”‚   β”‚
β”‚  β”‚      +               β”‚    β”‚  ← stores mistakes         β”‚   β”‚
β”‚  β”‚  [Try-and-Learn]     β”‚    β”‚       ↓                    β”‚   β”‚
β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚    β”‚  [LLM-as-Judge]            β”‚   β”‚
β”‚  β”‚  β”‚ Error Memory β”‚    β”‚    β”‚  ← scores every response   β”‚   β”‚
β”‚  β”‚  β”‚ Bank         β”‚    β”‚    β”‚       ↓                    β”‚   β”‚
β”‚  β”‚  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€    β”‚    β”‚  [MLX LoRA Self-Correction]β”‚   β”‚
β”‚  β”‚  β”‚ Mistake      β”‚    β”‚    β”‚  ← injects corrections     β”‚   β”‚
β”‚  β”‚  β”‚ Analyzer     β”‚    β”‚    β”‚    into new adapter        β”‚   β”‚
β”‚  β”‚  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€    β”‚    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚  β”‚  β”‚ Perturbation β”‚    β”‚                                      β”‚
β”‚  β”‚  β”‚ Explorer     β”‚    β”‚                                      β”‚
β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚                                      β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“¦ Installation

TrialNet Core (NumPy Engine)

git clone https://github.com/Suraj-v23/trialnet.git
cd trialnet
pip install -r requirements.txt

TrialNet LLM (Apple Silicon β€” Requires M1/M2/M3/M4 Mac)

cd mac_llm_trialnet
pip install -r requirements_mac.txt

🎯 Quick Start

1. Train the Core (NumPy) Model

# Hybrid mode β€” recommended
python train.py --mode hybrid --epochs 15

# Compare all three learning modes
python train.py --mode compare --epochs 15

# With live dashboard at http://localhost:5050
cd dashboard && python server.py
python train.py --mode hybrid --epochs 15 --dashboard

2. Evaluate

python evaluate.py --model saved_models/hybrid

3. Run the Local LLM Chatbot (Apple Silicon only)

cd mac_llm_trialnet

# Step 1 β€” Fine-tune on hybrid logic + coding curriculum
python 1_mac_finetune.py

# Step 2 β€” Chat (Auto-judge runs on every response)
python 2_mac_chatbot.py

# Step 3 β€” Self-correct (run after 10+ logged mistakes)
bash run_self_correction.sh

πŸ“ Project Structure

trialnet/
β”œβ”€β”€ train.py                    # Core training script
β”œβ”€β”€ evaluate.py                 # Evaluation script
β”œβ”€β”€ requirements.txt            # Core dependencies
β”‚
β”œβ”€β”€ trialnet/                   # NumPy neural network library
β”‚   β”œβ”€β”€ model.py                # Main TrialNet class
β”‚   β”œβ”€β”€ utils.py                # Data loading utilities
β”‚   β”œβ”€β”€ core/                   # Neural network fundamentals
β”‚   β”‚   β”œβ”€β”€ tensor.py           # Custom tensor ops (no PyTorch)
β”‚   β”‚   β”œβ”€β”€ layers.py           # Dense, Dropout, BatchNorm
β”‚   β”‚   β”œβ”€β”€ activations.py      # ReLU, Sigmoid, Softmax, etc.
β”‚   β”‚   └── losses.py           # CrossEntropy, MSE
β”‚   └── learning/               # Learning engines
β”‚       β”œβ”€β”€ traditional.py        # SGD, Adam optimizers
β”‚       β”œβ”€β”€ error_memory.py       # Error Memory Bank ⭐ NOVEL
β”‚       β”œβ”€β”€ mistake_analyzer.py   # Pattern discovery ⭐ NOVEL
β”‚       β”œβ”€β”€ perturbation.py       # Weight exploration ⭐ NOVEL
β”‚       └── trial_learner.py      # Orchestrator ⭐ NOVEL
β”‚
β”œβ”€β”€ mac_llm_trialnet/           # Apple Silicon LLM pipeline
β”‚   β”œβ”€β”€ 1_mac_finetune.py         # Hybrid LoRA fine-tuning
β”‚   β”œβ”€β”€ 2_mac_chatbot.py          # Chat + Auto-judge
β”‚   β”œβ”€β”€ 3_mac_self_correct.py     # Self-correction loop
β”‚   β”œβ”€β”€ evaluate_mac.py           # Regression eval baseline
β”‚   β”œβ”€β”€ run_self_correction.sh    # Full pipeline runner
β”‚   β”œβ”€β”€ requirements_mac.txt      # MLX + ChromaDB deps
β”‚   └── memory/
β”‚       β”œβ”€β”€ chroma_bank.py        # ChromaDB mistake banking
β”‚       └── judge.py              # LLM-as-Judge scorer
β”‚
β”œβ”€β”€ colab_llm_trialnet/         # Google Colab pipeline
β”‚   β”œβ”€β”€ 1_base_finetune.py
β”‚   β”œβ”€β”€ 2_colab_chatbot.py
β”‚   └── 3_self_correction_loop.py
β”‚
β”œβ”€β”€ dashboard/                  # Real-time training dashboard
β”‚   β”œβ”€β”€ server.py               # Flask API
β”‚   β”œβ”€β”€ index.html
β”‚   β”œβ”€β”€ style.css
β”‚   └── app.js
β”‚
β”œβ”€β”€ PROGRESS.md                 # Build progress log
β”œβ”€β”€ ROADMAP.md                  # Planned features
β”œβ”€β”€ LICENSE                     # MIT
└── README.md                   # This file

πŸ”¬ The Three Core Learning Modes

1. Traditional

Standard neural network β€” forward pass, loss, backpropagation, gradient descent.

2. Trial

Only the novel Try-and-Learn system β€” no gradient descent at all:

  • Error Memory Bank: Stores mistakes with priority scoring (high-confidence wrong answers get highest priority)
  • Perturbation Explorer: Random weight experiments β€” keep what helps, revert what hurts
  • Targeted Replay: Spends more training time on the hardest, most-repeated mistakes

3. Hybrid (recommended)

Combines both. Traditional gradients provide the base learning signal; Try-and-Learn provides targeted corrections for stubborn mistakes.


πŸ€– LLM Self-Correction Pipeline (Apple Silicon)

You (user) ──► Chat ──► LLM Response
                              β”‚
                         LLM Judge scores (0–10)
                              β”‚
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                score ≀ 5 (bad)      score β‰₯ 8 (good)
                    β”‚
              Auto-logged to ChromaDB
                    β”‚
              /correct [fix]  ← you provide the right answer
                    β”‚
         (10 mistakes collected)
                    β”‚
           bash run_self_correction.sh
                    β”‚
            New LoRA adapter created
                    β”‚
         Model permanently updated βœ…

πŸ”§ Built With

Component Technology
Core neural network Pure NumPy (no PyTorch/TensorFlow)
LLM backbone Qwen/Qwen2.5-1.5B-Instruct
Apple Silicon inference MLX + mlx-lm
Mistake memory ChromaDB (vector database)
Auto-judge LLM-as-Judge (same local model)
Dashboard Flask + Chart.js

πŸ•ΈοΈ Knowledge Graph (Graphify)

This project uses Graphify for AI-assisted code understanding.

To generate the knowledge graph locally:

pip install graphify
graphify .

Then open graphify-out/graph.html to explore the codebase visually.


πŸ—ΊοΈ Roadmap

See ROADMAP.md for planned features including DPO training, GRPO alignment, and multimodal capabilities.


🀝 Contributing

Contributions, issues, and feature requests are welcome! Feel free to:

  1. Fork the repository
  2. Create a branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“œ License

This project is licensed under the MIT License β€” see LICENSE for details.


πŸ‘¨β€πŸ’» Author

Suraj Verma Β· @Suraj-v23

Building AI that learns the way humans do β€” by remembering and correcting its mistakes.

About

A Neural Network That Learns From Its Mistakes

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages