Skip to main content

A tokenizer-free NLP library with T-FREE, CANINE, and byte-level approaches

Project description

Precious Package

Overview

The Precious package provides a minimal model showcasing three tokenizer-free approaches for natural language processing tasks. It includes implementations for T-FREE, CANINE, and byte-level embeddings, along with attention mechanisms for enhanced performance.

Installation

From PyPI (Recommended)

pip install precious-nlp

From Source (Development)

git clone https://github.com/bimri/precious.git
cd precious
pip install -e .

With Optional Dependencies

# For development tools
pip install precious-nlp[dev]

# For benchmarking
pip install precious-nlp[benchmarks]

# For documentation
pip install precious-nlp[docs]

# All optional dependencies
pip install precious-nlp[all]

Usage

Here is a basic example of how to use the PreciousModel:

# Import with hyphenated package name
import precious_nlp as precious
from precious_nlp import PreciousModel, PreciousConfig

# Initialize the model with the desired configuration
config = PreciousConfig(mode="byte", d_model=256)  # or "tfree", "canine"
model = PreciousModel(config)

# Prepare your input data
inputs = ["Hello, tokenizer-free world!"]
outputs = model(inputs)

# Access the logits
logits = outputs["logits"]
print(f"Output shape: {logits.shape}")  # [batch_size, seq_len, vocab_size]

# Training with targets
targets = ["Hello, tokenizer-free universe!"]
outputs = model(inputs, targets=targets)
loss = outputs["loss"]
print(f"Training loss: {loss.item()}")

Three Tokenizer-Free Approaches

1. Byte-Level Processing

import precious_nlp as precious
config = precious.PreciousConfig(mode="byte", d_model=256)
model = precious.PreciousModel(config)
# Processes text at byte level - universal and memory efficient

2. CANINE Approach

import precious_nlp as precious
config = precious.PreciousConfig(mode="canine", d_model=256)
model = precious.PreciousModel(config)
# Character-level processing with Unicode support

3. T-FREE Method

import precious_nlp as precious
config = precious.PreciousConfig(mode="tfree", d_model=256, tfree_vocab_v=8192)
model = precious.PreciousModel(config)
# Vocabulary-aware with character-level fallback

Key Features

  • 🚀 Three tokenizer-free approaches in one unified library
  • 🎯 Production-ready with comprehensive testing and documentation
  • 🌍 Universal text support - handles any Unicode text
  • Efficient processing with configurable model architectures
  • 🧪 Research-friendly with benchmarking and comparison tools
  • 📚 Well-documented with extensive examples and API reference

Quick Performance Comparison

Mode Memory Speed Best For
Byte Lowest Fastest General purpose, production
CANINE Medium Medium Multilingual, character-aware
T-FREE Highest Research Vocabulary analysis, interpretability

Documentation

Requirements

  • Python >= 3.8
  • PyTorch >= 1.9.0
  • NumPy >= 1.19.0

Contributing

Contributions are welcome! Please follow these steps to contribute:

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix.
  3. Make your changes and commit them.
  4. Push your branch and create a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

precious_nlp-0.1.0.tar.gz (17.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

precious_nlp-0.1.0-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file precious_nlp-0.1.0.tar.gz.

File metadata

  • Download URL: precious_nlp-0.1.0.tar.gz
  • Upload date:
  • Size: 17.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for precious_nlp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 abdcf51bf13dab5d8017f7bb2ca15942b765b091e0dd838b7bdd635b0e18980e
MD5 a750e6bbcdc12e219d4907bb8a75c044
BLAKE2b-256 516967c76c8f8fc9cc2c88d0f9a45a88803649868b724f080a5ab58115f1aa9b

See more details on using hashes here.

File details

Details for the file precious_nlp-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: precious_nlp-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for precious_nlp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 afd4edefaff385b9d780afb19d320ae9e81d588ab36f465e77505fc08884e3b6
MD5 ca7a21145671b4881551aa0f9823984c
BLAKE2b-256 8da3efb78804e73e819c72d99a403fc46da2c760c7188dc4745b09c87f955918

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page