패키지, 저장소 및 앱 카테고리 검색

GitHub 저장소mvitlov/tiktoken

tiktoken

tiktoken은 OpenAI 모델과 함께 사용할 수 있는 BPE 토크나이저입니다

tiktoken 프로젝트 이미지
스타
26
포크
6
최근 푸시(UTC)
2023. 7. 16.
프로젝트 상태
활성

원본 README

아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.

⏳ tiktoken

tiktoken is a BPE tokeniser for use with OpenAI's models.

Splitting text strings into tokens is useful because GPT models see text in the form of tokens. Knowing how many tokens are in a text string can tell you a) whether the string is too long for a text model to process and b) how much an OpenAI API call costs (as usage is priced by token). Different models use different encodings.

Features

The main Tiktoken class exposes APIs that allow you to process text using tokens, which are common sequences of character found in text. Some of the things you can do with tiktoken package are:

  • Encode text into tokens
  • Decode tokens into text
  • Compare different encodings
  • Count tokens for chat API calls

Usage

For more examples, see the /example folder.

import 'package:tiktoken/tiktoken.dart';

// Load an encoding
final encoding = encodingForModel("gpt-4");

// Tokenize text
print(encoding.encode("tiktoken is great!")); // [83, 1609, 5963, 374, 2294, 0]

// Decode tokens
print(encoding.decode([83, 1609, 5963, 374, 2294, 0])); // "tiktoken is great!"

// Alternatively, get the tokenizer by specifying encoding name:
final encoding = getEncoding("cl100k_base");
assert(enc.decode(enc.encode("hello world")) == "hello world");

Extending tiktoken

You may wish to extend Tiktoken to support new encodings. You can do this by passing around the existing model:

import 'package:tiktoken/tiktoken.dart';

// Create a base
final cl100kBase = encodingForModel("cl100k_base");

// Instantiate a new encoding and extend the base params
final encoding = Tiktoken(
  name: "cl100k_im",
  patStr: cl100kBase.patStr,
  mergeableRanks: cl100kBase.mergeableRanks,
  specialTokens: {
    ...cl100kBase.specialTokens,
    "<|im_start|>": 100264,
    "<|im_end|>": 100265,
  },
);

Additional information

This is a Dart port from the original tiktoken library written in Rust/Python.

Marin Vitlov GitHub avatar
GitHub 작성자

Marin Vitlov ↗

Flutter ❤️

ABOUT YOU SE & Co. KGZagreb공식 웹사이트 ↗
언어Dart

이 저장소가 배포한 패키지

사용 중인 의존성

의존성 목록 2 개

  • lints개발 의존성^2.0.0
  • test개발 의존성^1.16.0

프로젝트에 맞는 저장소를 선택하려면?

사용 목적에 따라 검색하고 개발 활동을 비교한 뒤 원본 저장소에서 요구 사항을 확인하세요.

  1. 이름, 작성자 또는 설명으로 검색하고 기술 주제로 범위를 좁힙니다.
  2. 스타, 포크, 최근 푸시를 함께 비교하세요. 스타는 관심의 지표이며 품질을 보장하지 않습니다.
  3. 사용하기 전에 GitHub에서 README, 라이선스, Issues를 확인하세요.

출처 및 관리

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