Skip to main content

Lord of the Datasets - Efficient NLP dataset preprocessing

Project description

LOTD - Lord Of The Datasets

Efficient NLP dataset preprocessing library for instruction tuning and general NLP tasks.

Features

  • Chat and text tokenization
  • Length filtering
  • Padding collators
  • HuggingFace dataset utilities (splitting, caching, dataloaders)
  • Prebuilt Alpaca dataset loader

Documentation

This package provides MkDocs documentaion.

Usage examples can be found in examples directory.

Installation

pip install lotd

Example Usage

from lotd import ChatTokenizer, PadCollator, get_loaders, datasets

# Preprocess dataset
dataset = my_dataset.map(
    ChatTokenizer(my_pretrained_tokenizer),
    input_columns=["prompt", "output"],
    batched=True,
    batch_size=512,
)

# Filter by length
dataset = dataset.filter(
    LengthFilter(min_length=0, max_length=max_length),
    input_columns=["input_ids"],
    batched=True,
    batch_size=512,
)

# Create DataLoaders
train_loader, val_loader, test_loader = get_loaders(
    dataset, collate_fn=PadCollator(pad_id=0)
)

# OR use pre-configured datasets
from lotd.datasets import alpaca

train_loader, val_loader, test_loader = alpaca(tokenizer=my_tokenizer)

Build

  1. Clone this repo:
git clone https://github.com/alex-karev/lotd.git
cd lotd
  1. Install build tools:
pip install --upgrade build setuptools wheel
  1. Build package:
python -m build
  1. Install:
pip install dist/lotd-0.1.0-py3-none-any.whl

Nix

You can include LOTD in another project with Nix Flakes:

{
  description = "My NLP Project";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    lotd = {
        url = "github:alex-karev/lotd"; # LOTD flake
        inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = { self, nixpkgs, lotd }: let
    pkgs = import nixpkgs { system = "x86_64-linux"; };
    devShells.default = pkgs.mkShell {
      name = "my-nlp-project";
      packages = [
        (pkgs.python312.withPackages (python-pkgs: [
              lotd.packages.x86_64-linux.lotd
              # other python packages
        ]))
      ];
    };
  };
}

License

See LICENSE

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

lotd-0.1.1.tar.gz (46.3 kB view details)

Uploaded Source

Built Distribution

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

lotd-0.1.1-py3-none-any.whl (34.6 kB view details)

Uploaded Python 3

File details

Details for the file lotd-0.1.1.tar.gz.

File metadata

  • Download URL: lotd-0.1.1.tar.gz
  • Upload date:
  • Size: 46.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.12

File hashes

Hashes for lotd-0.1.1.tar.gz
Algorithm Hash digest
SHA256 8628b820877decace79958c0ca7768265cb5de3c69e49a89e499ac37922c2f8a
MD5 406c1e09cbdd676c535d0fd926f9f9e8
BLAKE2b-256 ab28e867c9697e89763beccf9a3debfe661a8d5d2cc736d08f82c0ba587f9410

See more details on using hashes here.

File details

Details for the file lotd-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: lotd-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 34.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.12

File hashes

Hashes for lotd-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5d966cbdafe55e2535b373a96cdcaa1d019e7c972f83855597702b15499bbc14
MD5 e98dcebe0bc89538f724aba520c470bf
BLAKE2b-256 543f07bc17223b59ff61b6d1808575b3e43eb3ab4d48dfe00a46f8804158f9cc

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