Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tiktoken

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tiktoken

JS/WASM bindings for tiktoken

  • 1.0.13
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
133K
decreased by-16.73%
Maintainers
1
Weekly downloads
 
Created

What is tiktoken?

The tiktoken npm package is designed for tokenizing text, particularly for use with OpenAI's GPT models. It provides efficient and accurate tokenization, which is essential for natural language processing tasks.

What are tiktoken's main functionalities?

Tokenization

This feature allows you to tokenize a string of text into tokens. The example demonstrates how to encode a simple string using the GPT-3 encoding.

const tiktoken = require('tiktoken');
const encoder = tiktoken.getEncoding('gpt-3');
const tokens = encoder.encode('Hello, world!');
console.log(tokens);

Detokenization

This feature allows you to convert tokens back into the original text. The example shows how to decode tokens back into the original string.

const tiktoken = require('tiktoken');
const encoder = tiktoken.getEncoding('gpt-3');
const tokens = encoder.encode('Hello, world!');
const text = encoder.decode(tokens);
console.log(text);

Custom Encoding

This feature allows you to create a custom encoding scheme. The example demonstrates how to define a custom encoding and use it to tokenize a string.

const tiktoken = require('tiktoken');
const customEncoding = tiktoken.createEncoding({
  'Hello': 1,
  'world': 2,
  '!': 3
});
const tokens = customEncoding.encode('Hello, world!');
console.log(tokens);

Other packages similar to tiktoken

FAQs

Package last updated on 28 Jan 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc