Skip to main content

Shredword

A fast and efficient tokenizer library for natural language processing tasks, built with Python and optimized C backend.

Features

  • High Performance: Fast tokenization powered by optimized C libraries
  • Multiple Encodings: Support for various tokenization models and vocabularies
  • Flexible API: Easy-to-use Python interface with comprehensive functionality
  • Special Tokens: Built-in support for special tokens and custom vocabularies
  • Fallback Mechanisms: Robust error handling with fallback tokenization
  • BPE Support: Byte Pair Encoding implementation for subword tokenization
  • Word Tokenization: Fast word-level tokenization with contraction handling
  • TF-IDF Embeddings: Built-in TF-IDF vectorization with dense and sparse representations

Installation

pip install shredword

Quick Start

BPE Tokenization

from shred import load_encoding

tokenizer = load_encoding("pre_16k")

tokens = tokenizer.encode("Hello, world!")
print(tokens)

text = tokenizer.decode(tokens)
print(text)

print(f"Vocabulary size: {tokenizer.vocab_size}")
print(f"Special tokens: {tokenizer.special_tokens}")

Word Tokenization & TF-IDF Embeddings

from shred import WordTokenizer, TfidfEmbedding

tokenizer = WordTokenizer()
tokens = tokenizer.tokenize("Hello, world! This is a test.")
print(tokens)

embedding = TfidfEmbedding()
embedding.add_documents([
  "The quick brown fox jumps over the lazy dog",
  "Python programming is fun and exciting"
])

ids = embedding.encode_ids("The lazy fox")
dense_vec = embedding.encode_tfidf_dense("The lazy fox")
indices, values = embedding.encode_tfidf_sparse("The lazy fox")

embedding.save("vocab.txt")
loaded = TfidfEmbedding.load("vocab.txt")

Documentation

For detailed usage instructions, API reference, and examples, please see our User Documentation.

Supported Encodings

Shredword supports various pre-trained tokenization models. The library automatically downloads vocabulary files from the official repository when needed.

Contributing

We welcome contributions! Please feel free to submit issues, feature requests, or pull requests.

Development Setup

  1. Clone the repository
  2. Install development dependencies: pip install -r requirements.txt (there are none!)
  3. Run tests: python -m pytest

Guidelines

  • Follow PEP 8 style guidelines
  • Add tests for new features
  • Update documentation as needed
  • Ensure all tests pass before submitting PRs

License

This project is licensed under the Apache 2.0 License - see the LICENSE file for details.

Support

Release files for shredword 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for shredword 0.1.2
File Size Uploaded
shredword-0.1.2.tar.gz 1.2 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for shredword 0.1.2
File Interpreter ABI Platform
shredword-0.1.2-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details

Total release size: 1.3 MB

Release files / shredword-0.1.2.tar.gz

Download URL shredword-0.1.2.tar.gz
Size 1.2 MB
Tags Source
SHA-256 checksum
How to use checksums
6502ecb064a76de10672b5fd86e589f1e87ed0f92cff3a8faaffc86c1a79e2e8
BLAKE2b-256 checksum
How to use checksums
e938c2cfd5ac39be559e1101978eaf74de3950800a1e2f4ca3f5ab40e0201901
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.3

Release files / shredword-0.1.2-cp313-cp313-win_amd64.whl

Download URL shredword-0.1.2-cp313-cp313-win_amd64.whl
Size 115.6 kB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
294c1e5f05bb1a55c4dec0e133b994706cf67818924a0d3287d6d651e073a4c7
BLAKE2b-256 checksum
How to use checksums
9dba1d4e06e3d4f03c78ecc38a2a3a396b3adea24160ef48fd087c02584d8974
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.3

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.5

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page