rtsa 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- rtsa-0.1.0/LICENSE +21 -0
- rtsa-0.1.0/PKG-INFO +220 -0
- rtsa-0.1.0/README.md +153 -0
- rtsa-0.1.0/pyproject.toml +106 -0
- rtsa-0.1.0/rtsa/__init__.py +26 -0
- rtsa-0.1.0/rtsa/__main__.py +5 -0
- rtsa-0.1.0/rtsa/analysis/__init__.py +59 -0
- rtsa-0.1.0/rtsa/analysis/benchmark.py +358 -0
- rtsa-0.1.0/rtsa/analysis/fingerprint.py +325 -0
- rtsa-0.1.0/rtsa/analysis/performance_correlation.py +382 -0
- rtsa-0.1.0/rtsa/analysis/prune.py +657 -0
- rtsa-0.1.0/rtsa/analysis/signal_adapters.py +146 -0
- rtsa-0.1.0/rtsa/analysis/step_classifier.py +274 -0
- rtsa-0.1.0/rtsa/analysis/step_clustering.py +193 -0
- rtsa-0.1.0/rtsa/cli.py +434 -0
- rtsa-0.1.0/rtsa/config/__init__.py +34 -0
- rtsa-0.1.0/rtsa/core/__init__.py +31 -0
- rtsa-0.1.0/rtsa/core/metrics.py +525 -0
- rtsa-0.1.0/rtsa/core/motif_matcher.py +586 -0
- rtsa-0.1.0/rtsa/core/ngs_validator.py +628 -0
- rtsa-0.1.0/rtsa/core/robust_tsi.py +488 -0
- rtsa-0.1.0/rtsa/core/types.py +443 -0
- rtsa-0.1.0/rtsa/demo.py +99 -0
- rtsa-0.1.0/rtsa/experiments/__init__.py +1 -0
- rtsa-0.1.0/rtsa/experiments/annotate_steps.py +105 -0
- rtsa-0.1.0/rtsa/experiments/calibrate_thresholds.py +331 -0
- rtsa-0.1.0/rtsa/experiments/correlation_analysis.py +207 -0
- rtsa-0.1.0/rtsa/experiments/data_analysis.py +242 -0
- rtsa-0.1.0/rtsa/experiments/end_to_end_prune.py +391 -0
- rtsa-0.1.0/rtsa/experiments/pilot.py +354 -0
- rtsa-0.1.0/rtsa/experiments/run.py +456 -0
- rtsa-0.1.0/rtsa/experiments/synthetic_redundant_cots.py +221 -0
- rtsa-0.1.0/rtsa/extractors/__init__.py +30 -0
- rtsa-0.1.0/rtsa/extractors/agreement.py +634 -0
- rtsa-0.1.0/rtsa/extractors/analysis.py +139 -0
- rtsa-0.1.0/rtsa/extractors/baselines.py +221 -0
- rtsa-0.1.0/rtsa/extractors/experiments.py +264 -0
- rtsa-0.1.0/rtsa/extractors/gcp_validator.py +498 -0
- rtsa-0.1.0/rtsa/extractors/inter_annotator.py +134 -0
- rtsa-0.1.0/rtsa/extractors/llm_extractor.py +380 -0
- rtsa-0.1.0/rtsa/extractors/random_baseline.py +121 -0
- rtsa-0.1.0/rtsa/extractors/rule_based.py +578 -0
- rtsa-0.1.0/rtsa/extractors/syntax_based.py +448 -0
- rtsa-0.1.0/rtsa/extractors/synthetic_validation.py +198 -0
- rtsa-0.1.0/rtsa/utils/__init__.py +15 -0
- rtsa-0.1.0/rtsa/utils/data_loader.py +287 -0
- rtsa-0.1.0/rtsa/utils/gsm8k_loader.py +151 -0
- rtsa-0.1.0/rtsa/utils/hf_adapter.py +260 -0
- rtsa-0.1.0/rtsa/utils/math_loader.py +257 -0
- rtsa-0.1.0/rtsa/utils/trace_exporters.py +197 -0
- rtsa-0.1.0/rtsa/utils/visualize.py +95 -0
- rtsa-0.1.0/rtsa.egg-info/PKG-INFO +220 -0
- rtsa-0.1.0/rtsa.egg-info/SOURCES.txt +78 -0
- rtsa-0.1.0/rtsa.egg-info/dependency_links.txt +1 -0
- rtsa-0.1.0/rtsa.egg-info/entry_points.txt +2 -0
- rtsa-0.1.0/rtsa.egg-info/requires.txt +46 -0
- rtsa-0.1.0/rtsa.egg-info/top_level.txt +1 -0
- rtsa-0.1.0/setup.cfg +4 -0
- rtsa-0.1.0/tests/test_agreement.py +134 -0
- rtsa-0.1.0/tests/test_analysis_utils.py +180 -0
- rtsa-0.1.0/tests/test_baselines.py +191 -0
- rtsa-0.1.0/tests/test_benchmark.py +133 -0
- rtsa-0.1.0/tests/test_calibrate_thresholds.py +62 -0
- rtsa-0.1.0/tests/test_config_loader.py +90 -0
- rtsa-0.1.0/tests/test_extractors.py +232 -0
- rtsa-0.1.0/tests/test_fingerprint.py +134 -0
- rtsa-0.1.0/tests/test_gcp.py +158 -0
- rtsa-0.1.0/tests/test_hf_adapter.py +58 -0
- rtsa-0.1.0/tests/test_llm_extractor.py +117 -0
- rtsa-0.1.0/tests/test_metrics.py +108 -0
- rtsa-0.1.0/tests/test_motif_matcher.py +132 -0
- rtsa-0.1.0/tests/test_ngs_validator.py +230 -0
- rtsa-0.1.0/tests/test_performance_correlation.py +120 -0
- rtsa-0.1.0/tests/test_prune.py +224 -0
- rtsa-0.1.0/tests/test_robust_tsi.py +236 -0
- rtsa-0.1.0/tests/test_run_cli.py +38 -0
- rtsa-0.1.0/tests/test_step_classifier.py +103 -0
- rtsa-0.1.0/tests/test_step_clustering.py +67 -0
- rtsa-0.1.0/tests/test_trace_exporters.py +36 -0
- rtsa-0.1.0/tests/test_types.py +186 -0
rtsa-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Fengrru
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
rtsa-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rtsa
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Reasoning Trace Structure Analysis Toolkit — extract, analyze, prune, fingerprint, and benchmark CoT reasoning graphs
|
|
5
|
+
Author: Fengrru
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/Fengrru/rtsa
|
|
8
|
+
Project-URL: Repository, https://github.com/Fengrru/rtsa
|
|
9
|
+
Project-URL: Issues, https://github.com/Fengrru/rtsa/issues
|
|
10
|
+
Project-URL: Documentation, https://github.com/Fengrru/rtsa#readme
|
|
11
|
+
Project-URL: Changelog, https://github.com/Fengrru/rtsa/blob/main/CHANGELOG.md
|
|
12
|
+
Keywords: chain-of-thought,reasoning,llm,graph-analysis,pruning,redundancy-detection,structured-reasoning,cot-evaluation
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Science/Research
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
21
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
22
|
+
Classifier: Operating System :: OS Independent
|
|
23
|
+
Requires-Python: >=3.10
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
Requires-Dist: numpy>=1.24.0
|
|
27
|
+
Requires-Dist: scipy>=1.11.0
|
|
28
|
+
Requires-Dist: networkx>=3.1
|
|
29
|
+
Requires-Dist: scikit-learn>=1.3.0
|
|
30
|
+
Requires-Dist: statsmodels>=0.14.0
|
|
31
|
+
Requires-Dist: pandas>=2.0.0
|
|
32
|
+
Requires-Dist: matplotlib>=3.7.0
|
|
33
|
+
Requires-Dist: seaborn>=0.12.0
|
|
34
|
+
Requires-Dist: spacy>=3.6.0
|
|
35
|
+
Requires-Dist: pyyaml>=6.0
|
|
36
|
+
Requires-Dist: tqdm>=4.65.0
|
|
37
|
+
Requires-Dist: pydantic>=2.0
|
|
38
|
+
Requires-Dist: orjson>=3.9.0
|
|
39
|
+
Provides-Extra: dev
|
|
40
|
+
Requires-Dist: pytest>=7.4.0; extra == "dev"
|
|
41
|
+
Requires-Dist: pytest-cov>=4.1.0; extra == "dev"
|
|
42
|
+
Requires-Dist: pytest-xdist>=3.3.0; extra == "dev"
|
|
43
|
+
Provides-Extra: hf
|
|
44
|
+
Requires-Dist: datasets>=2.14.0; extra == "hf"
|
|
45
|
+
Provides-Extra: obs
|
|
46
|
+
Requires-Dist: opentelemetry-api>=1.20.0; extra == "obs"
|
|
47
|
+
Requires-Dist: opentelemetry-sdk>=1.20.0; extra == "obs"
|
|
48
|
+
Requires-Dist: opentelemetry-exporter-otlp>=1.20.0; extra == "obs"
|
|
49
|
+
Requires-Dist: langfuse>=2.0.0; extra == "obs"
|
|
50
|
+
Provides-Extra: notebook
|
|
51
|
+
Requires-Dist: jupyter>=1.0.0; extra == "notebook"
|
|
52
|
+
Requires-Dist: nbformat>=5.9.0; extra == "notebook"
|
|
53
|
+
Provides-Extra: llm
|
|
54
|
+
Requires-Dist: openai>=1.0.0; extra == "llm"
|
|
55
|
+
Requires-Dist: anthropic>=0.20.0; extra == "llm"
|
|
56
|
+
Requires-Dist: transformers>=4.35.0; extra == "llm"
|
|
57
|
+
Requires-Dist: torch>=2.1.0; extra == "llm"
|
|
58
|
+
Provides-Extra: all
|
|
59
|
+
Requires-Dist: datasets>=2.14.0; extra == "all"
|
|
60
|
+
Requires-Dist: opentelemetry-api>=1.20.0; extra == "all"
|
|
61
|
+
Requires-Dist: opentelemetry-sdk>=1.20.0; extra == "all"
|
|
62
|
+
Requires-Dist: opentelemetry-exporter-otlp>=1.20.0; extra == "all"
|
|
63
|
+
Requires-Dist: langfuse>=2.0.0; extra == "all"
|
|
64
|
+
Requires-Dist: jupyter>=1.0.0; extra == "all"
|
|
65
|
+
Requires-Dist: nbformat>=5.9.0; extra == "all"
|
|
66
|
+
Dynamic: license-file
|
|
67
|
+
|
|
68
|
+
<h1 align="center">RTSA</h1>
|
|
69
|
+
|
|
70
|
+
<p align="center"><strong>Reasoning Trace Structure Analysis</strong> — study Chain-of-Thought reasoning as a structured graph; no white-box model access required.</p>
|
|
71
|
+
|
|
72
|
+
<p align="center">
|
|
73
|
+
<a href="https://www.python.org/downloads/"><img src="https://img.shields.io/badge/python-3.10+-blue.svg" alt="Python 3.10+"></a>
|
|
74
|
+
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License: MIT"></a>
|
|
75
|
+
<a href="https://github.com/Fengrru/rtsa/actions"><img src="https://img.shields.io/badge/CI-GitHub%20Actions-green.svg" alt="CI"></a>
|
|
76
|
+
<a href="https://github.com/Fengrru/rtsa/actions"><img src="https://img.shields.io/badge/tests-322%20passing-green.svg" alt="tests: 322"></a>
|
|
77
|
+
</p>
|
|
78
|
+
|
|
79
|
+
<p align="center"><a href="docs/README.md">Documentation</a> · <a href="docs/api.md">API Reference</a> · <a href="docs/comparison.md">Comparison</a> · <a href="CHANGELOG.md">Changelog</a></p>
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## Motivation
|
|
84
|
+
|
|
85
|
+
Long reasoning traces are expensive to generate, opaque to inspect, and hard to verify — yet most tooling treats them as flat strings. RTSA parses CoT text into a typed DAG (Retrieve / Transform / Verify / Branch / Backtrack / Compare) and makes structural analysis practical: where the redundancy is, which step is likely wrong, whether structure predicts correctness, and who wrote the trace. Everything is computed from the text alone, so it works with any API-only model, requires no annotations, and every analysis is reproducible through a versioned experiment entrypoint.
|
|
86
|
+
|
|
87
|
+
## Example Extraction
|
|
88
|
+
|
|
89
|
+

