gpt_3_encoder 1.0.0 copy "gpt_3_encoder: ^1.0.0" to clipboard
gpt_3_encoder: ^1.0.0 copied to clipboard

A pure Dart implementation of OpenAI's original Python encoder/decoder for GPT models.

GPT 3 Encoder #

This package aims to provide a simple interface for encoding and decoding text same as GPT-3, GPT-2 that uses byte pair encoding (BPE) to turn text into a series of integers to feed into the models.

This package is a pure Dart implementation of OpenAI's original Python encoder/decoder.

Usage #

import 'package:gpt_3_encoder/gpt_3_encoder.dart';

void main() {
  // This is the text we want to encode and decode.
  final text = "Hello World!";

  // Encode the text.
  final encoded = GPT3Encoder.instance.encode(text);

  // Print the encoded text and its token length. 
  print(
    "Your text contains ${encoded.length} tokens, encoded as follows: $encoded",
  );

  // Decode back the encoded text token by token and print the results.
  encoded.forEach((token) {
    final decoded = GPT3Encoder.instance.decode([token]);
    print("Token: $token, decoded as: $decoded");
  });
}
2
likes
150
points
32
downloads

Publisher

verified publishergwhyyy.com

Weekly Downloads

A pure Dart implementation of OpenAI's original Python encoder/decoder for GPT models.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

More

Packages that depend on gpt_3_encoder