rt_seg is a Python 3.12.x package for segmenting reasoning traces into coherent chunks and (optionally) assigning a label to each chunk.
The main entry point is:
RTSeg
(from rt_segmentation.seg_factory)
It orchestrates one or more segmentation engines and — if multiple engines are used — an offset aligner that fuses their boundaries into a single segmentation.
rt_seg_demo.mp4
pip install rt-segpython3.12 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtNote: requires NVIDIA GPU (12.4.1+).
docker build -f docker/Dockerfile -t mytui:gpu .
docker run -it --rm --gpus all mytui:gpu
# podman build -f docker/Dockerfile -t mytui:gpu .
# podman run -it --rm --device nvidia.com/gpu=all mytui:gpuRTSeg(trace) produces:
offsets:list[tuple[int, int]]— character offsets into the tracelabels:list[str]— one label per segment
You can reconstruct segments via:
segments = [trace[s:e] for (s, e) in offsets]Most engines operate on a base segmentation first:
"clause"(default) → finer granularity"sent"→ coarser segmentation
from rt_seg import RTSeg
from rt_seg import RTRuleRegex
trace = "First step... Then second step... Finally conclude."
segmentor = RTSeg(
engines=RTRuleRegex,
seg_base_unit="clause",
)
offsets, labels = segmentor(trace)
for (s, e), label in zip(offsets, labels):
print(label, "=>", trace[s:e])If you pass multiple engines, you must provide an aligner.
from rt_seg import RTSeg
from rt_seg import RTRuleRegex
from rt_seg import RTBERTopicSegmentation
from rt_seg import OffsetFusionGraph
segmentor = RTSeg(
engines=[RTRuleRegex, RTBERTopicSegmentation],
aligner=OffsetFusionGraph,
label_fusion_type="concat", # or "majority"
seg_base_unit="clause",
)
offsets, labels = segmentor(trace)"majority"— choose most frequent label"concat"— concatenate labels (useful for debugging)
RTRuleRegexRTNewLine
RTLLMForcedDecoderBasedRTLLMSurprisalRTLLMEntropyRTLLMTopKShiftRTLLMFlatnessBreak
RTLLMThoughtAnchorRTLLMReasoningFlowRTLLMArgument
RTLLMOffsetBasedRTLLMSegUnitBased
RTPRMBase
RTBERTopicSegmentationRTEmbeddingBasedSemanticShiftRTEntailmentBasedSegmentationRTZeroShotSeqClassificationRTZeroShotSeqClassificationRFRTZeroShotSeqClassificationTA
You can override engine parameters at call time:
offsets, labels = segmentor(
trace,
model_name="Qwen/Qwen2.5-7B-Instruct",
chunk_size=200,
)OffsetFusionGraphOffsetFusionFuzzyOffsetFusionIntersectOffsetFusionMergeOffsetFusionVoting
| Strategy | Behavior |
|---|---|
| Intersect | Conservative |
| Merge | Permissive |
| Voting / Graph / Fuzzy | Balanced (recommended) |
from typing import Tuple, List
from rt_seg import SegBase
class MyEngine(SegBase):
@staticmethod
def _segment(trace: str, **kwargs) -> Tuple[List[tuple[int, int]], List[str]]:
offsets = [(0, len(trace))]
labels = ["UNK"]
return offsets, labelsbase_offsets = SegBase.get_base_offsets(trace, seg_base_unit="clause")from typing import List, Tuple
class MyOffsetFusion:
@staticmethod
def fuse(engine_offsets: List[List[Tuple[int, int]]], **kwargs):
return engine_offsets[0]python3.12 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
python -m tuiIf needed:
python src/tui.pyRequired only for full experiment pipeline.
docker run --rm -it \
-p 8000:8000 \
-v "$(pwd)/data:/data" \
surrealdb/surrealdb:latest \
start --user root --pass root file:/data/surreal.dbEndpoints:
- WebSocket:
ws://127.0.0.1:8000/rpc - HTTP:
http://127.0.0.1:8000
surreal import \
--endpoint ws://127.0.0.1:8000/rpc \
--username root \
--password root \
--namespace NR \
--database RT \
./data/YOUR_EXPORT_FILE.surql{
"user": "root",
"pwd": "root",
"ns": "NR",
"db": "RT",
"url": "ws://127.0.0.1:8000/rpc"
}python src/eval_main.py
python src/evo.py- Linux
- NVIDIA GPU
- NVIDIA driver
- Docker
- NVIDIA Container Toolkit
Verify:
nvidia-smi
docker run --rm --gpus all nvidia/cuda:12.4.1-base-ubuntu22.04 nvidia-smiHost driver CUDA ≥ Container CUDA
| Host | Container | Result |
|---|---|---|
| 12.8 | 12.4 | ✅ |
| 12.8 | 13.1 | ❌ |
| 13.x | 12.4 | ✅ |
docker build -f docker/Dockerfile -t rt-seg:gpu ../run_tui_app_docker.shInternally:
docker run -it --rm --gpus all rt-seg:gpuRT-SEG provides:
- Modular segmentation engines
- Late fusion strategies
- LLM-based reasoning segmentation
- Reproducible DB-backed experiments
- GPU Docker deployment