|
|
90
|
+
|
|
91
|
+
Real extraction (rule-based) of a MATH problem's human solution: 6 nodes, 8 edges. Each node type carries a distinct color; the graph is the input to every downstream analysis.
|
|
92
|
+
|
|
93
|
+
## Quickstart
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
pip install rtsa
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
from rtsa.extractors import RuleBasedExtractor
|
|
101
|
+
from rtsa.core.ngs_validator import NGSValidator
|
|
102
|
+
from rtsa.analysis.prune import RedundancyAnalyzer, PruneConfig
|
|
103
|
+
|
|
104
|
+
text = "Retrieve x=3. Transform: x*2=6. Verify: 6 is even."
|
|
105
|
+
graph = RuleBasedExtractor().extract(text, trace_id="demo_001")
|
|
106
|
+
|
|
107
|
+
valid, violations = NGSValidator().validate(graph)
|
|
108
|
+
report = RedundancyAnalyzer(config=PruneConfig()).analyze(graph, apply_pruning=True)
|
|
109
|
+
print(report.summary())
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
rtsa extract cot.txt --extractor rbe --output graph.json
|
|
114
|
+
rtsa validate graph.json
|
|
115
|
+
rtsa prune graph.json --apply --output pruned.json
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## What RTSA Answers
|
|
119
|
+
|
|
120
|
+
| Question | Answer |
|
|
121
|
+
|---|---|
|
|
122
|
+
| Is this trace redundant, and where? | Region-level redundancy detection + executable DAG pruning (`rtsa/analysis/prune.py`) |
|
|
123
|
+
| Is this reasoning step correct? | Black-box step classifier on 17 structural features (`rtsa/analysis/step_classifier.py`, CRV-inspired) |
|
|
124
|
+
| Does structure predict correctness? | 19-metric benchmark with FDR correction and bootstrap CIs (`rtsa/analysis/performance_correlation.py`) |
|
|
125
|
+
| Which model wrote this? | Structural-style authorship fingerprinting (`rtsa fingerprint`) |
|
|
126
|
+
| How similar are two traces? | Supervised Robust-TSI + unsupervised WL-kernel similarity |
|
|
127
|
+
|
|
128
|
+
## Capabilities
|
|
129
|
+
|
|
130
|
+
| Capability | Implementation | Maturity |
|
|
131
|
+
|---|---|---|
|
|
132
|
+
| CoT -> graph extraction | `rtsa/extractors/` (rule / syntax / LLM / random baselines) | Stable |
|
|
133
|
+
| Structural validation | `rtsa/core/ngs_validator.py` — 13 NGS rules, Type I/II failure modes (7 classes) | Stable |
|
|
134
|
+
| Redundancy pruning | `rtsa/analysis/prune.py` — 4 detectors, DAG-preserving, domain-adaptive thresholds | Stable |
|
|
135
|
+
| Step-level analysis | `rtsa/analysis/step_classifier.py` `step_clustering.py` — 17-dim error probability, macro-step clustering | Evolving |
|
|
136
|
+
| Similarity & fingerprinting | `rtsa/core/robust_tsi.py` `rtsa/analysis/fingerprint.py` — supervised TSI, WL-kernel, authorship | Stable |
|
|
137
|
+
| Performance-correlation benchmark | `rtsa/analysis/performance_correlation.py` — 19 metrics, Spearman + BH-FDR + bootstrap CI | Evolving |
|
|
138
|
+
| Statistical rigor | `rtsa/core/robust_tsi.py` — bootstrap CI, Cohen's d, savings error bands | Stable |
|
|
139
|
+
| Extractor benchmarking | `rtsa/analysis/benchmark.py` — GCP + NGS pass rate + TSI | Stable |
|
|
140
|
+
| Dataset adapters | `rtsa/utils/hf_adapter.py` — any HuggingFace CoT dataset | Evolving |
|
|
141
|
+
| Observability | `rtsa/utils/trace_exporters.py` — OTLP / Langfuse, no-op fallback | Experimental |
|
|
142
|
+
| Reproducible experiments | `rtsa/experiments/run.py` — versioned runs + manifest.json | Stable |
|
|
143
|
+
|
|
144
|
+
Maturity levels: **Stable** (battle-tested, covered by tests) · **Evolving** (functional, API may shift) · **Experimental** (proof of concept, optional deps).
|
|
145
|
+
|
|
146
|
+
## Pipeline
|
|
147
|
+
|
|
148
|
+
```
|
|
149
|
+
raw CoT text (JSONL / HuggingFace datasets)
|
|
150
|
+
| extractors: RBE (rule) · SBE (syntax) · LLM · random baselines
|
|
151
|
+
v
|
|
152
|
+
ReasoningTraceGraph (typed DAG)
|
|
153
|
+
|
|
|
154
|
+
+--> validate NGS structural rules + failure-mode taxonomy
|
|
155
|
+
+--> analyze graph metrics, motifs, TSI/JSD, structure<->correctness
|
|
156
|
+
+--> prune redundancy regions -> pruned graph (DAG-preserving)
|
|
157
|
+
+--> classify per-step error probability (GradientBoosting)
|
|
158
|
+
+--> benchmark GCP · NGS pass rate · TSI · authorship fingerprint
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## Related Work
|
|
162
|
+
|
|
163
|
+
| Work | Focus | RTSA counterpart |
|
|
164
|
+
|---|---|---|
|
|
165
|
+
| [LLM-MindMap](https://arxiv.org/abs/2505.13890) (EMNLP 2025) | Semantic step clustering; structural metrics predict performance | `rtsa/analysis/step_clustering.py` + `rtsa/analysis/performance_correlation.py` |
|
|
166
|
+
| [CRV](https://arxiv.org/abs/2510.09312) (Meta FAIR) | Verify reasoning steps from structural features (AUROC 70-92%); signatures are domain-dependent | `rtsa/analysis/step_classifier.py` + `PruneConfig.domain_overrides` |
|
|
167
|
+
| [CoT2Graph](https://openreview.net/forum?id=0XfuJjhaI5) | CoT-to-graph with reasoning-path validation and failure modes | `rtsa/core/ngs_validator.py` failure-mode taxonomy |
|
|
168
|
+
|
|
169
|
+
A capability-by-capability matrix is maintained in [docs/comparison.md](docs/comparison.md).
|
|
170
|
+
|
|
171
|
+
## Reproducible Experiments
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
python -m experiments.run extract --dataset gsm8k --max-traces 50
|
|
175
|
+
python -m experiments.run correlation --synthetic
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Every run lands in `rtsa/experiments/results/runs/<command>_<timestamp>/` with a `manifest.json` recording git commit, Python version, arguments, and UTC timestamp. See the [full CLI](docs/api.md#layer-5-experiments-experiments) for all subcommands.
|
|
179
|
+
|
|
180
|
+
## Results
|
|
181
|
+
|
|
182
|
+
Selected numbers from the built-in validation and real-data runs (reproducible via the commands above):
|
|
183
|
+
|
|
184
|
+
| Result | Value |
|
|
185
|
+
|---|---|
|
|
186
|
+
| Structural pruning, synthetic corpus | ~12.5% node compression, ~31 tokens/trace saved, 100% NGS pass rate |
|
|
187
|
+
| Structural pruning, GSM8K | self-limits to ~2% compression on naturally compact traces |
|
|
188
|
+
| Performance-correlation benchmark (synthetic validation, n=60) | 19 metrics, 12 significant after BH-FDR |
|
|
189
|
+
| Strongest effect (synthetic) | verify_density rho = -0.858, 95% CI [-0.881, -0.807] |
|
|
190
|
+
| Test suite | 322 tests passing (CI matrix: Python 3.10/3.11/3.12) |
|
|
191
|
+
|
|
192
|
+
## Documentation
|
|
193
|
+
|
|
194
|
+
- [docs/api.md](docs/api.md) — public API reference and module layout
|
|
195
|
+
- [docs/comparison.md](docs/comparison.md) — capability matrix vs. LLM-MindMap / CRV / CoT2Graph
|
|
196
|
+
- [docs/failure_modes.md](docs/failure_modes.md) — NGS failure-mode taxonomy
|
|
197
|
+
- [rtsa/experiments/notebooks/end_to_end.ipynb](rtsa/experiments/notebooks/end_to_end.ipynb) — end-to-end walkthrough
|
|
198
|
+
- [CHANGELOG.md](CHANGELOG.md) — version history (Keep a Changelog)
|
|
199
|
+
|
|
200
|
+
## Tests
|
|
201
|
+
|
|
202
|
+
```bash
|
|
203
|
+
python -m pytest tests/ -q
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## Citation
|
|
207
|
+
|
|
208
|
+
```bibtex
|
|
209
|
+
@software{rtsa2026,
|
|
210
|
+
title={RTSA: Reasoning Trace Structure Analysis Toolkit},
|
|
211
|
+
author={Fengrru},
|
|
212
|
+
year={2026},
|
|
213
|
+
url={https://github.com/Fengrru/rtsa}
|
|
214
|
+
}
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## Contributing & License
|
|
218
|
+
|
|
219
|
+
- Contributing: [CONTRIBUTING.md](CONTRIBUTING.md)
|
|
220
|
+
- License: [MIT](LICENSE)
|
rtsa-0.1.0/README.md
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
<h1 align="center">RTSA</h1>
|
|
2
|
+
|
|
3
|
+
<p align="center"><strong>Reasoning Trace Structure Analysis</strong> — study Chain-of-Thought reasoning as a structured graph; no white-box model access required.</p>
|
|
4
|
+
|
|
5
|
+
<p align="center">
|
|
6
|
+
<a href="https://www.python.org/downloads/"><img src="https://img.shields.io/badge/python-3.10+-blue.svg" alt="Python 3.10+"></a>
|
|
7
|
+
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License: MIT"></a>
|
|
8
|
+
<a href="https://github.com/Fengrru/rtsa/actions"><img src="https://img.shields.io/badge/CI-GitHub%20Actions-green.svg" alt="CI"></a>
|
|
9
|
+
<a href="https://github.com/Fengrru/rtsa/actions"><img src="https://img.shields.io/badge/tests-322%20passing-green.svg" alt="tests: 322"></a>
|
|
10
|
+
</p>
|
|
11
|
+
|
|
12
|
+
<p align="center"><a href="docs/README.md">Documentation</a> · <a href="docs/api.md">API Reference</a> · <a href="docs/comparison.md">Comparison</a> · <a href="CHANGELOG.md">Changelog</a></p>
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## Motivation
|
|
17
|
+
|
|
18
|
+
Long reasoning traces are expensive to generate, opaque to inspect, and hard to verify — yet most tooling treats them as flat strings. RTSA parses CoT text into a typed DAG (Retrieve / Transform / Verify / Branch / Backtrack / Compare) and makes structural analysis practical: where the redundancy is, which step is likely wrong, whether structure predicts correctness, and who wrote the trace. Everything is computed from the text alone, so it works with any API-only model, requires no annotations, and every analysis is reproducible through a versioned experiment entrypoint.
|
|
19
|
+
|
|
20
|
+
## Example Extraction
|
|
21
|
+
|
|
22
|
+

|
|
23
|
+
|
|
24
|
+
Real extraction (rule-based) of a MATH problem's human solution: 6 nodes, 8 edges. Each node type carries a distinct color; the graph is the input to every downstream analysis.
|
|
25
|
+
|
|
26
|
+
## Quickstart
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pip install rtsa
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
from rtsa.extractors import RuleBasedExtractor
|
|
34
|
+
from rtsa.core.ngs_validator import NGSValidator
|
|
35
|
+
from rtsa.analysis.prune import RedundancyAnalyzer, PruneConfig
|
|
36
|
+
|
|
37
|
+
text = "Retrieve x=3. Transform: x*2=6. Verify: 6 is even."
|
|
38
|
+
graph = RuleBasedExtractor().extract(text, trace_id="demo_001")
|
|
39
|
+
|
|
40
|
+
valid, violations = NGSValidator().validate(graph)
|
|
41
|
+
report = RedundancyAnalyzer(config=PruneConfig()).analyze(graph, apply_pruning=True)
|
|
42
|
+
print(report.summary())
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
rtsa extract cot.txt --extractor rbe --output graph.json
|
|
47
|
+
rtsa validate graph.json
|
|
48
|
+
rtsa prune graph.json --apply --output pruned.json
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## What RTSA Answers
|
|
52
|
+
|
|
53
|
+
| Question | Answer |
|
|
54
|
+
|---|---|
|
|
55
|
+
| Is this trace redundant, and where? | Region-level redundancy detection + executable DAG pruning (`rtsa/analysis/prune.py`) |
|
|
56
|
+
| Is this reasoning step correct? | Black-box step classifier on 17 structural features (`rtsa/analysis/step_classifier.py`, CRV-inspired) |
|
|
57
|
+
| Does structure predict correctness? | 19-metric benchmark with FDR correction and bootstrap CIs (`rtsa/analysis/performance_correlation.py`) |
|
|
58
|
+
| Which model wrote this? | Structural-style authorship fingerprinting (`rtsa fingerprint`) |
|
|
59
|
+
| How similar are two traces? | Supervised Robust-TSI + unsupervised WL-kernel similarity |
|
|
60
|
+
|
|
61
|
+
## Capabilities
|
|
62
|
+
|
|
63
|
+
| Capability | Implementation | Maturity |
|
|
64
|
+
|---|---|---|
|
|
65
|
+
| CoT -> graph extraction | `rtsa/extractors/` (rule / syntax / LLM / random baselines) | Stable |
|
|
66
|
+
| Structural validation | `rtsa/core/ngs_validator.py` — 13 NGS rules, Type I/II failure modes (7 classes) | Stable |
|
|
67
|
+
| Redundancy pruning | `rtsa/analysis/prune.py` — 4 detectors, DAG-preserving, domain-adaptive thresholds | Stable |
|
|
68
|
+
| Step-level analysis | `rtsa/analysis/step_classifier.py` `step_clustering.py` — 17-dim error probability, macro-step clustering | Evolving |
|
|
69
|
+
| Similarity & fingerprinting | `rtsa/core/robust_tsi.py` `rtsa/analysis/fingerprint.py` — supervised TSI, WL-kernel, authorship | Stable |
|
|
70
|
+
| Performance-correlation benchmark | `rtsa/analysis/performance_correlation.py` — 19 metrics, Spearman + BH-FDR + bootstrap CI | Evolving |
|
|
71
|
+
| Statistical rigor | `rtsa/core/robust_tsi.py` — bootstrap CI, Cohen's d, savings error bands | Stable |
|
|
72
|
+
| Extractor benchmarking | `rtsa/analysis/benchmark.py` — GCP + NGS pass rate + TSI | Stable |
|
|
73
|
+
| Dataset adapters | `rtsa/utils/hf_adapter.py` — any HuggingFace CoT dataset | Evolving |
|
|
74
|
+
| Observability | `rtsa/utils/trace_exporters.py` — OTLP / Langfuse, no-op fallback | Experimental |
|
|
75
|
+
| Reproducible experiments | `rtsa/experiments/run.py` — versioned runs + manifest.json | Stable |
|
|
76
|
+
|
|
77
|
+
Maturity levels: **Stable** (battle-tested, covered by tests) · **Evolving** (functional, API may shift) · **Experimental** (proof of concept, optional deps).
|
|
78
|
+
|
|
79
|
+
## Pipeline
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
raw CoT text (JSONL / HuggingFace datasets)
|
|
83
|
+
| extractors: RBE (rule) · SBE (syntax) · LLM · random baselines
|
|
84
|
+
v
|
|
85
|
+
ReasoningTraceGraph (typed DAG)
|
|
86
|
+
|
|
|
87
|
+
+--> validate NGS structural rules + failure-mode taxonomy
|
|
88
|
+
+--> analyze graph metrics, motifs, TSI/JSD, structure<->correctness
|
|
89
|
+
+--> prune redundancy regions -> pruned graph (DAG-preserving)
|
|
90
|
+
+--> classify per-step error probability (GradientBoosting)
|
|
91
|
+
+--> benchmark GCP · NGS pass rate · TSI · authorship fingerprint
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Related Work
|
|
95
|
+
|
|
96
|
+
| Work | Focus | RTSA counterpart |
|
|
97
|
+
|---|---|---|
|
|
98
|
+
| [LLM-MindMap](https://arxiv.org/abs/2505.13890) (EMNLP 2025) | Semantic step clustering; structural metrics predict performance | `rtsa/analysis/step_clustering.py` + `rtsa/analysis/performance_correlation.py` |
|
|
99
|
+
| [CRV](https://arxiv.org/abs/2510.09312) (Meta FAIR) | Verify reasoning steps from structural features (AUROC 70-92%); signatures are domain-dependent | `rtsa/analysis/step_classifier.py` + `PruneConfig.domain_overrides` |
|
|
100
|
+
| [CoT2Graph](https://openreview.net/forum?id=0XfuJjhaI5) | CoT-to-graph with reasoning-path validation and failure modes | `rtsa/core/ngs_validator.py` failure-mode taxonomy |
|
|
101
|
+
|
|
102
|
+
A capability-by-capability matrix is maintained in [docs/comparison.md](docs/comparison.md).
|
|
103
|
+
|
|
104
|
+
## Reproducible Experiments
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
python -m experiments.run extract --dataset gsm8k --max-traces 50
|
|
108
|
+
python -m experiments.run correlation --synthetic
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Every run lands in `rtsa/experiments/results/runs/<command>_<timestamp>/` with a `manifest.json` recording git commit, Python version, arguments, and UTC timestamp. See the [full CLI](docs/api.md#layer-5-experiments-experiments) for all subcommands.
|
|
112
|
+
|
|
113
|
+
## Results
|
|
114
|
+
|
|
115
|
+
Selected numbers from the built-in validation and real-data runs (reproducible via the commands above):
|
|
116
|
+
|
|
117
|
+
| Result | Value |
|
|
118
|
+
|---|---|
|
|
119
|
+
| Structural pruning, synthetic corpus | ~12.5% node compression, ~31 tokens/trace saved, 100% NGS pass rate |
|
|
120
|
+
| Structural pruning, GSM8K | self-limits to ~2% compression on naturally compact traces |
|
|
121
|
+
| Performance-correlation benchmark (synthetic validation, n=60) | 19 metrics, 12 significant after BH-FDR |
|
|
122
|
+
| Strongest effect (synthetic) | verify_density rho = -0.858, 95% CI [-0.881, -0.807] |
|
|
123
|
+
| Test suite | 322 tests passing (CI matrix: Python 3.10/3.11/3.12) |
|
|
124
|
+
|
|
125
|
+
## Documentation
|
|
126
|
+
|
|
127
|
+
- [docs/api.md](docs/api.md) — public API reference and module layout
|
|
128
|
+
- [docs/comparison.md](docs/comparison.md) — capability matrix vs. LLM-MindMap / CRV / CoT2Graph
|
|
129
|
+
- [docs/failure_modes.md](docs/failure_modes.md) — NGS failure-mode taxonomy
|
|
130
|
+
- [rtsa/experiments/notebooks/end_to_end.ipynb](rtsa/experiments/notebooks/end_to_end.ipynb) — end-to-end walkthrough
|
|
131
|
+
- [CHANGELOG.md](CHANGELOG.md) — version history (Keep a Changelog)
|
|
132
|
+
|
|
133
|
+
## Tests
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
python -m pytest tests/ -q
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Citation
|
|
140
|
+
|
|
141
|
+
```bibtex
|
|
142
|
+
@software{rtsa2026,
|
|
143
|
+
title={RTSA: Reasoning Trace Structure Analysis Toolkit},
|
|
144
|
+
author={Fengrru},
|
|
145
|
+
year={2026},
|
|
146
|
+
url={https://github.com/Fengrru/rtsa}
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## Contributing & License
|
|
151
|
+
|
|
152
|
+
- Contributing: [CONTRIBUTING.md](CONTRIBUTING.md)
|
|
153
|
+
- License: [MIT](LICENSE)
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "rtsa"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Reasoning Trace Structure Analysis Toolkit — extract, analyze, prune, fingerprint, and benchmark CoT reasoning graphs"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = {text = "MIT"}
|
|
11
|
+
authors = [{name = "Fengrru"}]
|
|
12
|
+
requires-python = ">=3.10"
|
|
13
|
+
keywords = [
|
|
14
|
+
"chain-of-thought",
|
|
15
|
+
"reasoning",
|
|
16
|
+
"llm",
|
|
17
|
+
"graph-analysis",
|
|
18
|
+
"pruning",
|
|
19
|
+
"redundancy-detection",
|
|
20
|
+
"structured-reasoning",
|
|
21
|
+
"cot-evaluation",
|
|
22
|
+
]
|
|
23
|
+
classifiers = [
|
|
24
|
+
"Development Status :: 4 - Beta",
|
|
25
|
+
"Intended Audience :: Science/Research",
|
|
26
|
+
"Intended Audience :: Developers",
|
|
27
|
+
"License :: OSI Approved :: MIT License",
|
|
28
|
+
"Programming Language :: Python :: 3.10",
|
|
29
|
+
"Programming Language :: Python :: 3.11",
|
|
30
|
+
"Programming Language :: Python :: 3.12",
|
|
31
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
32
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
33
|
+
"Operating System :: OS Independent",
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
dependencies = [
|
|
37
|
+
"numpy>=1.24.0",
|
|
38
|
+
"scipy>=1.11.0",
|
|
39
|
+
"networkx>=3.1",
|
|
40
|
+
"scikit-learn>=1.3.0",
|
|
41
|
+
"statsmodels>=0.14.0",
|
|
42
|
+
"pandas>=2.0.0",
|
|
43
|
+
"matplotlib>=3.7.0",
|
|
44
|
+
"seaborn>=0.12.0",
|
|
45
|
+
"spacy>=3.6.0",
|
|
46
|
+
"pyyaml>=6.0",
|
|
47
|
+
"tqdm>=4.65.0",
|
|
48
|
+
"pydantic>=2.0",
|
|
49
|
+
"orjson>=3.9.0",
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
[project.urls]
|
|
53
|
+
Homepage = "https://github.com/Fengrru/rtsa"
|
|
54
|
+
Repository = "https://github.com/Fengrru/rtsa"
|
|
55
|
+
Issues = "https://github.com/Fengrru/rtsa/issues"
|
|
56
|
+
Documentation = "https://github.com/Fengrru/rtsa#readme"
|
|
57
|
+
Changelog = "https://github.com/Fengrru/rtsa/blob/main/CHANGELOG.md"
|
|
58
|
+
|
|
59
|
+
[project.optional-dependencies]
|
|
60
|
+
dev = [
|
|
61
|
+
"pytest>=7.4.0",
|
|
62
|
+
"pytest-cov>=4.1.0",
|
|
63
|
+
"pytest-xdist>=3.3.0",
|
|
64
|
+
]
|
|
65
|
+
hf = [
|
|
66
|
+
"datasets>=2.14.0",
|
|
67
|
+
]
|
|
68
|
+
obs = [
|
|
69
|
+
"opentelemetry-api>=1.20.0",
|
|
70
|
+
"opentelemetry-sdk>=1.20.0",
|
|
71
|
+
"opentelemetry-exporter-otlp>=1.20.0",
|
|
72
|
+
"langfuse>=2.0.0",
|
|
73
|
+
]
|
|
74
|
+
notebook = [
|
|
75
|
+
"jupyter>=1.0.0",
|
|
76
|
+
"nbformat>=5.9.0",
|
|
77
|
+
]
|
|
78
|
+
llm = [
|
|
79
|
+
"openai>=1.0.0",
|
|
80
|
+
"anthropic>=0.20.0",
|
|
81
|
+
"transformers>=4.35.0",
|
|
82
|
+
"torch>=2.1.0",
|
|
83
|
+
]
|
|
84
|
+
all = [
|
|
85
|
+
"datasets>=2.14.0",
|
|
86
|
+
"opentelemetry-api>=1.20.0",
|
|
87
|
+
"opentelemetry-sdk>=1.20.0",
|
|
88
|
+
"opentelemetry-exporter-otlp>=1.20.0",
|
|
89
|
+
"langfuse>=2.0.0",
|
|
90
|
+
"jupyter>=1.0.0",
|
|
91
|
+
"nbformat>=5.9.0",
|
|
92
|
+
]
|
|
93
|
+
|
|
94
|
+
[tool.setuptools.packages.find]
|
|
95
|
+
where = ["."]
|
|
96
|
+
include = ["rtsa*"]
|
|
97
|
+
|
|
98
|
+
[project.scripts]
|
|
99
|
+
rtsa = "rtsa.__main__:main"
|
|
100
|
+
|
|
101
|
+
[project.gui-scripts]
|
|
102
|
+
|
|
103
|
+
[tool.pytest.ini_options]
|
|
104
|
+
testpaths = ["tests"]
|
|
105
|
+
python_files = ["test_*.py"]
|
|
106
|
+
addopts = ["-v", "--tb=short"]
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""
|
|
2
|
+
RTSA: Reasoning Trace Structure Analysis Toolkit.
|
|
3
|
+
|
|
4
|
+
Quick start:
|
|
5
|
+
from rtsa.extractors import create_extractor_deepseek
|
|
6
|
+
ext = create_extractor_deepseek()
|
|
7
|
+
graph = ext.extract("Calculate 5+3=8. Check the result.")
|
|
8
|
+
print(graph.nodes)
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
__version__ = "0.1.0"
|
|
12
|
+
|
|
13
|
+
# Convenience re-exports when running from the project directory
|
|
14
|
+
from rtsa.core.types import ReasoningTraceGraph, GraphNode, NodeType, MotifEntry
|
|
15
|
+
from rtsa.core.metrics import compute_graph_features, compute_tsi, compute_pairwise_tsi
|
|
16
|
+
from rtsa.core.motif_matcher import MotifMatcher
|
|
17
|
+
from rtsa.core.ngs_validator import NGSValidator
|
|
18
|
+
from rtsa.core.robust_tsi import UnsupervisedTSI
|
|
19
|
+
from rtsa.extractors import create_extractor_deepseek, RuleBasedExtractor, SyntaxBasedExtractor
|
|
20
|
+
|
|
21
|
+
__all__ = [
|
|
22
|
+
"ReasoningTraceGraph", "GraphNode", "NodeType", "MotifEntry",
|
|
23
|
+
"compute_graph_features", "compute_tsi", "compute_pairwise_tsi",
|
|
24
|
+
"MotifMatcher", "NGSValidator", "UnsupervisedTSI",
|
|
25
|
+
"create_extractor_deepseek", "RuleBasedExtractor", "SyntaxBasedExtractor",
|
|
26
|
+
]
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"""RTSA analysis layer — value-added modules built on core graph primitives.
|
|
2
|
+
|
|
3
|
+
Provides:
|
|
4
|
+
- prune : redundancy detection & CoT optimization
|
|
5
|
+
- fingerprint: LLM authorship attribution via graph structure
|
|
6
|
+
- benchmark : extractor reliability benchmarking (GCP + NGS + TSI)
|
|
7
|
+
"""
|
|
8
|
+
from rtsa.extractors.analysis import (
|
|
9
|
+
CostEstimator, CostBreakdown, estimate_project_cost,
|
|
10
|
+
kruskal_wallis_test, bootstrap_ci, cohens_d, partial_correlation,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
from .prune import (
|
|
14
|
+
PruneConfig,
|
|
15
|
+
RedundancyRegion,
|
|
16
|
+
PruningReport,
|
|
17
|
+
RedundancyAnalyzer,
|
|
18
|
+
prune_graph,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
from .fingerprint import (
|
|
22
|
+
ModelSignature,
|
|
23
|
+
FingerprintMatchResult,
|
|
24
|
+
ModelFingerprint,
|
|
25
|
+
enroll_model,
|
|
26
|
+
identify_author,
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
from .benchmark import (
|
|
30
|
+
ExtractorScore,
|
|
31
|
+
ExtractorBenchmarkResult,
|
|
32
|
+
BenchmarkReport,
|
|
33
|
+
ExtractorBenchmark,
|
|
34
|
+
benchmark_extractors,
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
__all__ = [
|
|
38
|
+
# Re-exports from rtsa.extractors.analysis (legacy)
|
|
39
|
+
"CostEstimator", "CostBreakdown", "estimate_project_cost",
|
|
40
|
+
"kruskal_wallis_test", "bootstrap_ci", "cohens_d", "partial_correlation",
|
|
41
|
+
# Prune module
|
|
42
|
+
"PruneConfig",
|
|
43
|
+
"RedundancyRegion",
|
|
44
|
+
"PruningReport",
|
|
45
|
+
"RedundancyAnalyzer",
|
|
46
|
+
"prune_graph",
|
|
47
|
+
# Fingerprint module
|
|
48
|
+
"ModelSignature",
|
|
49
|
+
"FingerprintMatchResult",
|
|
50
|
+
"ModelFingerprint",
|
|
51
|
+
"enroll_model",
|
|
52
|
+
"identify_author",
|
|
53
|
+
# Benchmark module
|
|
54
|
+
"ExtractorScore",
|
|
55
|
+
"ExtractorBenchmarkResult",
|
|
56
|
+
"BenchmarkReport",
|
|
57
|
+
"ExtractorBenchmark",
|
|
58
|
+
"benchmark_extractors",
|
|
59
|
+
]
|