garryrodriguez / php-ai-classifier
Native PHP text classification library
Package info
github.com/garryRodriguez/php-ai-classifier
pkg:composer/garryrodriguez/php-ai-classifier
v0.1.0
2026-01-31 04:42 UTC
Requires
- php: >=8.2
README
A lightweight, native PHP text classification library. Categorize support tickets, blog posts, or user feedback instantly without needing expensive external APIs like OpenAI or Python microservices.
Features
- 100% Native PHP: No dependencies, no Python, no C++ extensions.
- Fast & Private: All data stays on your server. Zero latency.
- Easy Integration: Built for Composer and modern PSR-4 standards.
- Naive Bayes Logic: Uses probability-based classification for reliable sorting.
Usage Example
use garryRodriguez\PhpAiClassifier\Classifier;
$ai = new Classifier();
// 1. Train the AI
$ai->train('billing', 'I need my invoice for last month');
$ai->train('billing', 'Where is my receipt?');
$ai->train('support', 'The app is crashing on my iPhone');
$ai->train('support', 'I cannot log in to my account');
// 2. Predict categories
$category = $ai->predict('Can you send me my bill?');
echo $category; // Outputs: billing
******
$ai = new Classifier();
// Only train if we don't have a saved model yet
if (!file_exists('my_model.json')) {
$ai->train('billing', 'I need my invoice');
$ai->saveModel('my_model.json');
} else {
$ai->loadModel('my_model.json');
}
echo $ai->predict('Where is my bill?');
Installation
Install the package via Composer:
composer require garryrodriguez/php-ai-classifier ```zsh composer require garryrodriguez/php-ai-classifier