#claude #anthropic #language-model #ai #llm #gpt

claude-tokenizer

Library for tokenizing text with the Anthropic Claude models

2 unstable releases

0.3.0 Sep 20, 2024
0.2.0 Sep 20, 2024
0.1.0 Sep 20, 2024

#473 in Machine learning

Download history 327/week @ 2024-09-20 28/week @ 2024-09-27 8/week @ 2024-10-04 17/week @ 2024-10-11 5/week @ 2024-10-18 76/week @ 2024-11-01 37/week @ 2024-11-08 17/week @ 2024-11-15 6/week @ 2024-11-22 26/week @ 2024-11-29

104 downloads per month
Used in 2 crates

MIT license

750KB
67 lines

Claude Tokenizer

Claude Tokenizer is a Rust library for tokenizing text using the Anthropic Claude models. It provides functionality to tokenize text and count tokens, which is useful for working with Claude and other large language models.

Features

  • Tokenizer for Anthropic's Claude AI models
  • tokenize function to convert text into tokens
  • count_tokens function to calculate the number of tokens in a given text
  • Embedded JSON tokenizer data for offline use
  • Built on the tokenizers library for efficient tokenization

Installation

Add this to your Cargo.toml:

[dependencies]
claude_tokenizer = "0.2.0"

Then, run cargo build to build your project.

Usage

Import the claude_tokenizer crate into your Rust project:

use claude_tokenizer;

Then, you can use the tokenize and count_tokens functions:

let text = "Hello, world!";
let tokens = tokenize(text).unwrap();
let token_count = count_tokens(text).unwrap();

println!("Tokens: {}", tokens);
println!("Token count: {}", token_count);

License

The Claude Tokenizer Crate is licensed under the MIT License.

MIT License

Copyright (c) 2024 Tom Dallimore

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Dependencies

~17MB
~344K SLoC