infx 1.0.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.
- infx-1.0.0/CHANGELOG.md +51 -0
- infx-1.0.0/LICENSE +21 -0
- infx-1.0.0/MANIFEST.in +10 -0
- infx-1.0.0/MERGE-RULES.md +72 -0
- infx-1.0.0/PKG-INFO +342 -0
- infx-1.0.0/README.md +307 -0
- infx-1.0.0/RELEASE.md +112 -0
- infx-1.0.0/infx/__init__.py +207 -0
- infx-1.0.0/infx/__main__.py +5 -0
- infx-1.0.0/infx/batch.py +82 -0
- infx-1.0.0/infx/cli.py +86 -0
- infx-1.0.0/infx/colony.py +479 -0
- infx-1.0.0/infx/core/__init__.py +35 -0
- infx-1.0.0/infx/core/errors.py +23 -0
- infx-1.0.0/infx/core/pipeline.py +65 -0
- infx-1.0.0/infx/core/registry.py +58 -0
- infx-1.0.0/infx/core/schema.py +175 -0
- infx-1.0.0/infx/core/scoring.py +89 -0
- infx-1.0.0/infx/core/text.py +98 -0
- infx-1.0.0/infx/death.py +147 -0
- infx-1.0.0/infx/deps.py +106 -0
- infx-1.0.0/infx/grammar/__init__.py +67 -0
- infx-1.0.0/infx/grammar/engine.py +178 -0
- infx-1.0.0/infx/grammar/judge.py +53 -0
- infx-1.0.0/infx/grammar/lexicon.py +187 -0
- infx-1.0.0/infx/grammar/rules.py +140 -0
- infx-1.0.0/infx/grammar/schema.py +84 -0
- infx-1.0.0/infx/judgment/__init__.py +15 -0
- infx-1.0.0/infx/judgment/base.py +51 -0
- infx-1.0.0/infx/judgment/fact/__init__.py +5 -0
- infx-1.0.0/infx/judgment/fact/detectors.py +182 -0
- infx-1.0.0/infx/judgment/opinion/__init__.py +9 -0
- infx-1.0.0/infx/judgment/opinion/cues.py +149 -0
- infx-1.0.0/infx/knowledge.py +149 -0
- infx-1.0.0/infx/look/__init__.py +72 -0
- infx-1.0.0/infx/look/__main__.py +5 -0
- infx-1.0.0/infx/look/backend.py +68 -0
- infx-1.0.0/infx/look/cli.py +110 -0
- infx-1.0.0/infx/look/evidence.py +76 -0
- infx-1.0.0/infx/look/eye.py +216 -0
- infx-1.0.0/infx/look/lmm.py +83 -0
- infx-1.0.0/infx/look/sight.py +168 -0
- infx-1.0.0/infx/look/table.py +84 -0
- infx-1.0.0/infx/patterns.py +287 -0
- infx-1.0.0/infx/py.typed +1 -0
- infx-1.0.0/infx/quality.py +181 -0
- infx-1.0.0/infx/report.py +108 -0
- infx-1.0.0/infx/settle.py +114 -0
- infx-1.0.0/infx/similarity.py +99 -0
- infx-1.0.0/infx/spoken/__init__.py +12 -0
- infx-1.0.0/infx/spoken/phrases.py +95 -0
- infx-1.0.0/infx/spoken/render.py +121 -0
- infx-1.0.0/infx/steps.py +268 -0
- infx-1.0.0/infx/syntax/__init__.py +33 -0
- infx-1.0.0/infx/syntax/clauses.py +70 -0
- infx-1.0.0/infx/syntax/features.py +122 -0
- infx-1.0.0/infx/syntax/scope.py +66 -0
- infx-1.0.0/infx/table.py +116 -0
- infx-1.0.0/infx/truth.py +303 -0
- infx-1.0.0/infx.egg-info/PKG-INFO +342 -0
- infx-1.0.0/infx.egg-info/SOURCES.txt +82 -0
- infx-1.0.0/infx.egg-info/dependency_links.txt +1 -0
- infx-1.0.0/infx.egg-info/entry_points.txt +3 -0
- infx-1.0.0/infx.egg-info/requires.txt +18 -0
- infx-1.0.0/infx.egg-info/top_level.txt +1 -0
- infx-1.0.0/pyproject.toml +64 -0
- infx-1.0.0/requirements-dev.txt +9 -0
- infx-1.0.0/requirements.txt +4 -0
- infx-1.0.0/setup.cfg +4 -0
- infx-1.0.0/tests/__init__.py +6 -0
- infx-1.0.0/tests/test_api.py +114 -0
- infx-1.0.0/tests/test_architecture.py +231 -0
- infx-1.0.0/tests/test_core.py +148 -0
- infx-1.0.0/tests/test_extras.py +120 -0
- infx-1.0.0/tests/test_grammar.py +116 -0
- infx-1.0.0/tests/test_io_vision.py +136 -0
- infx-1.0.0/tests/test_judgment.py +153 -0
- infx-1.0.0/tests/test_logic.py +212 -0
- infx-1.0.0/tests/test_look.py +152 -0
- infx-1.0.0/tests/test_look_table.py +115 -0
- infx-1.0.0/tests/test_mechanism.py +206 -0
- infx-1.0.0/tests/test_quality.py +100 -0
- infx-1.0.0/tests/test_syntax.py +109 -0
- infx-1.0.0/tests/test_vectorized.py +184 -0
infx-1.0.0/CHANGELOG.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# 变更记录
|
|
2
|
+
|
|
3
|
+
格式参考 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/),版本号遵循语义化版本。
|
|
4
|
+
|
|
5
|
+
## [1.0.0] — 2026-11-19
|
|
6
|
+
|
|
7
|
+
**发行名**:PyPI 包名 `infx`(`inference` 已被 Roboflow 的计算机视觉项目占用)。
|
|
8
|
+
项目/仓库名仍为 `inference`,import 名仍为 `infx`。
|
|
9
|
+
|
|
10
|
+
**1.0 的含义**:公开 API(`infx.__all__` 里的名字)在 1.x 内不破坏;破坏性变更只会在 2.0 出现,
|
|
11
|
+
且必须在此文件写明迁移方式。内部模块(下划线开头)不受此承诺约束。
|
|
12
|
+
|
|
13
|
+
### 新增
|
|
14
|
+
- `infx.grammar`:494 条语法规则库(中文 322 / 英文 172,18 个细类),每条带 id 与权重,
|
|
15
|
+
命中可追溯到具体规则;`audit()` 做死规则审计,`benchmark()` 测性能
|
|
16
|
+
- `infx.syntax`:从句切分、嵌套深度、**否定作用域**、句法画像(条件/问句/引用/转述/比较/因果/模糊限制)
|
|
17
|
+
- `infx.quality`:49 条回归集 + 10 条对抗集,计算准确率 / 精确率 / 召回率 / F1 / 混淆矩阵
|
|
18
|
+
- `infx.batch`:列表与 JSONL 批处理
|
|
19
|
+
- `infx.similarity`:bigram Jaccard、词频余弦、去重、最近邻
|
|
20
|
+
- `infx.report`:Markdown / 纯文本报告(不做 UI)
|
|
21
|
+
- `infx.look`:看图模块(LMM 接口 + GRU 眼睛 + 显著度选点 + pandas 表格)
|
|
22
|
+
- `infx.deps`:依赖自检(必需 / 可选 / look 依赖栈)
|
|
23
|
+
|
|
24
|
+
### 改进
|
|
25
|
+
- 事实判定器补:转述他人说法、传闻(弱权重)、宣告类谓语(否认/证实/确认/宣布/承认/声称/透露)
|
|
26
|
+
- 观点判定器补:常用评价词(很好/很棒/好用/难用/复杂/简单/困难/容易/不好)与第一人称立场(我支持/我赞成/我反对)
|
|
27
|
+
- 语法引擎按语言过滤:纯英文文本不跑中文规则,反之亦然;实测 **0.20 ms/句**
|
|
28
|
+
- 项目补 `LICENSE`、`CHANGELOG.md`、`MERGE-RULES.md`、`requirements*.txt`
|
|
29
|
+
|
|
30
|
+
### 质量数字(诚实版)
|
|
31
|
+
- 回归集(49 条手写):准确率 100%、宏 F1 1.000 —— **但这套样本是照着规则写的,不构成盲测**
|
|
32
|
+
- 对抗集(10 条,照已知弱点写):准确率 90%(起始为 20%)
|
|
33
|
+
- 死规则:59 句语料只激活 50/494 条(10.1%)——词形库的正常现象,不是缺陷
|
|
34
|
+
|
|
35
|
+
### 已知限制
|
|
36
|
+
- 反讽、双重否定、复杂条件句仍会错
|
|
37
|
+
- LMM 只有接口,`load_lmm()` 显式报错,不假装有模型
|
|
38
|
+
- 不内置联网;交叉验证要调用方注入外部来源
|
|
39
|
+
|
|
40
|
+
## [0.2.0] — 2026-11-19
|
|
41
|
+
|
|
42
|
+
### 变更
|
|
43
|
+
- 包名定为 `infx`(发行名 `inference`),`look` 从独立项目并入为 `infx.look` 子模块
|
|
44
|
+
- 分层规则落地(`MERGE-RULES.md`),架构由 `tests/test_architecture.py` 自动检查
|
|
45
|
+
- 依赖三处一致:`pyproject.toml` / `requirements.txt` / `infx/deps.py`
|
|
46
|
+
|
|
47
|
+
## [0.1.0] — 2026-11-19
|
|
48
|
+
|
|
49
|
+
### 新增
|
|
50
|
+
- 文本事实/观点判定(规则式)、中英双语、逐句汇总
|
|
51
|
+
- `Colony` 死亡机制、`patterns` 图案池、`steps` 步骤序列、`truth` 交叉验证、`settle` 三求、`table` pandas 结果
|
infx-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 My AI Knowledge Library
|
|
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.
|
infx-1.0.0/MANIFEST.in
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# 融合规则:`look` + `inference` → 一个库
|
|
2
|
+
|
|
3
|
+
> 这份文件是**规则**,不是说明。规则里带「✅ 强制」的条目由 `tests/test_architecture.py` 自动检查;
|
|
4
|
+
> 违反任何一条,测试直接失败。
|
|
5
|
+
|
|
6
|
+
## 1. 一个发行物,两个独立用点
|
|
7
|
+
|
|
8
|
+
| 用点 | 怎么用 | 依赖 | 不需要 |
|
|
9
|
+
|---|---|---|---|
|
|
10
|
+
| **推理力** | `import infx` · `python -m infx "文本"` · `infx` 命令 | numpy, pandas | torch、图像库 |
|
|
11
|
+
| **看图片** | `import infx.look` · `python -m infx.look --demo` · `infx-look` 命令 | **numpy, math, pandas, torch** | 推理层(colony/steps/truth/settle) |
|
|
12
|
+
|
|
13
|
+
**规则 1.1(✅ 强制)** 两个用点都能独立工作:`infx.look` 不得依赖推理层的任何模块。
|
|
14
|
+
**规则 1.2(✅ 强制)** 两个用点各有一个控制台入口:`infx` 与 `infx-look`,都在 `pyproject.toml` 的 `[project.scripts]` 里声明。
|
|
15
|
+
|
|
16
|
+
## 2. 分层与依赖方向
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
L0 基础 core/(schema, text, scoring, registry, errors) judgment/ grammar/ patterns death knowledge deps
|
|
20
|
+
L1 推理 colony steps truth settle syntax similarity
|
|
21
|
+
L2 集成 table spoken look/ batch report cli (可在 L0+L1 之上组装)
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
**规则 2.1(✅ 强制)** 依赖只能**向下**。L0 不得 import L1/L2;L1 不得 import L2。
|
|
25
|
+
**规则 2.2(✅ 强制)** `look/` 属于 L2,但**只允许**依赖 L0(`core.*`)与自己内部模块,不得依赖 L1(`colony/steps/truth/settle`)。
|
|
26
|
+
**规则 2.3** `look/lmm.py` 与 `look/eye.py` 是纯计算,不得 import `infx` 顶层(避免循环依赖)。
|
|
27
|
+
|
|
28
|
+
## 3. 命名规则
|
|
29
|
+
|
|
30
|
+
**规则 3.1(✅ 强制)** 子包全小写(`core/judgment/look/spoken`),模块全小写,类 PascalCase,函数 snake_case。
|
|
31
|
+
**规则 3.2** 顶层的 `infx` 只导出**稳定 API**;下划线开头的辅助函数不上浮。
|
|
32
|
+
**规则 3.3(✅ 强制)** 语义撞名必须加前缀区分:
|
|
33
|
+
|
|
34
|
+
| 名字 | 指什么 | 不指什么 |
|
|
35
|
+
|---|---|---|
|
|
36
|
+
| `Label` / `Verdict` | **文本**事实/观点判定结果 | 真伪交叉验证 |
|
|
37
|
+
| `TruthLabel` / `TruthVerdict` | **真伪**交叉验证结果 | 文本判定 |
|
|
38
|
+
| `judge_claim` | 对一个 Claim 做文本判定 | 真伪裁决 |
|
|
39
|
+
| `cross_validate` | 多源交叉验证 | 单句判定 |
|
|
40
|
+
|
|
41
|
+
## 4. 依赖声明必须三处一致
|
|
42
|
+
|
|
43
|
+
**规则 4.1(✅ 强制)** 以下三处的必需依赖集合必须相同:
|
|
44
|
+
|
|
45
|
+
1. `pyproject.toml` → `[project.dependencies]`
|
|
46
|
+
2. `requirements.txt`
|
|
47
|
+
3. `infx/deps.py` → `REQUIRED`
|
|
48
|
+
|
|
49
|
+
可选依赖(torch)同理对应:`[project.optional-dependencies].vision` / `requirements-dev.txt` / `deps.OPTIONAL`。
|
|
50
|
+
|
|
51
|
+
**规则 4.2** 新增依赖先在这里登记(为什么会缺、缺了降级成什么),再改上面三处。
|
|
52
|
+
|
|
53
|
+
**规则 4.3(✅ 强制)** `look` 的依赖栈固定为 **numpy / math / pandas / torch**:
|
|
54
|
+
|
|
55
|
+
- `math` 是标准库,不写进依赖声明,但**必须**在 `deps.LOOK_STDLIB` 里登记;
|
|
56
|
+
- `[project.optional-dependencies].look`、`deps.LOOK_STACK` 的第三方集合必须一致;
|
|
57
|
+
- `look/` 下任何模块**不得**引入这四者之外的第三方库(由 AST 检查)。
|
|
58
|
+
|
|
59
|
+
## 5. 融合边界(哪些不合并)
|
|
60
|
+
|
|
61
|
+
**规则 5.1** `look` 的"看懂"(LMM)只有接口 + 离线降级,**不假装**有模型;`load_lmm()` 必须显式报错。
|
|
62
|
+
**规则 5.2** 视觉证据进入文本判定时权重 ≤ `0.3`(`MAX_VISUAL_WEIGHT`),且只能加强 fact 侧,不得把 opinion 翻成 fact。
|
|
63
|
+
**规则 5.3** 原独立 `look/` 项目已归档,**不保留 import shim**;旧路径直接失效,避免两套 API 并存。
|
|
64
|
+
**规则 5.4** 语法规则库(`grammar/`)是**数据资产**:`lexicon.py` 存词表,`rules.py` 展开成规则。
|
|
65
|
+
加词只改词表,不改判定逻辑;规则条数由 `grammar.stats()` 暴露,测试断言 ≥300 条。
|
|
66
|
+
**规则 5.5** 语法判定器(`GrammarJudge`)**默认不启用**——默认流水线的行为已被测试固定,
|
|
67
|
+
要启用请显式传 `judges=grammar.judges_with_grammar()` 或用 CLI 的 `--grammar`。
|
|
68
|
+
|
|
69
|
+
## 6. 测试与文档同步
|
|
70
|
+
|
|
71
|
+
**规则 6.1** 新增一个用点 → 加一条 CLI 冒烟测试 + 在 README「两个独立用点」表里加一行。
|
|
72
|
+
**规则 6.2** 改分层 → 先改这份文件,再改代码,再跑 `test_architecture`。
|
infx-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: infx
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: infx:会猜、会死、会留下记忆的推理力模块;内含 look 子模块(看图并指出下一个点)
|
|
5
|
+
Author: My AI Knowledge Library
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Keywords: reasoning,evolutionary,death,vision,rnn,lmm,patterns,numpy,pandas
|
|
8
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
15
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
16
|
+
Classifier: Typing :: Typed
|
|
17
|
+
Requires-Python: >=3.11
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Requires-Dist: numpy>=1.24
|
|
21
|
+
Requires-Dist: pandas>=2.0
|
|
22
|
+
Provides-Extra: look
|
|
23
|
+
Requires-Dist: numpy>=1.24; extra == "look"
|
|
24
|
+
Requires-Dist: pandas>=2.0; extra == "look"
|
|
25
|
+
Requires-Dist: torch>=2.0; extra == "look"
|
|
26
|
+
Provides-Extra: vision
|
|
27
|
+
Requires-Dist: torch>=2.0; extra == "vision"
|
|
28
|
+
Provides-Extra: dev
|
|
29
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
30
|
+
Provides-Extra: all
|
|
31
|
+
Requires-Dist: numpy>=1.24; extra == "all"
|
|
32
|
+
Requires-Dist: pandas>=2.0; extra == "all"
|
|
33
|
+
Requires-Dist: torch>=2.0; extra == "all"
|
|
34
|
+
Dynamic: license-file
|
|
35
|
+
|
|
36
|
+
# infx
|
|
37
|
+
|
|
38
|
+
> 会猜、会死、会留下记忆的推理力模块;内含 `look` 子模块,专门用来看图片。
|
|
39
|
+
> **PyPI 包名 `infx` · import 名 `infx`**(项目仓库名是 `inference`;PyPI 上 `inference` 已被 Roboflow 的计算机视觉项目占用,与本库无关)
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install infx # 最小:numpy + pandas
|
|
43
|
+
pip install "infx[look]" # 加 torch:RNN 眼睛 + torch 后端
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
import infx
|
|
48
|
+
|
|
49
|
+
colony = infx.Colony(8, 2, size=48)
|
|
50
|
+
report = colony.solve(X, y, max_rounds=60) # 一轮一轮猜,猜错就死,原地复活
|
|
51
|
+
|
|
52
|
+
infx.look.next_point(image) # 下一个该看的点在哪
|
|
53
|
+
infx.look.Eye().look(image) # RNN 眼睛:会动、会预测、会怕
|
|
54
|
+
infx.Store().add(report).frame # pandas 表格
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
> 开发/贡献:见仓库里的 `RELEASE.md`(发布流程)与 `MERGE-RULES.md`(分层与依赖规则)。
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
import infx
|
|
61
|
+
|
|
62
|
+
colony = infx.Colony(8, 2, size=48)
|
|
63
|
+
report = colony.solve(X, y, max_rounds=60) # 一轮一轮猜,猜错就死,原地复活
|
|
64
|
+
|
|
65
|
+
infx.look.next_point(image) # 下一个该看的点在哪
|
|
66
|
+
infx.look.Eye().look(image) # RNN 眼睛:会动、会预测、会怕
|
|
67
|
+
infx.Store().add(report).frame # pandas 表格
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## 两个部分
|
|
73
|
+
|
|
74
|
+
| 部分 | 模块 | 干什么 |
|
|
75
|
+
|---|---|---|
|
|
76
|
+
| **推理力** | `colony` `death` `patterns` `steps` `truth` `settle` `knowledge` `table` | 猜、死、复活、学步骤、判真伪、沉淀、出表 |
|
|
77
|
+
| **看图片** | `infx.look`(`eye` `lmm` `sight` `evidence`) | LMM 看懂、RNN 让眼睛会动会怕、指出下一个该看的点 |
|
|
78
|
+
| **文本判定** | `core` `judgment` `spoken` | 判事实/观点、按置信度表述(早先那层,保留) |
|
|
79
|
+
|
|
80
|
+
## 两个独立用点(同一个库)
|
|
81
|
+
|
|
82
|
+
`look` 不是独立项目,是**这个库里的一个小模块**;但它有自己的使用入口,能单独用。
|
|
83
|
+
|
|
84
|
+
| 用点 | 导入 | 命令 | 只需要 |
|
|
85
|
+
|---|---|---|---|
|
|
86
|
+
| **推理力** | `import infx` | `python -m infx "文本"` 或 `infx` | numpy, pandas |
|
|
87
|
+
| **看图片** | `import infx.look` | `python -m infx.look --demo` 或 `infx-look` | numpy, math, pandas, torch |
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
python -m infx "据新华社报道,会议于 2024 年 3 月举行。"
|
|
91
|
+
python -m infx.look --demo --saliency --eye
|
|
92
|
+
python -m infx.look --npy gray32.npy --steps 3 --json
|
|
93
|
+
python -m infx.look --demo --csv points.csv # 注视点表(pandas)
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
原独立的 `work/python/look/` 已整体并入 `infx.look/` 并归档,**没有保留 import shim**(避免两套 API 并存)。
|
|
97
|
+
|
|
98
|
+
## 融合规则(有规则的融合)
|
|
99
|
+
|
|
100
|
+
完整规则在 [MERGE-RULES.md](MERGE-RULES.md)。其中 9 条标「✅ 强制」的由 [tests/test_architecture.py](tests/test_architecture.py) 自动检查——规则不落成测试就只是文字。
|
|
101
|
+
|
|
102
|
+
```
|
|
103
|
+
L0 基础 core judgment patterns death knowledge deps
|
|
104
|
+
L1 推理 colony steps truth settle
|
|
105
|
+
L2 集成 table spoken look cli ← 依赖只能向下
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
- **依赖只能向下**:L0 不得 import L1/L2
|
|
109
|
+
- **`look` 只允许依赖 L0 与自己**,不许碰推理层
|
|
110
|
+
- **`look` 的依赖栈固定为 numpy / math / pandas / torch 四件套**(`math` 是标准库,登记在 `deps.LOOK_STDLIB`)
|
|
111
|
+
- **两个用点各有控制台入口**,都在 `pyproject.toml` 声明
|
|
112
|
+
- **依赖三处必须一致**:`pyproject.toml` ↔ `requirements.txt` ↔ `infx/deps.py`
|
|
113
|
+
- **语义撞名必须分家**:`Label`/`Verdict`(文本判定)vs `TruthLabel`/`TruthVerdict`(真伪交叉验证)
|
|
114
|
+
|
|
115
|
+
## 依赖(装法有三种,声明三处一致)
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
python -m pip install -e . # 最小:numpy + pandas
|
|
119
|
+
python -m pip install -e '.[look]' # look 的完整栈:numpy + math(内置) + pandas + torch
|
|
120
|
+
python -m pip install -e '.[vision]' # 只要 GRU 眼睛的后端
|
|
121
|
+
python -m pip install -e '.[all]' # 一次装齐
|
|
122
|
+
python -m pip install -r requirements-dev.txt # 不装包、直接跑代码时用
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
运行时自检:`python -c "import infx; print(infx.deps.report())"`
|
|
126
|
+
|
|
127
|
+
```
|
|
128
|
+
依赖状态:
|
|
129
|
+
✔ numpy 2.5.4 数组与张量运算(推理核心、视觉显著性)
|
|
130
|
+
✔ pandas 3.1.1 结果管理、查询与导出(Store)
|
|
131
|
+
✔ torch 2.15.0+cpu GRU 眼睛与 torch 后端(缺失则用贪心扫视 / numpy 后端)
|
|
132
|
+
✔ 必需依赖齐全
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## 计划 → 机制对照表
|
|
136
|
+
|
|
137
|
+
| 你写的 | 代码里是什么 | 位置 |
|
|
138
|
+
|---|---|---|
|
|
139
|
+
| 库叫 inference,import 名 infx | `[project] name="inference"`,包目录 `infx/` | `pyproject.toml` |
|
|
140
|
+
| look 是 infx 里的单独模块,专门看图 | 子包 `infx.look` | `infx/look/` |
|
|
141
|
+
| look 用 RNN 和 LMM | `eye.py`(GRU 扫视)+ `lmm.py`(接口,真模型缺失时明确报错) | `infx/look/` |
|
|
142
|
+
| 加 pandas 做结果管理/查询/导出 | `Store` + `rounds_frame/neurons_frame/verdicts_frame` | `table.py` |
|
|
143
|
+
| 类似 Transformer 但不是,学技术不走老路 | 无注意力、无梯度、无反向传播;学习 = 选择 + 死亡 + 复活 | `colony.py` |
|
|
144
|
+
| 混合旧识 | 死亡时留指纹,复活时混入 | `death.py::make_residue` |
|
|
145
|
+
| 一轮一轮地猜,猜到最准 | `Colony.solve()` 循环 | `colony.py` |
|
|
146
|
+
| 猜不到就死,死亡是核心机制 | `LifeState.strike()` 到线即死,**主流程不是异常** | `death.py` |
|
|
147
|
+
| 神经元自动死亡,猜错就淘汰 | 每个单元独立一条命 | `colony.py::step` |
|
|
148
|
+
| 用轮数当死亡线 | `DeathPolicy.max_strikes` | `death.py` |
|
|
149
|
+
| 死亡留一点记忆 | `Tombstone.residue`(默认 25%) | `death.py` |
|
|
150
|
+
| 位置永不动,死的是内容,复活回原位 | `slot` 索引不变,只清 `pattern`;`revive(slot)` 原地复活 | `colony.py` |
|
|
151
|
+
| 感知余命、预判下一步会不会死 | `LifeState.remaining / ratio / would_die_if_wrong()` | `death.py` |
|
|
152
|
+
| 猜中后:再求值 / 再追求 / 再求知 | `settle()`:留出集复核 → 追准 → 沉淀 | `settle.py` |
|
|
153
|
+
| 自动提问 + 上网 + 外部当裁判 | `Questioner` 出题 + `Resolver` 注入外部源(不内置联网) | `truth.py` |
|
|
154
|
+
| random 特殊图案当假设种子 | 六类结构图案 | `patterns.py` |
|
|
155
|
+
| 海量特殊图案矩阵当原材料池 | `patterns.pool()` + `EvolvingPool`(会持续演化) | `patterns.py` |
|
|
156
|
+
| 步骤序列任意长/顺序/嵌套/跳转/进化 | `Sequence` 嵌 `Sequence`,`Step.when/jump` | `steps.py` |
|
|
157
|
+
| 自动学习生成 steps | `Policy.observe/suggest/evolve` | `steps.py` |
|
|
158
|
+
| 单源是观点,多源一致才是真实 | `cross_validate()`:只数**独立 group**,转载不算 | `truth.py` |
|
|
159
|
+
|
|
160
|
+
## 一轮长什么样
|
|
161
|
+
|
|
162
|
+
```
|
|
163
|
+
评估 所有假设一次算完(堆叠张量 W (size,d,k) + einsum)
|
|
164
|
+
排名 按 (准确率, 置信度余量) 排队
|
|
165
|
+
记错 排名末尾 cull_ratio 记一次 strike(第一名有保护)
|
|
166
|
+
死亡 strike 到线就死:内容清空,指纹留成墓碑,坐标保留
|
|
167
|
+
复活 同坐标重建:繁殖(抄精英+加性变异)或探索(残留+新血)
|
|
168
|
+
退火 连续没进步就缩小步长,有进步就恢复
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
**三条踩坑换来的洞察:**
|
|
172
|
+
|
|
173
|
+
1. **只有淘汰没有繁殖,永远学不会**——从失败者的残留重生,准确率死锁 0.61。
|
|
174
|
+
2. **乘性噪声学不动**——`P *= (1+ε)` 只能缩放不能转向,改加性才开始爬。
|
|
175
|
+
3. **淘汰要按排名不按绝对分**——"低于平均"会让分数线随平均涨,强者也被判错。
|
|
176
|
+
|
|
177
|
+
## 计算引擎
|
|
178
|
+
|
|
179
|
+
- **纯张量**:所有神经元共用一个 `W (size, d, k)`,一次 `einsum("nd,sdk->nsk")` 算完「样本 × 神经元 × 类别」。
|
|
180
|
+
- `backend="numpy"`(默认)/ `backend="torch"`:同一套公式,两条后端,结果一致。
|
|
181
|
+
- 实测:48 神经元 × 80 样本 × 60 轮,**5.42s → 0.17s(约 32×)**,torch 后端 0.14s。
|
|
182
|
+
- **没有任何 UI / 绘图依赖**,只返回 numpy 数组。
|
|
183
|
+
|
|
184
|
+
## 图案会一直变:`EvolvingPool`
|
|
185
|
+
|
|
186
|
+
每代:**按适应度留精英 → 两两混合 → 加性变异 → 投影回原结构**。
|
|
187
|
+
所以第 10 代的对称矩阵仍**严格**对称,但已不是初代那个;低秩投影后秩不变,二值仍只有 ±1。
|
|
188
|
+
`immigration`(迁入率)保证有新鲜血液——纯精英选择会让类型塌缩。
|
|
189
|
+
|
|
190
|
+
## 看图:next_point
|
|
191
|
+
|
|
192
|
+
```python
|
|
193
|
+
sight = infx.look.scan(image, steps=3)
|
|
194
|
+
infx.look.explain(sight)
|
|
195
|
+
# 已看 3 处:(4,4) → (0,0) → (2,1)。下一个该看 (2,2):显著度 0.24,距最近已看点 1 格。
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
选点只有两条可解释规则:**显著度**(`|块均值−全图均值| + 块内标准差`)与**新颖度**(离已看点的距离)。
|
|
199
|
+
视觉证据接进判定时权重上限 **0.3**——看到亮块不能把观点判成事实,有测试守着。
|
|
200
|
+
|
|
201
|
+
## 语法规则库:494 条
|
|
202
|
+
|
|
203
|
+
`infx.grammar` 把"事实/观点"的判定从少量手写规则,扩成一个**可统计、可筛选、可导出**的规则库。
|
|
204
|
+
|
|
205
|
+
```python
|
|
206
|
+
from infx import grammar
|
|
207
|
+
|
|
208
|
+
grammar.stats()
|
|
209
|
+
# {'total': 494, 'by_lang': {'en': 172, 'zh': 322},
|
|
210
|
+
# 'by_family': {'fact': 152, 'opinion': 342},
|
|
211
|
+
# 'by_kind': {'evaluative': 114, 'source': 33, 'modal': 28, ...}} # 18 个细类
|
|
212
|
+
|
|
213
|
+
grammar.match("据新华社报道,温度达到 100 摄氏度。")
|
|
214
|
+
# [RuleMatch(rule=zh.src.900, text='据新华社报道'), RuleMatch(rule=zh.measure.001, text='100 摄氏度')]
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
每条规则都是数据:`id / lang / family / kind / pattern / weight`,命中时能追到具体是哪一条。
|
|
218
|
+
|
|
219
|
+
**加词的流程**:改 `grammar/lexicon.py` 的词表 → 规则自动展开 → 跑测试。因为词表是分类资产,规则是执行形式,两者分开维护。
|
|
220
|
+
|
|
221
|
+
18 个细类:`evaluative` `value` `modal` `hedge` `comparative` `predictive` `rhetoric` `stance` `source` `predicate` `definition` `temporal` `causal` `measure` `date` `ratio` `range` `quote`。
|
|
222
|
+
|
|
223
|
+
**默认不启用**——默认流水线的行为已被 235 项测试固定。要启用:
|
|
224
|
+
|
|
225
|
+
```bash
|
|
226
|
+
python -m infx --grammar "据报,温度达到 100 摄氏度,方案非常糟糕。"
|
|
227
|
+
```
|
|
228
|
+
```python
|
|
229
|
+
from infx.grammar import judges_with_grammar
|
|
230
|
+
verdict = infx.judge_claim(claim, judges=judges_with_grammar())
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
## 句法分析:否定、条件、引用
|
|
234
|
+
|
|
235
|
+
`infx.syntax` 解决"语法规则只看词形、不看结构"的盲区。
|
|
236
|
+
|
|
237
|
+
```python
|
|
238
|
+
from infx.syntax import analyze
|
|
239
|
+
|
|
240
|
+
p = analyze("如果温度达到 100 摄氏度,水就会沸腾。")
|
|
241
|
+
p.is_conditional, p.conditionals # True, ['如果…就']
|
|
242
|
+
p.clauses, p.depth # 从句列表、括号嵌套深度
|
|
243
|
+
p.negations, p.quotes, p.reported # 否定词、引用、转述
|
|
244
|
+
p.comparatives, p.causals, p.hedges # 比较、因果、模糊限制
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
**否定作用域**是重点:`这并不重要` 里"重要"命中了评价词,但否定之后语义反转。
|
|
248
|
+
`syntax.scope` 把否定划到**本从句结束**(最多 24 字),并给出 `is_negated(text, start, end)`。
|
|
249
|
+
长否定词优先匹配:`并非` 不会被拆成 `非`。
|
|
250
|
+
|
|
251
|
+
## 批处理 / 相似度 / 报告
|
|
252
|
+
|
|
253
|
+
```python
|
|
254
|
+
# 批量:列表进、记录出;或 JSONL 进、JSONL 出
|
|
255
|
+
rows = infx.bulk_judge(["句子1", "句子2"], with_syntax=True)
|
|
256
|
+
infx.judge_jsonl("in.jsonl", "out.jsonl")
|
|
257
|
+
|
|
258
|
+
# 相似度:去重、找最近邻(字符 bigram 的 Jaccard + 词频余弦)
|
|
259
|
+
infx.jaccard("水的沸点是100摄氏度", "水的沸点是100摄氏度") # 1.0
|
|
260
|
+
infx.dedupe(texts, threshold=0.9) # 保留哪些下标
|
|
261
|
+
infx.most_similar("水的沸点", candidates) # (下标, 分数)
|
|
262
|
+
|
|
263
|
+
# 报告:纯文本 / Markdown(不做 UI,只产出字符串)
|
|
264
|
+
print(infx.markdown_report(infx.assess(text)))
|
|
265
|
+
print(infx.syntax_report("如果 A 则 B,这并不重要。"))
|
|
266
|
+
print(infx.grammar_report("据新华社报道,温度达到 100 摄氏度。"))
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
## 质量数字(诚实版)
|
|
270
|
+
|
|
271
|
+
| 集合 | 规模 | 准确率 | 宏 F1 | 说明 |
|
|
272
|
+
|---|---|---|---|---|
|
|
273
|
+
| 回归集 `quality.LABELED` | 49 | **100%** | 1.000 | **照规则写的,不是盲测**;唯一用途是防退化 |
|
|
274
|
+
| 对抗集 `quality.ADVERSARIAL` | 10 | **90%** | 0.859 | 照已知弱点写:反讽、双重否定、条件句 |
|
|
275
|
+
|
|
276
|
+
```bash
|
|
277
|
+
python -c "from infx import quality; print(quality.report(quality.evaluate(quality.LABELED)))"
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
```
|
|
281
|
+
样本 49 条(跳过 0)
|
|
282
|
+
准确率 100.0% 宏平均 F1 1.000
|
|
283
|
+
|
|
284
|
+
标签 精确率 召回率 F1 样本
|
|
285
|
+
fact 1.00 1.00 1.00 18
|
|
286
|
+
opinion 1.00 1.00 1.00 19
|
|
287
|
+
mixed 1.00 1.00 1.00 12
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
另外两个数字:
|
|
291
|
+
|
|
292
|
+
- **死规则审计**:59 句语料只激活 **50/494** 条规则(10.1%)。这是词形库的正常现象——494 是**覆盖上限**,不是每条都会用上。
|
|
293
|
+
- **性能**:语法引擎 **0.20 ms/句**(494 条规则,已按语言过滤)。
|
|
294
|
+
|
|
295
|
+
**这些数字说明什么**:规则系统在常见句式上很稳,在结构复杂句上会错。
|
|
296
|
+
要判断它是否适合你的数据,跑 `quality.evaluate(你的样本)`——它接受任意 `[(文本, 标签)]`。
|
|
297
|
+
|
|
298
|
+
## 诚实边界
|
|
299
|
+
|
|
300
|
+
| 不要期待 | 原因 |
|
|
301
|
+
|---|---|
|
|
302
|
+
| 打败 Transformer | 这是机制原型,没有大规模数据与预训练 |
|
|
303
|
+
| 保证 100% 准确率 | 无梯度随机搜索,实测收敛 0.93–0.99 |
|
|
304
|
+
| 真"看懂"图 | `Eye` 的 GRU 未训练;`OfflineLMM` 只给统计描述,**不是 LMM** |
|
|
305
|
+
| 自己联网查证 | `Resolver` 的抓取函数要你注入(离线可测) |
|
|
306
|
+
|
|
307
|
+
## 测试
|
|
308
|
+
|
|
309
|
+
```bash
|
|
310
|
+
cd work/python/inference
|
|
311
|
+
python -m unittest discover -s tests -t . # 249 项,全绿,约 0.7s
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
其中 15 项是**架构规则测试**(分层方向、look 独立性、look 依赖栈、两个入口、依赖三处一致、命名分家)。
|
|
315
|
+
|
|
316
|
+
## 目录
|
|
317
|
+
|
|
318
|
+
```
|
|
319
|
+
inference/ # 项目(发行名 inference)
|
|
320
|
+
├── infx/ # 包(import infx)—— 50 个模块
|
|
321
|
+
│ ├── death.py colony.py patterns.py steps.py truth.py settle.py knowledge.py table.py
|
|
322
|
+
│ ├── grammar/ # 494 条语法规则:lexicon → rules → engine → judge
|
|
323
|
+
│ ├── syntax/ # 分句 / 否定作用域 / 句法画像
|
|
324
|
+
│ ├── batch.py similarity.py report.py
|
|
325
|
+
│ ├── core/ judgment/ spoken/ # 文本事实/观点判定层
|
|
326
|
+
│ ├── look/ # 看图片:eye(GRU) / lmm / sight / evidence
|
|
327
|
+
│ └── cli.py # python -m infx "文本"
|
|
328
|
+
├── tests/ # 235 项
|
|
329
|
+
├── examples/
|
|
330
|
+
└── pyproject.toml
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
## 参考
|
|
334
|
+
|
|
335
|
+
- `[[ai-coding]]` —— 围栏与验收优先;本项目的测试与"诚实边界"照它做
|
|
336
|
+
- `[[hallucination]]` —— 单源就是幻觉温床;交叉验证判据的由来
|
|
337
|
+
- `[[evals]]` —— 没有评测集就没有进步;README 里的实测数字就是这条的落地
|
|
338
|
+
- `[[llm-wiki]]` —— 把维护成本交给机制,人只做策展
|
|
339
|
+
|
|
340
|
+
## License
|
|
341
|
+
|
|
342
|
+
MIT
|