This presentation discusses implementing machine learning inference in PHP using ONNX and Transformers. We introduce Transformer models, which revolutionized natural language processing since their introduction in 2017 through the "Attention is All You Need" paper.
Unlike previous sequential processing models, Transformers can process all input simultaneously, featuring encoder-decoder structure, self-attention layers, and position embeddings.
The presentation demonstrates three practical use cases in PHP:
Text Classification: Using the TransformersPHP package to analyze sentiment in product reviews, showcasing code for processing and scoring text input.
Image Classification: Implementing image recognition capabilities, with an example of a "hot dog" detection system using ONNX models.
LLM Generation: Demonstrating text generation using smaller language models, including integration with the Flan-T5 model.
The technical implementation relies on PHP's Foreign Function Interface (FFI), which allows PHP code to directly interact with C libraries without additional extensions. The presentation emphasizes ONNX (Open Neural Network Exchange) as a key component, enabling interoperability between different machine learning frameworks like PyTorch and TensorFlow.
A significant current limitation is the lack of GPU support, making the speaker recommend:
Using this approach for smaller tasks like classification and image tagging
Delegating larger LLM work to GPU-based infrastructure
Considering alternatives for LLM implementation:
Using SaaS services (OpenAI, Claude API)
Utilizing HuggingFace Inference endpoints
Building custom solutions (with associated risks)
The presentation also highlights SmolLM, a compact 538MB language model suitable for smaller applications, demonstrating the potential for efficient ML implementation in PHP environments.