Skip to main content

sourcetext

PyPI CI License: MIT

Return to the source text behind your model output.

Sometimes, working with and understanding a text corpus requires more than your NLP models' output. It requires inspection of the source text: looking at the documents behind a prediction, a cluster, or an outlier score.

sourcetext gives you that in three lines of Python code. Hand it your texts and your model's output (labels, scores, clusters, embeddings, dates), and it opens a local web app where you can navigate your documents by their annotations and read each one in full.

Quickstart

Install with pip:

pip install sourcetext

Then integrate in your NLP workflow.

from sourcetext import SourceText

texts = [
    "The harvest failed for the third year running.",
    "A new bridge was opened to great celebration.",
    "Grain prices rose sharply in the spring.",
]
predictions = ["negative", "positive", "negative"]

st = SourceText(texts, prediction=predictions)
st.start_server()  # then open http://localhost:8001

And dive into the source text in a simple UI in your browser.

The sourcetext app

In a script, start_server() blocks until you press Ctrl+C. In Jupyter it runs in the background, so you can keep working and call st.stop_server() when done.

The app has:

  • Table view: sort, search and filter documents by any field.
  • Plot view: embeddings, or any two fields against each other.
  • Confusion matrix view: cross two label fields, click a cell to read its documents.
  • Span view: find documents by their span annotations (e.g. NER).
  • Document pane: read a document in full, with all its field values.
  • Notes: write a note on any document, saved to a JSONL file.

Fields

Everything you pass beyond the texts is a field: one value per document. The common cases have named arguments (prediction=, confidence=, gold_label=, score=, embedding=, group=). Any other keyword argument adds a field with that name, wrapped in its type:

from sourcetext import LabelType, ScoreType, SourceText

SourceText(
    texts,
    prediction=preds,
    toxicity=ScoreType(toxicity_scores),
    genre=LabelType(genres),
)
Type Values Typical use
TextType str titles, authors, source metadata
LabelType str, int, bool classes, gold labels, clusters, topics
ScoreType float, int confidence, sentiment, any metric
TemporalType year (int), date, datetime publication year, timestamps
Point2DType (x, y) pair of numbers UMAP / t-SNE embedding projections
SpanType list of {"start", "end", ...} dicts named entities, marked passages

Every argument also takes a column name when you pass a DataFrame as data=.

Documentation

  • Examples: classification, topic models, embeddings, named entities, DataFrames.
  • API reference: SourceText's arguments, field types, label definitions, serving the app.
  • Notes: where notes are saved and how they're matched back to documents.

Project status

sourcetext is in early development (alpha). The API may change between releases, and some parts are not built yet:

See the roadmap for what's planned next.

Feedback and issues are very welcome at github.com/KasperFyhn/sourcetext/issues.

Contributing

Development setup, the architecture, and how the Python package and the React frontend fit together are described in CLAUDE.md. In short:

pip install -e ".[dev]"
pre-commit install
pytest
./scripts/dev.sh classification_simple   # API + hot-reloading UI on a mock dataset

License

MIT

Metadata

Release files for sourcetext 0.3.0

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

Source distribution (sdist)

Source distribution for sourcetext 0.3.0
File Size Uploaded Provenance Actions
sourcetext-0.3.0.tar.gz 285.0 kB With provenance Details for sourcetext-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sourcetext 0.3.0
File Interpreter ABI Platform Actions
sourcetext-0.3.0-py3-none-any.whl Python 3 none any Details for sourcetext-0.3.0-py3-none-any.whl

Total release size: 564.7 kB

Release files / sourcetext-0.3.0.tar.gz

Download URL sourcetext-0.3.0.tar.gz
Size 285.0 kB
Tags Source
SHA-256 checksum
How to use checksums
20f6e2d23a4eb8e1c1da2a2b013c6f2251fdd47e53da5d69d44d9c878a552dd3
BLAKE2b-256 checksum
How to use checksums
e5f338ee6e3b2523b40ee7acdb3bd4a1887dd58c9e9da7ceeb6b715a3af5d663
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.

Transparency log

Release files / sourcetext-0.3.0-py3-none-any.whl

Download URL sourcetext-0.3.0-py3-none-any.whl
Size 279.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cf17a98331c917ba61bdfd215a8164baed48e9b5d36049a64dca6f5faed1a5d7
BLAKE2b-256 checksum
How to use checksums
45de504c641c0d59b556a23b444114bcd0b3f21203038c622fc2e85fc904d1a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.

Transparency log

Security for sourcetext 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for sourcetext-0.3.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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