Skip to content

Quick Start

Use the fast U-Net model to display a text file with content-type highlighting:

Terminal window
typeseg --model fast file.txt

For Mamba, use typeseg --model precise file.txt. The CLI defaults to Mamba if you omit --model. Mamba uses context across the file and can improve labels near type changes, with a longer wait on CPU. Choosing a model explains the tradeoff.

The Command Line guide covers stdin, the segcat alias, terminal colors, and the segment table.

import typeseg
text = '<html><style>body { color: blue; }</style></html>'
result = typeseg.fast(text) # U-Net: start here for throughput
for segment in result.segments:
print(segment.label, segment.start, segment.end, segment.confidence)
print(text[segment.start:segment.end])

result.segments contains contiguous runs with a label, start, end, confidence, and matched text. Boundaries are Python character offsets, with the end excluded. The exact predictions depend on the model and post-processing.

Use typeseg.precise(text) for Mamba’s full-file context. Both functions return the same result type, so you can compare them without changing downstream code.

Preserve segment order. Draw each region with width proportional to segment.end - segment.start, and use a consistent color for each label. Link each region to the corresponding source range.

For byte-based viewers, map decoded character offsets to the original encoding before displaying byte ranges. Understanding the Output includes a UTF-8 example.