Skip to content
Used the liblinear library with php
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Minimum PHP Version Latest Stable Version Total Downloads License

A simple, light and efficient short-text classification tool based on Liblinear for PHP.

Inspired by Python Library TextGrocery.

For Lemmarizer words, used php-lemmatizer

Installation Liblinear library

Debian or Ubuntu :

apt-get install liblinear-dev liblinear-tools liblinear3

Other distribution view repository github

Install php-liblinear

You can install it with Composer:

composer require mbeurel/php-liblinear


Example scripts are available ina separate repository php-liblinear/examples.

Sample Code

include "vendor/autoload.php";
use PhpLiblinear\Classification\LibLinear;
$data = [
  ["French", "Ceci est un texte dans la langue française."],
  ["French", "Bonjour, comment allez vous ?"],
  ["French", "Bonjour, je m'appelle Jean !!!"],
  ["English", "This is a english language text."],
  ["English", "Hello, How are you ?"],
  ["English", "Hello, my name is Jean !!!"],
try {
  // Init library
  $libLinear = new LibLinear("instanceName", __DIR__."/var", array(
        "type"      =>  0,            // Liblinear type, view the liblinear documentation
        "cost"      =>  1.0,          
        "epsilon"   =>  0.1,
        "debug"     =>  false

  // Liblinear train
  // Save model

  // Load model
  // Liblinear predict : String or Array parameters, to array => ["Bonjour, je m'appelle Louis", "Comment allez vous ?"]
  $result = $libLinear->predict("Bonjour, je m'appelle Louis");
  // View result

  //  $result = array(
  //    0  =>  array(
  //      "value"        =>  "French",
  //      "percentage"   =>  0.763259,
  //      "percentages"  =>  array(
  //        "French"        => 0.763259,
  //        "English"       => 0.236741
  //      )
  //    )
  //  )

} catch(\Exception $e) {
  echo $e;


Created by Matthieu Beurel. Sponsored by Nexboard.

You can’t perform that action at this time.