Llama 3.2 Token Counter
A simple and efficient token counter for Llama 3.2 models.
Description
The Llama 3.2 Token Counter is a Python package that provides an easy way to count tokens generated by Llama 3.2 models. This tool is essential for developers and researchers working with large language models, helping them manage token limits and optimize their use of the Llama 3.2 architecture.
Features
- Accurate token counting for Llama 3.2 models
- Easy-to-use Python API
- Supports both string and list of strings inputs
- Asynchronous token counting support
- Batch processing for large inputs
- Lightweight and efficient
Installation
You can install the Llama 3.2 Token Counter using pip:
pip install llama3.2-token-counter
Usage
Here's a quick example of how to use the Llama 3.2 Token Counter:
from llama_token_counter import LlamaTokenCounter
import asyncio
# Initialize the token counter
counter = LlamaTokenCounter()
# Synchronous token counting
text = "Hello, world! This is a sample text for token counting."
token_count = counter.count_tokens(text)
print(f"The text contains {token_count} tokens.")
# Asynchronous token counting
async def count_async():
text = "This is an async token counting example."
token_count = await counter.count_tokens(text)
print(f"The async text contains {token_count} tokens.")
asyncio.run(count_async())
# Count tokens in a list of strings
texts = ["Hello, world!", "This is another sample.", "Multiple strings can be processed."]
token_count = counter.count_tokens(texts)
print(f"The list of texts contains {token_count} tokens in total.")
# Get the maximum token limit
max_tokens = counter.get_max_tokens()
print(f"The maximum token limit is {max_tokens}.")
# Batch processing for large lists
large_list = ["Text " + str(i) for i in range(10000)]
token_count = counter.count_tokens(large_list, batch_size=500)
print(f"The large list contains {token_count} tokens in total.")
Contributing
We welcome contributions to the Llama 3.2 Token Counter! If you'd like to contribute, please look at CONTRIBUTING.md for more information.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contact
Anthony - @anthoeknee
Project Link: https://github.com/anthoeknee/llama3.2-token-counter
Running Tests
To run the tests, follow these steps:
-
Clone the repository:
git clone https://github.com/yourusername/llama3.2-token-counter.git cd llama3.2-token-counter -
Install the development dependencies:
pip install -r requirements.txt -
Run the tests:
pytest tests
Make sure you have the necessary tokenizer files in the src/llama_token_counter/tokenizer directory before running the tests.
Release files for llama3.2-token-counter 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| llama3_2_token_counter-0.5.0.tar.gz | 5.6 MB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| llama3.2_token_counter-0.5.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size:8.9 MB
Release files / llama3_2_token_counter-0.5.0.tar.gz
| Download URL | llama3_2_token_counter-0.5.0.tar.gz |
|---|---|
| Size | 5.6 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6381d44b57afe7b7b28fa28e1d8d2e3b74e50a0e5f6b21f396fd7639804c2a3b
|
|
BLAKE2b-256 checksum How to use checksums |
8ab00d05b1d8dfa408d0b4c7ceb884bafb5a89d71231a79db3279041af8543e9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.9
|
Release files / llama3.2_token_counter-0.5.0-py3-none-any.whl
| Download URL | llama3.2_token_counter-0.5.0-py3-none-any.whl |
|---|---|
| Size | 3.3 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0377c60da862bd9f5f1a7188d2cd214572cd5db031f709135afd80bc4cab1047
|
|
BLAKE2b-256 checksum How to use checksums |
165b2ca8d4be6211daceb22646462d3888627530ade0f0d3859078f9014027c7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.9
|