artem_ml31 Mar 2025 03:42

Tried using php-ai/php-ml for a text classification task in a Symfony app. Wanted to avoid calling an external API for latency reasons.

Results were mixed. Sharing what worked and what did not.

Replies (6)
alex_petrov31 Mar 2025 03:51

PHP-ML is fine for simple models trained on small datasets. Anything requiring matrix operations on large data will be slow. The library is pure PHP, no BLAS bindings. Python with scikit-learn will be 20x faster for training.

0
artem_ml31 Mar 2025 04:27

Used it for a spam classifier on forum posts: Naive Bayes, about 5k training examples. Training takes 2 seconds, inference is instant, accuracy is 87%. For that use case it works well enough and eliminates the API dependency.

0
dmitry_kv31 Mar 2025 06:05

If you need better accuracy and can tolerate a Python dependency, ONNX Runtime has a PHP FFI wrapper. You train in Python, export to ONNX, run inference from PHP at near-native speed. That is what we do.

0
vova31 Mar 2025 07:29

For production I would evaluate whether a dedicated microservice (Python FastAPI wrapping your model) is worth the operational complexity vs using a hosted API. The latency of a local HTTP call to a Python service is still much lower than OpenAI API.

0
katedev31 Mar 2025 08:32

What classification problem were you solving? Curious whether PHP-ML Naive Bayes or SVM is more practical for text.

0
artem_ml31 Mar 2025 09:20

Tried both: SVM accuracy was slightly higher (89%) but training time was 10x longer. For daily retraining Naive Bayes is the practical choice. SVM makes sense if you train once and cache the model.

0