segment-any-text/wtpsplit

Toolkit to segment text into sentences or other semantic units in a robust, efficient and adaptable way.

What it solves

wtpsplit is a robust and efficient tool for segmenting text into sentences or other semantic units across 85 languages. It addresses the challenge of sentence segmentation in diverse languages and domains, providing a high-performance alternative to traditional rule-based or simpler ML models, especially when dealing with punctuation-agnostic or domain-specific text.

How it works

The library implements two primary models: SaT (Segment Any Text) and WtP (Where’s the Point?). SaT is the current state-of-the-art approach that predicts newline probabilities to determine where sentences end. It supports various model sizes (from 1 to 12 layers) to balance speed and performance.

Key technical features include:

  • Viterbi Algorithm: Used for length-constrained segmentation to find globally optimal split points based on model predictions and user-defined length preferences.
  • LoRA Adaptation: Allows the models to be efficiently adapted to specific languages, domains (e.g., legal documents, tweets), or styles (e.g., ASR transcriptions) with very little training data.
  • Optimization: Supports torch.compile and ONNX Runtime for significantly faster inference on CPU and GPU.

Who it’s for

Developers and researchers working on NLP pipelines where accurate sentence splitting is a critical first step, particularly those handling multilingual data, non-standard text styles, or requiring strict length constraints for downstream tasks like embedding models.

Highlights

  • Multilingual Support: Robust segmentation across 85 languages.
  • Length Constraints: Ability to enforce minimum and maximum segment lengths using various priors (Gaussian, Log-normal, etc.).
  • Domain Adaptation: Pre-trained LoRA modules for legal, code-switching, and social media text.
  • High Performance: Optimized for speed via ONNX and PyTorch Inductor, with support for GPU and TPU.
  • Paragraph Segmentation: Capability to split text into paragraphs in addition to sentences.

Related

  • Project
  • Project
  • Dispatch
  • Project
  • Project