PHP code example of crazzy501 / gpt-3-encoder-php

1. Go to this page and download the library: Download crazzy501/gpt-3-encoder-php 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/ */

    

crazzy501 / gpt-3-encoder-php example snippets




$encoder = new \GPT3Encoder\Gpt3Encoder();

$prompt = "Many words map to one token, but some don't: indivisible. Unicode characters like emojis may be split into many tokens containing the underlying bytes: 🤚🏾 Sequences of characters commonly found next to each other may be grouped together: 1234567890";

$token_array = $encoder->encode($prompt);

$original_text = $encoder->decode($token_array);


$original_text = $encoder->decode($token_array,true);


$configuration = (new \GPT3Encoder\Gpt3EncoderConfiguration)
    ->setCacheClass(\GPT3Encoder\Gpt3CacheMemcached::class)
    ->setEncoder(__DIR__.'/encoder.json')
    ->setVocabulary(__DIR__.'/vocabulary.bpe')
    ->setCharacters(__DIR__.'/characters.json')
    ->setMemoryLimitThreshold(10000);   // for memory limit checks

$encoder = new \GPT3Encoder\Gpt3Encoder($configuration);