Metadata-Version: 2.4
Name: textslinger
Version: 0.5.0
Summary: TextSlinger: Fast and accurate text predictions in Python
Author-email: Keith Vertanen <vertanen@mtu.edu>, Dylan Gaines <dgaine20@kennesaw.edu>, Soufia Bahmani <sbahmani@mtu.edu>, Blade Frisch <bfrisch@bgsu.edu>
License-Expression: MIT
Project-URL: Homepage, https://github.com/kdv123/textslinger
Project-URL: Source, https://github.com/kdv123/textslinger
Project-URL: Documentation, https://github.com/kdv123/textslinger/blob/main/README.md#documentation
Platform: Linux
Platform: Windows
Platform: Mac OS-X
Classifier: Development Status :: 3 - Alpha
Classifier: Topic :: Scientific/Engineering :: Human Machine Interfaces
Classifier: Natural Language :: English
Classifier: Intended Audience :: Science/Research
Classifier: Intended Audience :: End Users/Desktop
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy<3,>=2.4
Provides-Extra: ngram
Requires-Dist: kenlm<0.4,>=0.3.0; extra == "ngram"
Provides-Extra: llm
Requires-Dist: torch>=2.13.0; extra == "llm"
Requires-Dist: accelerate>=1.1.0; extra == "llm"
Requires-Dist: transformers<6,>=5.15.1; extra == "llm"
Requires-Dist: peft<1,>=0.21.3; extra == "llm"
Requires-Dist: sentencepiece>=0.2.1; extra == "llm"
Requires-Dist: protobuf<7,>=5; extra == "llm"
Requires-Dist: regex; extra == "llm"
Provides-Extra: quantization
Requires-Dist: textslinger[llm]; extra == "quantization"
Requires-Dist: bitsandbytes>=0.50.2; extra == "quantization"
Provides-Extra: eval
Requires-Dist: textslinger[llm,ngram]; extra == "eval"
Requires-Dist: datasets>=2.18.0; extra == "eval"
Requires-Dist: scipy; extra == "eval"
Requires-Dist: huggingface-hub; extra == "eval"
Requires-Dist: lm-eval==0.4.13; extra == "eval"
Provides-Extra: dev
Requires-Dist: textslinger[eval]; extra == "dev"
Requires-Dist: coverage>=7.0; extra == "dev"
Requires-Dist: pytest; extra == "dev"
Requires-Dist: black; extra == "dev"
Provides-Extra: release
Requires-Dist: twine==5.0.0; extra == "release"
Requires-Dist: build>=1.4.0; extra == "release"
Requires-Dist: wheel==0.43.0; extra == "release"
Provides-Extra: all
Requires-Dist: textslinger[dev,eval,llm,ngram,quantization,release]; extra == "all"
Dynamic: license-file

<table border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="120">
      <a href="images/textslinger.png"><img src="images/textslinger_small.jpg" width="236" alt="Cowboy drawing his two cell phone six shooters"></a>
    </td>
    <td align="center">
      <h2>TextSlinger: Fast and Accurate Text Predictions in Python</h2>
    </td>
  </tr>
</table>

TextSlinger predicts characters and words from accepted text and optional noisy input observations.
It supports character n-grams through [KenLM](https://github.com/kpu/kenlm), Prediction by Partial
Matching (PPM), Hugging Face subword language models, and Byte Latent Transformer (BLT).

Use it to build predictive text-entry applications, score supplied strings, or evaluate prediction
quality and latency. Results include probability evidence and bounds on uncertainty left by a
limited search.

## Getting started

TextSlinger requires **Python 3.12 or newer**. Python 3.13 is recommended for new environments.
Follow the
[installation guide](docs/installation.md) to install the library, choose a PyTorch build for your
device, and download any model assets you need. The base install (`pip install textslinger`) supports
PPM without PyTorch or KenLM. Install `textslinger[ngram]` for KenLM or `textslinger[llm]` for neural
models; evaluation scripts use `textslinger[eval]`.

This small PPM example trains from text and needs no downloaded model:

```python
from textslinger import PPM

model = PPM.from_training_texts(["the cat sat ", "the car stopped "])
characters = model.predict_characters(
    left_context="the ca",
    output_characters=tuple("abcdefghijklmnopqrstuvwxyz "),
)
words = model.predict_words(left_context="the ca", nbest=3)

print([prediction.character for prediction in characters.top(3)])
print([prediction.word for prediction in words.predictions])
```

Every character request specifies its output alphabet. Word requests can restrict spellings, endings
and vocabulary, or supply likelihoods for uncertain input. See the [prediction API](docs/api.md) for
examples, result interpretation, quantized model loading and cancellation.

## Capabilities and limits

- **Character prediction** supports Unicode output across token boundaries for supported byte
  tokenizers. Unicode word prediction has narrower support; see
  [Unicode scope](docs/api.md#unicode-scope).
- **Word prediction** supports autocomplete, complete-input recognition, and mixtures of the two.
  Noisy observations describe input after the accepted context, rather than replacing that context.
- **Search bounds** describe unexplored probability mass within the model's conditioning policy.
  They do not bound every source of numerical or tokenization error; see
  [probability bounds](docs/api.md#scope-of-probability-bounds).
- **Optional compilation** prepares frequently used subword-model calculations before serving
  requests. Long-running applications can use
  [`prepare_compilation()`](docs/subword.md#one-call-optional-compilation). Uncovered cases use
  ordinary inference without compiling during a request.

## Documentation

| Guide                                                       | Contents                                                |
| ----------------------------------------------------------- | ------------------------------------------------------- |
| [Installation](docs/installation.md)                        | Environments, dependencies and model assets             |
| [Prediction API](docs/api.md)                               | Model construction, requests, results and cancellation  |
| [Scripts](docs/scripts.md)                                  | Evaluation, simulation and profiling commands           |
| [Tests](docs/testing.md)                                    | Backend checks, precision and regression references     |
| [Subword engine](docs/subword.md)                           | Search algorithms, caching, compilation and diagnostics |
| [Optimization decisions](docs/optimizations.md)             | Measured benefits, limitations and rejected approaches  |
| [Mathematical overview](docs/math.tex)                      | Inference model with a touchscreen example              |
| [Mathematical implementation](docs/math-implementation.tex) | How the model maps to code                              |

For HTTP and WebSocket serving, use
[TextSlinger Server](https://github.com/kdv123/textslinger-server).

---

This material is based upon work supported by the NSF under Grant No. IIS-1909089 and IIS-2402876.
