dayan 0.2.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.
- dayan-0.2.0/.gitattributes +1 -0
- dayan-0.2.0/.github/workflows/ci.yml +41 -0
- dayan-0.2.0/.github/workflows/publish.yml +47 -0
- dayan-0.2.0/.gitignore +17 -0
- dayan-0.2.0/CITATION.cff +11 -0
- dayan-0.2.0/LICENSE +201 -0
- dayan-0.2.0/PKG-INFO +134 -0
- dayan-0.2.0/README.md +109 -0
- dayan-0.2.0/README_zh.md +54 -0
- dayan-0.2.0/benchmarks/game24_metrics.json +93 -0
- dayan-0.2.0/benchmarks/logical_da_rte.json +334 -0
- dayan-0.2.0/examples/quickstart_offline.py +49 -0
- dayan-0.2.0/pyproject.toml +56 -0
- dayan-0.2.0/src/dayan/__init__.py +77 -0
- dayan-0.2.0/src/dayan/augment/__init__.py +20 -0
- dayan-0.2.0/src/dayan/augment/data.py +423 -0
- dayan-0.2.0/src/dayan/augment/filtering.py +273 -0
- dayan-0.2.0/src/dayan/augment/pipeline.py +571 -0
- dayan-0.2.0/src/dayan/augment/prompts.py +275 -0
- dayan-0.2.0/src/dayan/augment/symbolic_backends.py +508 -0
- dayan-0.2.0/src/dayan/augment/verification.py +312 -0
- dayan-0.2.0/src/dayan/augment/workflow.py +112 -0
- dayan-0.2.0/src/dayan/cli.py +45 -0
- dayan-0.2.0/src/dayan/graph/__init__.py +23 -0
- dayan-0.2.0/src/dayan/graph/analysis.py +88 -0
- dayan-0.2.0/src/dayan/graph/functions.py +94 -0
- dayan-0.2.0/src/dayan/graph/graph.py +193 -0
- dayan-0.2.0/src/dayan/graph/instrument.py +619 -0
- dayan-0.2.0/src/dayan/graph/invoke.py +215 -0
- dayan-0.2.0/src/dayan/graph/trace.py +188 -0
- dayan-0.2.0/src/dayan/graph/utils.py +38 -0
- dayan-0.2.0/src/dayan/llm.py +202 -0
- dayan-0.2.0/src/dayan/metrics.py +328 -0
- dayan-0.2.0/src/dayan/mining.py +119 -0
- dayan-0.2.0/src/dayan/optimize.py +121 -0
- dayan-0.2.0/tests/test_augment.py +59 -0
- dayan-0.2.0/tests/test_game24_metrics.py +128 -0
- dayan-0.2.0/tests/test_graph.py +69 -0
- dayan-0.2.0/tests/test_k3_smoke.py +73 -0
- dayan-0.2.0/tests/test_logical_da.py +66 -0
- dayan-0.2.0/tests/test_metric_discrimination.py +76 -0
- dayan-0.2.0/tests/test_metrics_mining.py +138 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
* text=auto eol=lf
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
name: ci
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
test:
|
|
10
|
+
strategy:
|
|
11
|
+
matrix:
|
|
12
|
+
os: [ubuntu-latest, windows-latest, macos-latest]
|
|
13
|
+
python-version: ["3.10", "3.11", "3.12", "3.13"]
|
|
14
|
+
runs-on: ${{ matrix.os }}
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
|
+
|
|
18
|
+
- uses: actions/setup-python@v5
|
|
19
|
+
with:
|
|
20
|
+
python-version: ${{ matrix.python-version }}
|
|
21
|
+
|
|
22
|
+
- name: Install package (dependency-free core)
|
|
23
|
+
run: pip install -e .
|
|
24
|
+
|
|
25
|
+
- name: Compile check
|
|
26
|
+
run: python -m compileall -q src tests
|
|
27
|
+
|
|
28
|
+
- name: Offline tests (scripted LLM backends, no endpoint)
|
|
29
|
+
run: python -m unittest discover -s tests -v
|
|
30
|
+
|
|
31
|
+
lint:
|
|
32
|
+
runs-on: ubuntu-latest
|
|
33
|
+
steps:
|
|
34
|
+
- uses: actions/checkout@v4
|
|
35
|
+
- uses: actions/setup-python@v5
|
|
36
|
+
with:
|
|
37
|
+
python-version: "3.12"
|
|
38
|
+
- name: Ruff
|
|
39
|
+
run: |
|
|
40
|
+
pip install ruff
|
|
41
|
+
ruff check src tests
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
name: publish
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
build:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
steps:
|
|
11
|
+
- uses: actions/checkout@v4
|
|
12
|
+
- uses: actions/setup-python@v5
|
|
13
|
+
with:
|
|
14
|
+
python-version: "3.12"
|
|
15
|
+
- name: Build sdist and wheel
|
|
16
|
+
run: |
|
|
17
|
+
pip install build
|
|
18
|
+
python -m build
|
|
19
|
+
- name: Twine check
|
|
20
|
+
run: |
|
|
21
|
+
pip install twine
|
|
22
|
+
twine check dist/*
|
|
23
|
+
- name: Upload artifacts
|
|
24
|
+
uses: actions/upload-artifact@v4
|
|
25
|
+
with:
|
|
26
|
+
name: dayan-dist
|
|
27
|
+
path: dist/
|
|
28
|
+
|
|
29
|
+
pypi:
|
|
30
|
+
# PyPI Trusted Publishing (OIDC): no stored token. Configure once on
|
|
31
|
+
# pypi.org — Manage project → Publishing → add GitHub publisher with
|
|
32
|
+
# owner ruochunjin, repository dayan, workflow publish.yml,
|
|
33
|
+
# environment name "pypi".
|
|
34
|
+
needs: build
|
|
35
|
+
runs-on: ubuntu-latest
|
|
36
|
+
environment:
|
|
37
|
+
name: pypi
|
|
38
|
+
url: https://pypi.org/p/dayan
|
|
39
|
+
permissions:
|
|
40
|
+
id-token: write
|
|
41
|
+
steps:
|
|
42
|
+
- uses: actions/download-artifact@v4
|
|
43
|
+
with:
|
|
44
|
+
name: dayan-dist
|
|
45
|
+
path: dist/
|
|
46
|
+
- name: Publish to PyPI
|
|
47
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
dayan-0.2.0/.gitignore
ADDED
dayan-0.2.0/CITATION.cff
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
cff-version: 1.2.0
|
|
2
|
+
title: "DaYan (大衍): thought-graph modeling and process evaluation for LLM reasoning"
|
|
3
|
+
message: >-
|
|
4
|
+
If you use this software, please cite both the software and the
|
|
5
|
+
underlying research papers (Thought Mining; Logical DA).
|
|
6
|
+
type: software
|
|
7
|
+
# TODO: add author list and repository URL before public release.
|
|
8
|
+
authors: []
|
|
9
|
+
url: "https://github.com/ruochunjin/dayan"
|
|
10
|
+
version: 0.1.0
|
|
11
|
+
license: Apache-2.0
|
dayan-0.2.0/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any licenses granted to
|
|
86
|
+
You under this License for that Work shall terminate as of the date
|
|
87
|
+
such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your use of permissions.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
dayan-0.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: dayan
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: DaYan (大衍): thought-graph modeling, process-level evaluation, pattern mining and verified data augmentation for LLM reasoning
|
|
5
|
+
Project-URL: Homepage, https://github.com/ruochunjin/dayan
|
|
6
|
+
Project-URL: Issues, https://github.com/ruochunjin/dayan/issues
|
|
7
|
+
Author: DaYan Developers
|
|
8
|
+
License: Apache-2.0
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: LLM reasoning,RL process reward,data augmentation,process evaluation,thought graph
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Science/Research
|
|
13
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
16
|
+
Requires-Python: >=3.10
|
|
17
|
+
Provides-Extra: augment
|
|
18
|
+
Requires-Dist: z3-solver>=4.12; extra == 'augment'
|
|
19
|
+
Provides-Extra: dev
|
|
20
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
21
|
+
Requires-Dist: ruff>=0.6; extra == 'dev'
|
|
22
|
+
Provides-Extra: llm
|
|
23
|
+
Requires-Dist: openai>=1.30; extra == 'llm'
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
|
|
26
|
+
# DaYan 大衍
|
|
27
|
+
|
|
28
|
+
> *大衍之数五十,其用四十有九。* — The I Ching's Great Expansion generates
|
|
29
|
+
> structured hexagram states through a formal derivation procedure.
|
|
30
|
+
> **DaYan** does the same for LLM reasoning: it turns the reasoning *process*
|
|
31
|
+
> into structured data — a Thought Graph — and then analyzes it.
|
|
32
|
+
|
|
33
|
+
DaYan is a toolkit for **modeling, evaluating, and enhancing LLM reasoning as
|
|
34
|
+
data**. Where standard evaluation only checks final answers, DaYan answers
|
|
35
|
+
*how* the model reasoned — and feeds the findings back as improvements.
|
|
36
|
+
|
|
37
|
+
```text
|
|
38
|
+
reasoning program (your code calling an LLM)
|
|
39
|
+
→ @analysis instrumentation (sys.settrace, no source changes)
|
|
40
|
+
→ program trace → data-flow graph → Thought Graph
|
|
41
|
+
(nodes = LLM outputs "thoughts", edges = data dependencies)
|
|
42
|
+
→ process evaluation: 5 metrics beyond accuracy
|
|
43
|
+
→ pattern mining: frequent thinking patterns (successful vs. failed)
|
|
44
|
+
→ enhancement: prompt rules / verifiable RL process rewards
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
An auxiliary subpackage, `dayan.augment`, provides **symbolically verified
|
|
48
|
+
data augmentation** (Logical DA): LLM-generated samples whose labels are
|
|
49
|
+
checked by Z3 / Prover9 / rule / CSP solvers before they enter your training
|
|
50
|
+
set.
|
|
51
|
+
|
|
52
|
+
## Quickstart
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
from dayan import analysis, query, set_backend, AnalysisOutput
|
|
56
|
+
|
|
57
|
+
# Inject any LLM: (context, instruction, temperature) -> str
|
|
58
|
+
set_backend(my_llm_fn)
|
|
59
|
+
|
|
60
|
+
@analysis(output_type=AnalysisOutput.THOUGHT)
|
|
61
|
+
def solve(nums):
|
|
62
|
+
step = query("Add the numbers in {} and get [total]", nums) # LLM step
|
|
63
|
+
return int(step) * 2
|
|
64
|
+
|
|
65
|
+
result, thought_graph = solve([4, 4])
|
|
66
|
+
print(result) # program output
|
|
67
|
+
print(thought_graph.print_summary()) # nodes/edges of the reasoning process
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Evaluate a cohort of reasoning runs:
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
from dayan import ThoughtSample, mine_frequent_patterns, reasoning_efficiency, stepwise_consistency
|
|
74
|
+
|
|
75
|
+
patterns = mine_frequent_patterns([g1, g2, g3], length=3, min_support=2)
|
|
76
|
+
print(reasoning_efficiency(patterns)) # κ (branching) / λ (first layer)
|
|
77
|
+
print(stepwise_consistency(ThoughtSample(g1, success=True, step_matches={...})))
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Mine patterns from successful vs. failed runs and turn them into prompt
|
|
81
|
+
rules or RL process rewards:
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
from dayan import contrastive_patterns, patterns_to_prompt_rules, PatternProcessReward
|
|
85
|
+
|
|
86
|
+
good, bad = contrastive_patterns(success_graphs, failure_graphs)
|
|
87
|
+
rules = patterns_to_prompt_rules(good, bad) # inject into prompts
|
|
88
|
+
reward_fn = PatternProcessReward(good, bad) # per-step RL reward
|
|
89
|
+
reward = reward_fn(label_sequence_of_a_trajectory)
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Verified data augmentation
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
dayan augment --dataset records.json --output augmented.json --solver z3
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
The pipeline (attribute extraction → diversity filtering → label-flipped
|
|
99
|
+
generation → symbolic verification → reflection) runs on any OpenAI-compatible
|
|
100
|
+
endpoint; `DAYAN_API_KEY` / `DAYAN_BASE_URL` / `DAYAN_MODEL` configure it
|
|
101
|
+
(falling back to `OPENAI_*`). An Anthropic-messages endpoint (e.g. K3) works
|
|
102
|
+
via `DAYAN_BACKEND=anthropic`. Solvers: `z3`, `prover9`, `rules`, `csp`
|
|
103
|
+
(auto-detected), with an `llm` fallback.
|
|
104
|
+
|
|
105
|
+
## Measured end-to-end (K3 endpoint)
|
|
106
|
+
|
|
107
|
+
| Suite | Result |
|
|
108
|
+
| --- | --- |
|
|
109
|
+
| Instrumented reasoning smoke | program → 4-node Thought Graph, correct answer, metrics on the real trace |
|
|
110
|
+
| Game24 thought mining (6 puzzles, single-shot) | **0.83 accuracy**; multipath reliability gain +0.17; SCS 1.00 |
|
|
111
|
+
| Metric discrimination (synthetic) | branched κ=3.00 vs linear κ=1.00 — efficiency metric separates backtracking from chains |
|
|
112
|
+
| Logical DA on RTE-style samples | 4 inputs → 11 generated, **7/11 verified by Z3** (symbolic), 5 rejected |
|
|
113
|
+
|
|
114
|
+
## Installation
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
pip install -e . # core is dependency-free
|
|
118
|
+
pip install -e ".[llm]" # optional OpenAI SDK backend (stdlib works too)
|
|
119
|
+
pip install -e ".[augment]" # z3-solver for label verification
|
|
120
|
+
pip install -e ".[dev]" # tests + lint
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Research lineage
|
|
124
|
+
|
|
125
|
+
- **Thought Mining for Large Language Model Reasoning** — the Thought Graph
|
|
126
|
+
data model, the five process metrics, and both enhancement strategies.
|
|
127
|
+
- **Logical DA** (ACL 2025 Findings) — multi-agent data augmentation with
|
|
128
|
+
symbolic label verification.
|
|
129
|
+
|
|
130
|
+
If you use DaYan, please cite these works (see CITATION.cff).
|
|
131
|
+
|
|
132
|
+
## License
|
|
133
|
+
|
|
134
|
+
Apache-2.0 (see LICENSE).
|
dayan-0.2.0/README.md
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# DaYan 大衍
|
|
2
|
+
|
|
3
|
+
> *大衍之数五十,其用四十有九。* — The I Ching's Great Expansion generates
|
|
4
|
+
> structured hexagram states through a formal derivation procedure.
|
|
5
|
+
> **DaYan** does the same for LLM reasoning: it turns the reasoning *process*
|
|
6
|
+
> into structured data — a Thought Graph — and then analyzes it.
|
|
7
|
+
|
|
8
|
+
DaYan is a toolkit for **modeling, evaluating, and enhancing LLM reasoning as
|
|
9
|
+
data**. Where standard evaluation only checks final answers, DaYan answers
|
|
10
|
+
*how* the model reasoned — and feeds the findings back as improvements.
|
|
11
|
+
|
|
12
|
+
```text
|
|
13
|
+
reasoning program (your code calling an LLM)
|
|
14
|
+
→ @analysis instrumentation (sys.settrace, no source changes)
|
|
15
|
+
→ program trace → data-flow graph → Thought Graph
|
|
16
|
+
(nodes = LLM outputs "thoughts", edges = data dependencies)
|
|
17
|
+
→ process evaluation: 5 metrics beyond accuracy
|
|
18
|
+
→ pattern mining: frequent thinking patterns (successful vs. failed)
|
|
19
|
+
→ enhancement: prompt rules / verifiable RL process rewards
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
An auxiliary subpackage, `dayan.augment`, provides **symbolically verified
|
|
23
|
+
data augmentation** (Logical DA): LLM-generated samples whose labels are
|
|
24
|
+
checked by Z3 / Prover9 / rule / CSP solvers before they enter your training
|
|
25
|
+
set.
|
|
26
|
+
|
|
27
|
+
## Quickstart
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
from dayan import analysis, query, set_backend, AnalysisOutput
|
|
31
|
+
|
|
32
|
+
# Inject any LLM: (context, instruction, temperature) -> str
|
|
33
|
+
set_backend(my_llm_fn)
|
|
34
|
+
|
|
35
|
+
@analysis(output_type=AnalysisOutput.THOUGHT)
|
|
36
|
+
def solve(nums):
|
|
37
|
+
step = query("Add the numbers in {} and get [total]", nums) # LLM step
|
|
38
|
+
return int(step) * 2
|
|
39
|
+
|
|
40
|
+
result, thought_graph = solve([4, 4])
|
|
41
|
+
print(result) # program output
|
|
42
|
+
print(thought_graph.print_summary()) # nodes/edges of the reasoning process
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Evaluate a cohort of reasoning runs:
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
from dayan import ThoughtSample, mine_frequent_patterns, reasoning_efficiency, stepwise_consistency
|
|
49
|
+
|
|
50
|
+
patterns = mine_frequent_patterns([g1, g2, g3], length=3, min_support=2)
|
|
51
|
+
print(reasoning_efficiency(patterns)) # κ (branching) / λ (first layer)
|
|
52
|
+
print(stepwise_consistency(ThoughtSample(g1, success=True, step_matches={...})))
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Mine patterns from successful vs. failed runs and turn them into prompt
|
|
56
|
+
rules or RL process rewards:
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
from dayan import contrastive_patterns, patterns_to_prompt_rules, PatternProcessReward
|
|
60
|
+
|
|
61
|
+
good, bad = contrastive_patterns(success_graphs, failure_graphs)
|
|
62
|
+
rules = patterns_to_prompt_rules(good, bad) # inject into prompts
|
|
63
|
+
reward_fn = PatternProcessReward(good, bad) # per-step RL reward
|
|
64
|
+
reward = reward_fn(label_sequence_of_a_trajectory)
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Verified data augmentation
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
dayan augment --dataset records.json --output augmented.json --solver z3
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
The pipeline (attribute extraction → diversity filtering → label-flipped
|
|
74
|
+
generation → symbolic verification → reflection) runs on any OpenAI-compatible
|
|
75
|
+
endpoint; `DAYAN_API_KEY` / `DAYAN_BASE_URL` / `DAYAN_MODEL` configure it
|
|
76
|
+
(falling back to `OPENAI_*`). An Anthropic-messages endpoint (e.g. K3) works
|
|
77
|
+
via `DAYAN_BACKEND=anthropic`. Solvers: `z3`, `prover9`, `rules`, `csp`
|
|
78
|
+
(auto-detected), with an `llm` fallback.
|
|
79
|
+
|
|
80
|
+
## Measured end-to-end (K3 endpoint)
|
|
81
|
+
|
|
82
|
+
| Suite | Result |
|
|
83
|
+
| --- | --- |
|
|
84
|
+
| Instrumented reasoning smoke | program → 4-node Thought Graph, correct answer, metrics on the real trace |
|
|
85
|
+
| Game24 thought mining (6 puzzles, single-shot) | **0.83 accuracy**; multipath reliability gain +0.17; SCS 1.00 |
|
|
86
|
+
| Metric discrimination (synthetic) | branched κ=3.00 vs linear κ=1.00 — efficiency metric separates backtracking from chains |
|
|
87
|
+
| Logical DA on RTE-style samples | 4 inputs → 11 generated, **7/11 verified by Z3** (symbolic), 5 rejected |
|
|
88
|
+
|
|
89
|
+
## Installation
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
pip install -e . # core is dependency-free
|
|
93
|
+
pip install -e ".[llm]" # optional OpenAI SDK backend (stdlib works too)
|
|
94
|
+
pip install -e ".[augment]" # z3-solver for label verification
|
|
95
|
+
pip install -e ".[dev]" # tests + lint
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Research lineage
|
|
99
|
+
|
|
100
|
+
- **Thought Mining for Large Language Model Reasoning** — the Thought Graph
|
|
101
|
+
data model, the five process metrics, and both enhancement strategies.
|
|
102
|
+
- **Logical DA** (ACL 2025 Findings) — multi-agent data augmentation with
|
|
103
|
+
symbolic label verification.
|
|
104
|
+
|
|
105
|
+
If you use DaYan, please cite these works (see CITATION.cff).
|
|
106
|
+
|
|
107
|
+
## License
|
|
108
|
+
|
|
109
|
+
Apache-2.0 (see LICENSE).
|
dayan-0.2.0/README_zh.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# DaYan 大衍
|
|
2
|
+
|
|
3
|
+
> 《易经》"大衍之数五十,其用四十有九"——以形式化推演程序生成结构化的卦象状态。**大衍**对大模型推理做同样的事:把推理*过程*变成结构化数据(Thought Graph),再加以分析。
|
|
4
|
+
|
|
5
|
+
[English README](README.md)
|
|
6
|
+
|
|
7
|
+
大衍是一个**"思维数据"的建模、评估与增强工具包**。传统评测只看最终答案对不对,大衍回答"模型是怎么推理的",并把发现回流为改进。
|
|
8
|
+
|
|
9
|
+
```text
|
|
10
|
+
推理程序(您的代码调用 LLM)
|
|
11
|
+
→ @analysis 插桩(sys.settrace,不改源代码)
|
|
12
|
+
→ 程序 trace → 数据流图 → Thought Graph(节点=LLM 输出的"思维",边=数据依赖)
|
|
13
|
+
→ 过程评估:五个超越准确率的指标
|
|
14
|
+
→ 模式挖掘:频繁思维模式(成功 vs 失败对比挖掘)
|
|
15
|
+
→ 增强:prompt 规则注入 / 可验证的 RL 过程奖励
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
辅助子包 `dayan.augment` 提供**符号验证的数据增广**(Logical DA):LLM 生成的样本,标签先经 Z3 / Prover9 / 规则 / CSP 求解器校验才进入训练集。
|
|
19
|
+
|
|
20
|
+
## 快速开始
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
from dayan import analysis, query, set_backend, AnalysisOutput
|
|
24
|
+
|
|
25
|
+
set_backend(my_llm_fn) # 注入任意 LLM:(context, instruction, temperature) -> str
|
|
26
|
+
|
|
27
|
+
@analysis(output_type=AnalysisOutput.THOUGHT)
|
|
28
|
+
def solve(nums):
|
|
29
|
+
step = query("Add the numbers in {} and get [total]", nums) # LLM 步骤
|
|
30
|
+
return int(step) * 2
|
|
31
|
+
|
|
32
|
+
result, thought_graph = solve([4, 4])
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## 五个过程评估指标
|
|
36
|
+
|
|
37
|
+
推理效率(频繁模式的分支因子 κ / 首现层 λ)· 关键节点判断(节点影响力相关性 NIS)· 推理共性(路径分布 KL 散度)· 多路径可靠性(路径聚合增益)· 逐步一致性(深度加权 SCS)。
|
|
38
|
+
|
|
39
|
+
## 可信数据增广
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
dayan augment --dataset records.json --output augmented.json --solver z3
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
端点配置:`DAYAN_API_KEY` / `DAYAN_BASE_URL` / `DAYAN_MODEL`(兼容 `OPENAI_*`)。
|
|
46
|
+
|
|
47
|
+
## 学术脉络
|
|
48
|
+
|
|
49
|
+
- *Thought Mining for Large Language Model Reasoning*——Thought Graph 数据模型、五个过程指标、两种增强策略
|
|
50
|
+
- *Logical DA*(ACL 2025 Findings)——多智能体数据增广与符号标签验证
|
|
51
|
+
|
|
52
|
+
## 许可
|
|
53
|
+
|
|
54
|
+
Apache-2.0(见 LICENSE)。
|