A small, focused Bengali elementary math solver. It reads a natural-language problem (Bangla), predicts the operation with a lightweight ML model, computes the answer, and shows step‑by‑step reasoning in Bengali.
- Web UI (web/): Tailwind CSS + vanilla JS front‑end
- API endpoints:
- web/solver.php (POST) — solve a problem
- web/generate.php (GET) — sample problems from dataset.csv
- Core logic (PHP):
- trainer.php — trains a Rubix ML text classifier
- solver.php — loads the model, predicts operation, extracts numbers, computes result, builds steps
- helpers.php — normalization, digit conversion, number extraction
- result.php — Bengali step rendering
- PHP 8.0+
- Composer
- A local server (Laragon/XAMPP) or PHP’s built‑in server
- Clone and install dependencies
git clone https://github.com/arafat-web/ganitmitra-ai.git
cd ganitmitra-ai
composer install
- Prepare dataset
- Place your datasets (CSV) in the project root.
- Used by this repo:
- dataset.csv — used by web/generate.php to show example problems
- dataset_new.csv — used by trainer.php to train the model
Tip: Keep one canonical dataset if you prefer (adjust scripts accordingly).
php trainer.php
- Produces bengali_math_model.dat on success (saved when quick check accuracy > 90%).
- Trainer prints a short report (classes found, quick accuracy check).
Option A — with Laragon/XAMPP: place the project under your web root and visit /web/
Option B — PHP built‑in server:
cd web
php -S localhost:8000
Open http://localhost:8000 in your browser.
POST a Bangla problem to the solver endpoint:
curl -X POST \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "problem=রাহিমের কাছে ৫টি আম আছে। করিম তাকে ৩টি আম দিল। এখন তার কাছে কতটি আম?" \
http://localhost:8000/solver.php
Example JSON response (trimmed):
{
"success": true,
"problem": "...",
"bengali_answer": "৮",
"steps": ["..."],
"method": "ml_model"
}
- Feature extraction: WordCountVectorizer(1000, 2) + TfIdfTransformer
- Classifier: RandomForest (100 estimators)
- Label space (operations): add, subtract, multiply, divide, divide_ceil, multi_step
- Runtime flow (solver.php):
- Extract numeric values from text (supports Bengali digits, decimals)
- Predict operation class with the trained model
- Compute result for that operation
- Build human‑friendly Bengali steps
Frontend (web/index.php):
- Clean, mobile‑friendly UI (Tailwind CDN + Font Awesome)
- Enter key triggers solve; Ctrl/Shift+Enter adds a newline
- Shows step‑by‑step solution and a bold Bengali answer
- Loads fresh example problems from generate.php after each solve
ganitmitra-ai/
├─ web/
│ ├─ index.php # UI (Tailwind CDN, Font Awesome), calls web/solver.php
│ ├─ solver.php # JSON endpoint for solving
│ ├─ generate.php # Returns random problems from dataset.csv
│ └─ style.css # Bengali font + small UI polish
├─ trainer.php # Trains and saves bengali_math_model.dat
├─ solver.php # ML-based solver (loads model, predicts op, computes)
├─ helpers.php # Text normalization, number extraction/conversion
├─ result.php # Builds Bengali step-by-step explanations
├─ dataset.csv # Example problems for UI suggestions
├─ dataset_new.csv # Training data for trainer.php
├─ bengali_math_model.dat # Saved model (created after training)
└─ composer.json
- rubix/ml (^2.5) — ML pipeline, training, and inference
- league/csv (9.24.1) — CSV utilities (e.g., generate/show dataset)
- mpdf/mpdf (^8.0) — Included for potential PDF export (not used in core flow yet)
- Add more labeled examples to dataset_new.csv for operations that underperform
- Tweak vectorizer size or n‑grams in trainer.php
- Try different classifiers (e.g., Naive Bayes, SVC) in trainer.php
- Unify dataset usage (adjust generate.php or trainer.php to the same CSV)
-
Model file not found
- Run
php trainer.phpto generatebengali_math_model.dat.
- Run
-
Low accuracy
- Enrich and balance
dataset_new.csv; increase vectorizer vocab; try another classifier.
- Enrich and balance
-
JSON parse error in UI
- Check
web/solver.phplogs; ensure no PHP warnings leak into JSON (buffering+headers are set).
- Check
-
Mixed dataset files
- Remember
web/generate.phpusesdataset.csvwhiletrainer.phpusesdataset_new.csv.
- Remember
-
Rubix ML errors you may see
- "Regressors require continuous labels, categorical given" → use a classifier (you already do) or ensure labels are strings for classification.
Class "Rubix\ML\Classifiers\GradientBoostedTrees" not found→ install a Rubix version that contains it or use available classifiers (e.g., RandomForest).
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
For issues and feature requests, use GitHub Issues.
This project is licensed under the MIT License. See the LICENSE file for details.