PHP code example of codewithkyrian / transformers

1. Go to this page and download the library: Download codewithkyrian/transformers library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

codewithkyrian / transformers example snippets


use function Codewithkyrian\Transformers\Pipelines\pipeline;

// Allocate a pipeline for sentiment-analysis
$pipe = pipeline('sentiment-analysis');

$out = $pipe('I love transformers!');
// [{'label': 'POSITIVE', 'score': 0.999808732}]

use function Codewithkyrian\Transformers\Pipelines\pipeline;

// Allocate a pipeline for translation
$pipe = pipeline('translation', 'Xenova/distilbert-base-uncased-finetuned-sst-2-english');


use Codewithkyrian\Transformers\Transformers;

Transformers::setup()
    ->setCacheDir('...') // Set the default cache directory for transformers models. Defaults to `.transformers-cache/models`
    ->setRemoteHost('...') // Set the remote host for downloading models. Defaults to `https://huggingface.co`
    ->setRemotePathTemplate('...') // Set the remote path template for downloading models. Defaults to `{model}/resolve/{revision}/{file}`
    ->setAuthToken('...') // Set the auth token for downloading models. Defaults to `null`
    ->setUserAgent('...') // Set the user agent for downloading models. Defaults to `transformers-php/{version}`
    ->setImageDriver('...') // Set the image driver for processing images. Defaults to `IMAGICK'
    ->apply(); // Apply the configuration
ini
extension = ffi
ini
ffi.enable = true