lakun 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.
- lakun-0.1.0/LICENSE +176 -0
- lakun-0.1.0/MANIFEST.in +10 -0
- lakun-0.1.0/PKG-INFO +73 -0
- lakun-0.1.0/PYPI_README.md +52 -0
- lakun-0.1.0/README.md +131 -0
- lakun-0.1.0/README.zh-CN.md +131 -0
- lakun-0.1.0/START.md +48 -0
- lakun-0.1.0/examples/text_input.json +20 -0
- lakun-0.1.0/lakun/__init__.py +15 -0
- lakun-0.1.0/lakun/cli.py +99 -0
- lakun-0.1.0/lakun/data.py +100 -0
- lakun-0.1.0/lakun/encoding.py +99 -0
- lakun-0.1.0/lakun/inference.py +152 -0
- lakun-0.1.0/lakun/model.py +50 -0
- lakun-0.1.0/lakun/model_card.py +65 -0
- lakun-0.1.0/lakun/pretrained.py +94 -0
- lakun-0.1.0/lakun/split_data.py +91 -0
- lakun-0.1.0/lakun/train.py +342 -0
- lakun-0.1.0/lakun/vendor/__init__.py +1 -0
- lakun-0.1.0/lakun/vendor/laya/LICENSE +176 -0
- lakun-0.1.0/lakun/vendor/laya/__init__.py +5 -0
- lakun-0.1.0/lakun/vendor/laya/common.py +251 -0
- lakun-0.1.0/lakun.egg-info/PKG-INFO +73 -0
- lakun-0.1.0/lakun.egg-info/SOURCES.txt +42 -0
- lakun-0.1.0/lakun.egg-info/dependency_links.txt +1 -0
- lakun-0.1.0/lakun.egg-info/entry_points.txt +2 -0
- lakun-0.1.0/lakun.egg-info/requires.txt +10 -0
- lakun-0.1.0/lakun.egg-info/top_level.txt +1 -0
- lakun-0.1.0/main.py +12 -0
- lakun-0.1.0/predict_lakun.py +64 -0
- lakun-0.1.0/pyproject.toml +35 -0
- lakun-0.1.0/requirements-train.txt +8 -0
- lakun-0.1.0/setup.cfg +4 -0
- lakun-0.1.0/tests/test_cli.py +62 -0
- lakun-0.1.0/tests/test_distributed.py +49 -0
- lakun-0.1.0/tests/test_encoding.py +58 -0
- lakun-0.1.0/tests/test_inference_cli.py +28 -0
- lakun-0.1.0/tests/test_launcher.py +32 -0
- lakun-0.1.0/tests/test_loss.py +20 -0
- lakun-0.1.0/tests/test_pipeline.py +81 -0
- lakun-0.1.0/tests/test_pretrained.py +36 -0
- lakun-0.1.0/tests/test_split.py +43 -0
- lakun-0.1.0/train_lakun.py +33 -0
lakun-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
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 patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date 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 exercise of permissions under this License.
|
|
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 warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
lakun-0.1.0/MANIFEST.in
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
include LICENSE
|
|
2
|
+
include README.md README.zh-CN.md PYPI_README.md START.md
|
|
3
|
+
include main.py train_lakun.py predict_lakun.py requirements-train.txt
|
|
4
|
+
recursive-include examples *.json
|
|
5
|
+
recursive-include lakun *.py LICENSE
|
|
6
|
+
prune dataset
|
|
7
|
+
prune images
|
|
8
|
+
prune runs
|
|
9
|
+
prune weights
|
|
10
|
+
prune offline_wheels
|
lakun-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: lakun
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Typed decisions from text or one image with LaKun
|
|
5
|
+
Author: AI Discussion Room
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
License-File: lakun/vendor/laya/LICENSE
|
|
11
|
+
Requires-Dist: torch>=2.6
|
|
12
|
+
Requires-Dist: transformers<5,>=4.57
|
|
13
|
+
Requires-Dist: accelerate<2,>=0.26
|
|
14
|
+
Requires-Dist: safetensors>=0.4
|
|
15
|
+
Requires-Dist: huggingface-hub>=0.20
|
|
16
|
+
Requires-Dist: Pillow>=10
|
|
17
|
+
Requires-Dist: numpy>=1.24
|
|
18
|
+
Provides-Extra: test
|
|
19
|
+
Requires-Dist: pytest>=8; extra == "test"
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
|
|
22
|
+
# LaKun:文本与单图的类型化决策模型
|
|
23
|
+
|
|
24
|
+
我做 LaKun,是为了让模型针对一段文本状态或一张图片,直接回答我指定的选择、档位评分和二元判断问题。它输出每个候选项的 softmax 分数与最高分选项,不生成自由文本。一次调用最多可提交 20 道问题,目前每次最多处理一张图片。
|
|
25
|
+
|
|
26
|
+
这个 PyPI 安装包提供推理代码,源码包另含训练脚本;两种发行文件都**不包含权重或数据集**。我的完整检查点有 756,409,158 个参数;`lakun.safetensors` 大小为 3,025,715,432 字节(2.82 GiB),完整推理目录约 2.85 GiB。`0.7B` 是模型仓库名中的近似称呼。
|
|
27
|
+
|
|
28
|
+
## 安装与使用
|
|
29
|
+
|
|
30
|
+
先安装适合本机的 PyTorch,再安装 LaKun:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
python -m pip install lakun
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
我目前还没有公开模型权重。只有已经取得**完整本地检查点目录**的人才能运行推理;安装代码包不会下载权重,`--checkpoint` 也不接受魔塔仓库 ID。我的源码项目中,检查点目录是 `runs/lakun_full/best`。在该目录存在的项目根目录下运行下面的命令,就能交互输入一道题、文本状态或本地图片路径:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
lakun --checkpoint runs/lakun_full/best
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
纯文本单题也可以直接传参:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
lakun --checkpoint runs/lakun_full/best --state "订单已经退款。" --type noul --question "订单是否已经退款?"
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
在交互模式下,输入图片路径即可问单图问题;选择题的候选项用 `|` 分隔。需要在脚本中使用时:
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
from lakun import LaKunPredictor
|
|
52
|
+
|
|
53
|
+
model = LaKunPredictor.from_pretrained("runs/lakun_full/best")
|
|
54
|
+
result = model.predict(
|
|
55
|
+
[{"type": "choice", "question": "这是什么类型的请求?", "criteria": ["咨询", "投诉", "退款"]}],
|
|
56
|
+
state="用户说:我被重复扣费了,请尽快退款。",
|
|
57
|
+
)
|
|
58
|
+
print(result["answers"][0])
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
`choice` 接受 2–20 个候选项,`score` 接受 3–20 个有序档位,`noul` 固定为 `false/true`。`predicted_index` 从 0 开始。上下文最多 512 token;输入超限时,我的实现优先保留问题和候选项,再保留状态开头。这里的 softmax 分数未经概率校准,不能直接当成现实中的正确率。
|
|
62
|
+
|
|
63
|
+
## 我测到的表现
|
|
64
|
+
|
|
65
|
+
在按组隔离的测试集上,所选检查点与 `qwen3.8-flash` 生成的伪标签的一致率为:选择题 **83.11%**、评分题 **83.37%**、二元题 **80.92%**,共 12,703 组、38,141 题。这不是人工核验的通用准确率。我以验证损失选出第 16,882 步检查点;第二轮训练损失继续下降、验证损失反而上升,所以没有保留更晚的权重。
|
|
66
|
+
|
|
67
|
+
我在 Windows 11、RTX 3060 12GB、PyTorch 2.7.1+cu126、FP32 下,先预热 5 次,再串行测 30 次 `predict()`:纯文本单题中位耗时 **17.01 ms**,单图单题 **162.01 ms**。计时包含分词、图片预处理(如适用)、前向传播和结果整理,不含权重加载、下载和网络耗时;其他硬件的速度可能不同。
|
|
68
|
+
|
|
69
|
+
## 我目前看到的局限
|
|
70
|
+
|
|
71
|
+
在接近我的训练数据分布的题目上,LaKun 已有可用表现;我观察到带明确数值线索或候选项间简单推理的任务比较容易答好,但还没有独立分项测评来证明这一点。外部垃圾评论分类实验显示跨领域迁移较弱;第二轮验证损失变差也让我警惕过度专用化,甚至可能存在微调坍塌,但尚不能证明底座能力已经丧失。数据伪标签、答案位置偏斜、单图限制及未经校准的分数,都需要谨慎对待。
|
|
72
|
+
|
|
73
|
+
源码采用 Apache-2.0。**模型权重的许可尚未确定,也尚未公开**;源码许可不等于权重许可。我的 GitHub 源码仓库和魔塔权重仓库目前都是私有的。
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# LaKun:文本与单图的类型化决策模型
|
|
2
|
+
|
|
3
|
+
我做 LaKun,是为了让模型针对一段文本状态或一张图片,直接回答我指定的选择、档位评分和二元判断问题。它输出每个候选项的 softmax 分数与最高分选项,不生成自由文本。一次调用最多可提交 20 道问题,目前每次最多处理一张图片。
|
|
4
|
+
|
|
5
|
+
这个 PyPI 安装包提供推理代码,源码包另含训练脚本;两种发行文件都**不包含权重或数据集**。我的完整检查点有 756,409,158 个参数;`lakun.safetensors` 大小为 3,025,715,432 字节(2.82 GiB),完整推理目录约 2.85 GiB。`0.7B` 是模型仓库名中的近似称呼。
|
|
6
|
+
|
|
7
|
+
## 安装与使用
|
|
8
|
+
|
|
9
|
+
先安装适合本机的 PyTorch,再安装 LaKun:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
python -m pip install lakun
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
我目前还没有公开模型权重。只有已经取得**完整本地检查点目录**的人才能运行推理;安装代码包不会下载权重,`--checkpoint` 也不接受魔塔仓库 ID。我的源码项目中,检查点目录是 `runs/lakun_full/best`。在该目录存在的项目根目录下运行下面的命令,就能交互输入一道题、文本状态或本地图片路径:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
lakun --checkpoint runs/lakun_full/best
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
纯文本单题也可以直接传参:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
lakun --checkpoint runs/lakun_full/best --state "订单已经退款。" --type noul --question "订单是否已经退款?"
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
在交互模式下,输入图片路径即可问单图问题;选择题的候选项用 `|` 分隔。需要在脚本中使用时:
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
from lakun import LaKunPredictor
|
|
31
|
+
|
|
32
|
+
model = LaKunPredictor.from_pretrained("runs/lakun_full/best")
|
|
33
|
+
result = model.predict(
|
|
34
|
+
[{"type": "choice", "question": "这是什么类型的请求?", "criteria": ["咨询", "投诉", "退款"]}],
|
|
35
|
+
state="用户说:我被重复扣费了,请尽快退款。",
|
|
36
|
+
)
|
|
37
|
+
print(result["answers"][0])
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
`choice` 接受 2–20 个候选项,`score` 接受 3–20 个有序档位,`noul` 固定为 `false/true`。`predicted_index` 从 0 开始。上下文最多 512 token;输入超限时,我的实现优先保留问题和候选项,再保留状态开头。这里的 softmax 分数未经概率校准,不能直接当成现实中的正确率。
|
|
41
|
+
|
|
42
|
+
## 我测到的表现
|
|
43
|
+
|
|
44
|
+
在按组隔离的测试集上,所选检查点与 `qwen3.8-flash` 生成的伪标签的一致率为:选择题 **83.11%**、评分题 **83.37%**、二元题 **80.92%**,共 12,703 组、38,141 题。这不是人工核验的通用准确率。我以验证损失选出第 16,882 步检查点;第二轮训练损失继续下降、验证损失反而上升,所以没有保留更晚的权重。
|
|
45
|
+
|
|
46
|
+
我在 Windows 11、RTX 3060 12GB、PyTorch 2.7.1+cu126、FP32 下,先预热 5 次,再串行测 30 次 `predict()`:纯文本单题中位耗时 **17.01 ms**,单图单题 **162.01 ms**。计时包含分词、图片预处理(如适用)、前向传播和结果整理,不含权重加载、下载和网络耗时;其他硬件的速度可能不同。
|
|
47
|
+
|
|
48
|
+
## 我目前看到的局限
|
|
49
|
+
|
|
50
|
+
在接近我的训练数据分布的题目上,LaKun 已有可用表现;我观察到带明确数值线索或候选项间简单推理的任务比较容易答好,但还没有独立分项测评来证明这一点。外部垃圾评论分类实验显示跨领域迁移较弱;第二轮验证损失变差也让我警惕过度专用化,甚至可能存在微调坍塌,但尚不能证明底座能力已经丧失。数据伪标签、答案位置偏斜、单图限制及未经校准的分数,都需要谨慎对待。
|
|
51
|
+
|
|
52
|
+
源码采用 Apache-2.0。**模型权重的许可尚未确定,也尚未公开**;源码许可不等于权重许可。我的 GitHub 源码仓库和魔塔权重仓库目前都是私有的。
|
lakun-0.1.0/README.md
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# LaKun: typed decisions from text or one image
|
|
2
|
+
|
|
3
|
+
English · [简体中文](README.zh-CN.md) · [Dataset profile and charts](analysis/DATASET_PROFILE.md)
|
|
4
|
+
|
|
5
|
+
I built LaKun to answer questions I define in advance about a text state or a single image: choose among options, select an ordered rating bin, or decide `false/true`. It returns softmax scores and the highest-scoring option for each question. It does not generate free-form text and is not a chat model. One `predict()` call can contain all three question types, with up to 20 questions and one image.
|
|
6
|
+
|
|
7
|
+
> **Release status:** I distribute the code package on PyPI. My [GitHub source repository](https://github.com/AI-Discussion-Room/LaKun) and [ModelScope weight repository](https://modelscope.cn/models/hh108801/LaKun-0.7B) remain **private**. The code is Apache-2.0; the weight license is **not yet decided** and must not be inferred from the code license. Installing the package alone does not provide a checkpoint.
|
|
8
|
+
|
|
9
|
+
## At a glance
|
|
10
|
+
|
|
11
|
+
| Item | Current implementation / measurement |
|
|
12
|
+
|---|---|
|
|
13
|
+
| Input | A text state or one image, with 1–20 typed questions |
|
|
14
|
+
| Questions | `choice`: 2–20 options; `score`: 3–20 bins; `noul`: `false/true` |
|
|
15
|
+
| Output | Per-question `criteria`, `probabilities`, and `predicted_index`; probability calibration is **not validated** |
|
|
16
|
+
| Architecture | mmBERT-base + SigLIP SO400M + visual-token bridge + typed decision head |
|
|
17
|
+
| Parameter count | **756,409,158 (~0.756B)** across 627 checkpoint tensors; `0.7B` is an approximate repository name |
|
|
18
|
+
| Weight size | `lakun.safetensors`: **3,025,715,432 bytes (2.82 GiB)**; complete inference directory: about **2.85 GiB** |
|
|
19
|
+
| Context | At most 512 tokens, reserving 64 visual tokens for images; overlength inputs are truncated, prioritizing question/options and the start of the state |
|
|
20
|
+
|
|
21
|
+
I jointly fine-tuned the text and vision encoders. I did **not** load a Laya fine-tuned checkpoint; the decision head uses Laya-derived code with its notice preserved. LaKun's results are not Laya's results.
|
|
22
|
+
|
|
23
|
+
## Quick start
|
|
24
|
+
|
|
25
|
+
Install a PyTorch build appropriate for your machine first. Install my code package from PyPI:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
python -m pip install lakun
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
If you have access to my source checkout, you can instead run these commands from the project root:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
python -m pip install -e .
|
|
35
|
+
python predict_lakun.py --checkpoint runs/lakun_full/best --input examples/text_input.json
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
For **one question at a time**, run `python main.py --checkpoint runs/lakun_full/best` and enter a text state (or image path), question type, question, and options at the prompts. You can also use a non-interactive command:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
python main.py --checkpoint runs/lakun_full/best --state "The order has been refunded." --type noul --question "Has the order been refunded?"
|
|
42
|
+
# One-image example: replace photo.jpg with your local image path
|
|
43
|
+
python main.py --checkpoint runs/lakun_full/best --image photo.jpg --type choice --question "What is shown?" --criteria cat dog car
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The command prints the top option and all softmax scores. After a PyPI installation, use `lakun --checkpoint runs/lakun_full/best` for the same interactive interface when running from my project root with its private checkpoint present.
|
|
47
|
+
|
|
48
|
+
`runs/lakun_full/best/` is my local complete checkpoint, not part of the Git repository. If you have access to the private ModelScope repository, download it first and pass the resulting local directory to `--checkpoint`; the loader does **not** accept a repository ID directly.
|
|
49
|
+
|
|
50
|
+
Here is the real API with all three question types in one request. Supply `state=` for text, or `image="/path/to/image.jpg"` for one local image:
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
from lakun import LaKunPredictor
|
|
54
|
+
|
|
55
|
+
model = LaKunPredictor.from_pretrained("runs/lakun_full/best")
|
|
56
|
+
result = model.predict(
|
|
57
|
+
[
|
|
58
|
+
{"type": "choice", "question": "What kind of request is this?", "criteria": ["question", "complaint", "refund"]},
|
|
59
|
+
{"type": "score", "question": "How urgent is it?", "criteria": ["low", "medium", "high"]},
|
|
60
|
+
{"type": "noul", "question": "Does the user request a refund?", "criteria": ["false", "true"]},
|
|
61
|
+
],
|
|
62
|
+
state="The customer says they were charged twice and asks for a prompt refund.",
|
|
63
|
+
)
|
|
64
|
+
for answer in result["answers"]:
|
|
65
|
+
print(answer["type"], answer["predicted_index"], answer["probabilities"])
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
`predicted_index` is zero-based and refers to the supplied option order. For `score`, it is the winning **bin index**, not a continuous regression output. The probabilities are softmax values, not calibrated real-world correctness probabilities.
|
|
69
|
+
|
|
70
|
+
For overlength inputs, the encoder keeps the question and options first (shortening very long options if necessary), then as much of the **beginning of the state** as fits. Discarded trailing text is not considered. Summarize or split long documents if the important evidence appears near the end.
|
|
71
|
+
|
|
72
|
+
## What I measured
|
|
73
|
+
|
|
74
|
+
I split groups—not individual questions—between training, validation and test. I selected the checkpoint at optimizer step **16,882** using validation loss. On **12,703 held-out groups / 38,141 questions**, agreement with the teacher's pseudo-labels was:
|
|
75
|
+
|
|
76
|
+
| Type | Agreement |
|
|
77
|
+
|---|---:|
|
|
78
|
+
| Choice | 83.11% |
|
|
79
|
+
| Score | 83.37% |
|
|
80
|
+
| Noul | 80.92% |
|
|
81
|
+
|
|
82
|
+
The labels were generated by `qwen3.8-flash`, not verified by people. These are **not** general-purpose accuracy, reasoning, or probability-calibration scores. Best validation loss was `0.014464`. During the second epoch, training loss kept falling while validation loss rose, so I retained the earlier checkpoint and stopped training.
|
|
83
|
+
|
|
84
|
+
### Local inference speed
|
|
85
|
+
|
|
86
|
+
I measured the complete `LaKunPredictor.predict()` call on **Windows 11**, an **NVIDIA GeForce RTX 3060 12GB**, **PyTorch 2.7.1+cu126**, using FP32 inference. For each scenario I ran 5 warm-ups and 30 sequential timed calls, synchronizing CUDA before and after timing. The measurement includes tokenization, image decoding/preprocessing where applicable, forward pass, and result construction. It **excludes** checkpoint loading, download, and network overhead. The image is one local held-out sample; this is a speed test, not an accuracy test.
|
|
87
|
+
|
|
88
|
+
| Scenario | Questions/call | Median | p95 |
|
|
89
|
+
|---|---:|---:|---:|
|
|
90
|
+
| Text | 1 | 17.01 ms | 19.23 ms |
|
|
91
|
+
| Text | 3 | 18.18 ms | 18.65 ms |
|
|
92
|
+
| One image | 1 | 162.01 ms | 168.69 ms |
|
|
93
|
+
| One image | 3 | 168.71 ms | 171.59 ms |
|
|
94
|
+
|
|
95
|
+
I include both the [benchmark script](analysis/benchmark_inference.py) and the [measurement record](analysis/benchmark_rtx3060_2026-09-24.json). To rerun: `python -m analysis.benchmark_inference --checkpoint runs/lakun_full/best --image /path/to/one-image.jpg`. These results should not be presented as RTX 4090 throughput or concurrent serving latency.
|
|
96
|
+
|
|
97
|
+
## My dataset
|
|
98
|
+
|
|
99
|
+
I unified images and text into **one state + multiple typed questions** per group. All question labels were generated by `qwen3.8-flash`. The current profile contains **126,663 groups / 380,424 questions**: 59,996 image groups / 180,424 questions and 66,667 text groups / 200,000 questions. Choice, score and noul occur at similar frequencies. The approximately 8:1:1 split keeps every group's questions together.
|
|
100
|
+
|
|
101
|
+

|
|
102
|
+
|
|
103
|
+
The profile also covers option counts, rating bins, seven image source subsets and 50 synthetic text topics. One important bias: among four-option questions, option B is the teacher's answer in **53.15%** of image questions and **46.48%** of text questions; D is only **1.74%** and **2.98%**, respectively. The model may exploit answer position rather than content.
|
|
104
|
+
|
|
105
|
+

|
|
106
|
+
|
|
107
|
+
[Source and coverage chart](analysis/figures/03-coverage.png) · [All 50 text topics and answer positions](analysis/figures/04-domains-and-choice-labels.png) · [Full dataset profile](analysis/DATASET_PROFILE.md). The chart labels are currently Chinese.
|
|
108
|
+
|
|
109
|
+
I have not uploaded the raw JSONL, images, or the 1,000 inspected test examples to GitHub or ModelScope. These charts contain aggregates only. Upstream image/data terms need further review before any dataset release.
|
|
110
|
+
|
|
111
|
+
## Training and reproducibility
|
|
112
|
+
|
|
113
|
+
`train_lakun.py` needs Python 3.10+, a CUDA-enabled PyTorch build, `requirements-train.txt`, the original base weights under `weights/mmbert-base/` and `weights/siglip-so400m-patch14-384/`, plus six `dataset/{image,text}_{train,val,test}.jsonl` files and their referenced images. I recommend a small pipeline run before full training:
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
python -m pip install -r requirements-train.txt
|
|
117
|
+
python train_lakun.py --train-groups 12 --val-groups 6 --test-groups 6 --epochs 1 --out runs/lakun_pilot
|
|
118
|
+
python train_lakun.py
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
The script uses visible local GPUs (DDP with multiple GPUs), checks validation every 3,000 optimizer steps, runs at most three epochs, and stops after three checks without sufficient loss improvement. The complete `best/` directory contains both encoders and the custom decision components; do not download just the `.safetensors` file. Current checkpoints omit optimizer state and cannot resume the precise interrupted training step. See [`START.md`](START.md).
|
|
122
|
+
|
|
123
|
+
## Release boundaries
|
|
124
|
+
|
|
125
|
+
I keep code in [`AI-Discussion-Room/LaKun`](https://github.com/AI-Discussion-Room/LaKun) and weights in [`hh108801/LaKun-0.7B`](https://modelscope.cn/models/hh108801/LaKun-0.7B); both repositories are private at present. I distribute the code package through PyPI, without weights or data; see my [release checklist](RELEASE_PYPI.md). A `pip install lakun` installation still needs a complete checkpoint obtained separately. Transformers `AutoModel.from_pretrained()` cannot load this custom architecture directly. The source is [Apache-2.0](LICENSE); before a public weight release I still need to review upstream model/data terms and decide on a separate weight license.
|
|
126
|
+
|
|
127
|
+
## Limitations I am seeing
|
|
128
|
+
|
|
129
|
+
Within a distribution close to my training data, LaKun is already useful for these typed decisions. In informal use, I find questions with explicit numerical cues or simple inference between supplied options easier for it, **but I have not run a separate controlled benchmark for that observation**. An external spam-classification experiment exposed weak cross-domain transfer. Falling training loss alongside worse validation loss also makes me concerned about over-specialization or a form of “fine-tuning collapse.” I cannot yet prove that the pretrained backbone itself has lost capability; that needs comparisons with the unfine-tuned base, other checkpoints, and human-labeled out-of-domain tests.
|
|
130
|
+
|
|
131
|
+
I therefore do not claim this is a general classifier, a strongly generalizing vision model, or a verified numerical-reasoning model. One-image input, answer-position bias, pseudo-label error, uncalibrated scores, cross-domain behavior, and data provenance remain open limitations.
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# LaKun:让文字或单张图片回答类型化问题
|
|
2
|
+
|
|
3
|
+
[English](README.md) · 简体中文 · [数据集完整统计](analysis/DATASET_PROFILE.md)
|
|
4
|
+
|
|
5
|
+
我做 LaKun,是想让模型面对一段状态或一张图片时,直接回答我预先定义的问题:从候选项中选择、按档位评分,或者回答 `false/true`。它输出每个候选项的 softmax 分数和最高分选项,不生成自由文本,也不是聊天模型。一次 `predict()` 可以同时提交这三类问题;目前一个请求最多 20 题、最多一张图片。
|
|
6
|
+
|
|
7
|
+
> **发布状态:**我通过 PyPI 分发代码包。源码位于私有 GitHub 仓库,完整权重位于私有魔塔仓库 [`hh108801/LaKun-0.7B`](https://modelscope.cn/models/hh108801/LaKun-0.7B)。代码采用 Apache-2.0;**权重的公开许可尚未确定**,我不会把源码许可自动等同于权重许可。只安装代码包不能完成推理。
|
|
8
|
+
|
|
9
|
+
## 一眼看懂
|
|
10
|
+
|
|
11
|
+
| 项目 | 当前实现与实测 |
|
|
12
|
+
|---|---|
|
|
13
|
+
| 输入 | 文本状态,或单张图片;每次 1–20 个类型化问题 |
|
|
14
|
+
| 问题 | `choice` 2–20 个候选项;`score` 3–20 档;`noul` 固定 `false/true` |
|
|
15
|
+
| 输出 | 每题的 `criteria`、`probabilities`、`predicted_index`;**概率尚未做校准验证** |
|
|
16
|
+
| 模型 | mmBERT-base + SigLIP SO400M + 视觉 token 桥接 + 决策头 |
|
|
17
|
+
| 参数量 | **756,409,158(约 0.756B)**,从本检查点 627 个张量逐项统计;`0.7B` 是仓库名中的近似称呼 |
|
|
18
|
+
| 权重体积 | `lakun.safetensors` **3,025,715,432 字节(2.82 GiB)**;完整推理目录约 **2.85 GiB** |
|
|
19
|
+
| 上下文 | 最多 512 token(图像预留 64 个视觉 token);超限时自动截断,优先保留问题/候选项和状态开头 |
|
|
20
|
+
|
|
21
|
+
我联合微调了文本和视觉编码器,没有使用 Laya 已训练好的权重。决策头借鉴并保留了 Laya 衍生代码及许可证;因此 LaKun 的指标不能当作 Laya 的指标。
|
|
22
|
+
|
|
23
|
+
## 先跑起来
|
|
24
|
+
|
|
25
|
+
先安装与本机驱动匹配的 PyTorch,再从 PyPI 安装我的代码包:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
python -m pip install lakun
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
已有源码访问权限时,也可以在项目根目录改用以下命令:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
python -m pip install -e .
|
|
35
|
+
python predict_lakun.py --checkpoint runs/lakun_full/best --input examples/text_input.json
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
如果只想自己输入**一道题**,运行 `python main.py --checkpoint runs/lakun_full/best`,按提示填写文本状态(或一张图片的路径)、题型、问题和候选项。也可以不进入交互模式,直接给参数:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
python main.py --checkpoint runs/lakun_full/best --state "订单已经退款。" --type noul --question "订单是否已经退款?"
|
|
42
|
+
# 单图示例:把 photo.jpg 换成你自己的图片路径
|
|
43
|
+
python main.py --checkpoint runs/lakun_full/best --image photo.jpg --type choice --question "图中是什么?" --criteria 猫 狗 汽车
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
输出会显示最高分候选项和所有候选项的 softmax 分数。通过 PyPI 安装后,在含有上述私有检查点的项目根目录下,也可以运行 `lakun --checkpoint runs/lakun_full/best` 进入相同的交互界面。
|
|
47
|
+
|
|
48
|
+
`runs/lakun_full/best/` 是我本地的完整检查点目录,不在 GitHub 里。若你有私有魔塔仓库权限,也可以先下载到本地,再将下载目录传给 `--checkpoint`;当前加载器**不接受仓库 ID 代替本地路径**。
|
|
49
|
+
|
|
50
|
+
下面是真实 API 的三题同问示例;`state` 在这里输入,图片任务则通过 `image=` 传一张本地图片:
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
from lakun import LaKunPredictor
|
|
54
|
+
|
|
55
|
+
model = LaKunPredictor.from_pretrained("runs/lakun_full/best")
|
|
56
|
+
result = model.predict(
|
|
57
|
+
[
|
|
58
|
+
{"type": "choice", "question": "这是什么类型的请求?", "criteria": ["咨询", "投诉", "退款"]},
|
|
59
|
+
{"type": "score", "question": "这件事有多紧急?", "criteria": ["不紧急", "一般", "紧急"]},
|
|
60
|
+
{"type": "noul", "question": "用户是否要求退款?", "criteria": ["false", "true"]},
|
|
61
|
+
],
|
|
62
|
+
state="用户说:我被重复扣费了,请尽快退款。",
|
|
63
|
+
)
|
|
64
|
+
for answer in result["answers"]:
|
|
65
|
+
print(answer["type"], answer["predicted_index"], answer["probabilities"])
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
`predicted_index` 从 0 开始,对应你传入的 `criteria` 顺序。`score` 目前返回**最高分档位的索引**,不是连续回归分数。这里的 `probabilities` 是候选项 softmax 值;我还没有做可靠的概率校准测试,不能把 `0.9` 理解为“现实中有 90% 的正确率”。
|
|
69
|
+
|
|
70
|
+
输入过长时,编码器会优先保留问题与候选项(过长的选项也会按预算缩短),再保留**状态文本开头**能装下的部分;被截掉的尾部不会参与判断。如果关键信息在后面,建议先压缩文本或分段提问。
|
|
71
|
+
|
|
72
|
+
## 我测到的效果
|
|
73
|
+
|
|
74
|
+
我按组划分训练、验证和测试集;选模型时只看验证损失,最终保留优化步 **16,882** 的检查点。在 **12,703 组 / 38,141 题**的留出测试集上,它与教师伪标签的一致率为:
|
|
75
|
+
|
|
76
|
+
| 类型 | 一致率 |
|
|
77
|
+
|---|---:|
|
|
78
|
+
| Choice | 83.11% |
|
|
79
|
+
| Score | 83.37% |
|
|
80
|
+
| Noul | 80.92% |
|
|
81
|
+
|
|
82
|
+
这些标签由 `qwen3.8-flash` 生成,**不是人工真值**;这里的数字不是通用准确率,也不能证明数值推理或图片理解的真实能力。最佳验证损失为 `0.014464`;第二轮训练损失继续下降时,验证损失反而上升,所以我保留第一轮末的权重并早停。损失和上面三个一致率是不同指标,不能互相替代。
|
|
83
|
+
|
|
84
|
+
### 本地推理速度
|
|
85
|
+
|
|
86
|
+
我用本项目完整检查点在 **Windows 11、NVIDIA GeForce RTX 3060 12GB、PyTorch 2.7.1+cu126、FP32 推理** 下测量。每种场景先预热 5 次,再串行执行 30 次;每次计时前后同步 CUDA。计时覆盖 `predict()` 的分词、图片读取与预处理、前向传播和结果整理;**不含**模型加载、下载或网络传输。图片来自本地测试集中的一张样本,测速不是准确率评估。
|
|
87
|
+
|
|
88
|
+
| 场景 | 每次问题数 | 中位延迟 | p95 延迟 |
|
|
89
|
+
|---|---:|---:|---:|
|
|
90
|
+
| 纯文本 | 1 | 17.01 ms | 19.23 ms |
|
|
91
|
+
| 纯文本 | 3 | 18.18 ms | 18.65 ms |
|
|
92
|
+
| 单张图片 | 1 | 162.01 ms | 168.69 ms |
|
|
93
|
+
| 单张图片 | 3 | 168.71 ms | 171.59 ms |
|
|
94
|
+
|
|
95
|
+
我把[可复测脚本](analysis/benchmark_inference.py)和[本次测量记录](analysis/benchmark_rtx3060_2026-09-24.json)都放在 `analysis/`。复测命令:`python -m analysis.benchmark_inference --checkpoint runs/lakun_full/best --image /path/to/one-image.jpg`。这组结果仅代表上述机器和输入,不等于 AutoDL 的 4090 速度,也不是多请求并发吞吐。
|
|
96
|
+
|
|
97
|
+
## 我构建的数据集
|
|
98
|
+
|
|
99
|
+
我将图像和文本统一成“**一组状态 + 多道类型化问题**”的格式,问题标签全部来自 `qwen3.8-flash`。当前统计有 **126,663 组 / 380,424 题**:图像 59,996 组 / 180,424 题,文本 66,667 组 / 200,000 题。三类题数量接近,按组约 8:1:1 划分,保证同组问题不会跨训练、验证、测试集。
|
|
100
|
+
|
|
101
|
+

|
|
102
|
+
|
|
103
|
+
我在分析里还统计了候选项数量、评分档位、二元标签、7 个图像来源和 50 个文本方向。最值得警惕的是四选一的答案位置偏斜:图像题的 B 项占 **53.15%**、D 项仅 **1.74%**;文本题 B 项占 **46.48%**、D 项仅 **2.98%**。模型可能利用位置规律,而不是真正理解内容。
|
|
104
|
+
|
|
105
|
+

|
|
106
|
+
|
|
107
|
+
[查看其余两张图:来源/覆盖](analysis/figures/03-coverage.png) · [50 个文本方向及位置分布](analysis/figures/04-domains-and-choice-labels.png) · [完整频数与统计方法](analysis/DATASET_PROFILE.md)
|
|
108
|
+
|
|
109
|
+
我没有把训练 JSONL、图片或测试样本上传到 GitHub / 魔塔。图表是汇总统计,不包含那 1,000 组测试明细;原始图像来源和数据许可还需要逐项核对。
|
|
110
|
+
|
|
111
|
+
## 训练与复现
|
|
112
|
+
|
|
113
|
+
训练入口是 `train_lakun.py`。需要 Python 3.10+、可用的 CUDA PyTorch、`requirements-train.txt`、原始底座权重 `weights/mmbert-base/` 与 `weights/siglip-so400m-patch14-384/`,以及六份 `dataset/{image,text}_{train,val,test}.jsonl` 和图片。先做小样本流程检查,再开始全量训练:
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
python -m pip install -r requirements-train.txt
|
|
117
|
+
python train_lakun.py --train-groups 12 --val-groups 6 --test-groups 6 --epochs 1 --out runs/lakun_pilot
|
|
118
|
+
python train_lakun.py
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
训练默认使用本机可见 GPU(多卡为 DDP),每 3,000 优化步验证,最多 3 轮,连续 3 次验证损失未达到改进阈值则早停。检查点包含两座编码器和自定义决策模块;推理时要保留整个 `best/` 目录,不能只拿 `.safetensors`。当前检查点没有优化器状态,不能无损接着上次中断的优化步训练。详见 [`START.md`](START.md)。
|
|
122
|
+
|
|
123
|
+
## 发布边界
|
|
124
|
+
|
|
125
|
+
我把代码放在 [`AI-Discussion-Room/LaKun`](https://github.com/AI-Discussion-Room/LaKun),把权重放在 [`hh108801/LaKun-0.7B`](https://modelscope.cn/models/hh108801/LaKun-0.7B);两处仓库目前均为**私有**。我通过 PyPI 分发不含权重与数据的代码包,详见[发布清单](RELEASE_PYPI.md)。即使 `pip install lakun` 成功,仍需另外取得完整权重。这个自定义架构也不能直接通过 Transformers `AutoModel.from_pretrained()` 加载。源码采用 [Apache-2.0](LICENSE);权重公开前,我还需要完成上游模型/数据条款和权重许可检查。
|
|
126
|
+
|
|
127
|
+
## 我目前看到的局限
|
|
128
|
+
|
|
129
|
+
我把局限放在最后,也会在魔塔模型卡保留同样说明。LaKun 在**与训练数据接近的分布**上,对这三种类型化题目已有可用表现;我尤其觉得有明确数值线索、需要在候选项之间做简单推理的题目更容易答好,**但这只是目前试用观察,尚无独立分项测评支持**。另一方面,外部垃圾评论分类试验暴露出明显的跨领域迁移问题;第二轮训练损失下降而验证损失变差,也让我警惕过度专用化,甚至某种“微调坍塌”现象。现在还不能证明是底座能力真正坍塌,需要与未微调底座、不同检查点及人工标注域外集做对照。
|
|
130
|
+
|
|
131
|
+
因此我不会宣称它已经是通用分类器、强泛化视觉模型或可靠的数值推理模型。它目前只支持单张图片;答案位置偏斜、伪标签误差、未经校准的概率、跨域表现和来源许可,都是公开前要继续解决的问题。
|
lakun-0.1.0/START.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# LaKun 启动说明
|
|
2
|
+
|
|
3
|
+
LaKun 使用原始 mmBERT-base 文本权重、原始 SigLIP SO400M 图像权重,以及受 Laya 启发的决策评分头;不加载 Laya 微调权重。项目包名是 `lakun`。
|
|
4
|
+
|
|
5
|
+
## 放到服务器并训练
|
|
6
|
+
|
|
7
|
+
保留 `lakun/`、`train_lakun.py`、`predict_lakun.py`、`pyproject.toml`、`requirements-train.txt`、`tokenizer/`、`images/`、`dataset/` 中图文各三份 `*_train.jsonl`/`*_val.jsonl`/`*_test.jsonl`,以及 `weights/mmbert-base/` 与 `weights/siglip-so400m-patch14-384/` 中的正式权重及配置。划分按图片/文本 group ID 完成,比例约 8:1:1,同组问题不跨集合。图片路径由数据行引用,必须保留所引用图片及相对目录结构。
|
|
8
|
+
|
|
9
|
+
在项目根目录运行:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
python -c "import torch; print(torch.__version__, torch.version.cuda, torch.cuda.device_count()); assert torch.cuda.is_available()"
|
|
13
|
+
python -m pip install -r requirements-train.txt
|
|
14
|
+
python train_lakun.py --train-groups 12 --val-groups 6 --test-groups 6 --epochs 1 --out runs/lakun_pilot
|
|
15
|
+
python train_lakun.py
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
第一行确认当前 `python` 指向带 CUDA 的 PyTorch 环境,第二行安装本目录的 LaKun 包和其他依赖;如果环境中已有满足要求的 PyTorch,就不需要另行安装。第三行是小样本真权重试跑,确认显存与速度;第四行是完整训练。默认最多 3 轮,每 3000 个优化步验证一次,并在每轮结束时验证;验证损失改善至少 0.001 才更新最佳权重,连续 3 次无改善就早停。可用 `--epochs`、`--eval-every`、`--patience`、`--min-delta` 调整。训练期间不看测试集,最后只对最佳权重测一次。`train_lakun.py` 自动使用当前机器可见的全部 GPU,单卡直接运行,多卡自动使用 DDP;卡数不写死。只用部分 GPU 时设置 `CUDA_VISIBLE_DEVICES`。正式训练采用 BF16;不要把分散在不同服务器上的 GPU 当作同一台机器的多卡。
|
|
19
|
+
|
|
20
|
+
## 权重保存与下载
|
|
21
|
+
|
|
22
|
+
全量训练默认写入服务器项目目录 `runs/lakun_full/`,其中最佳完整模型权重在 `runs/lakun_full/best/`。当前设置单文件上限 10GB,正常会得到一个 `best/lakun.safetensors`;`best/` 内还含文本/图像配置、tokenizer、图像预处理器及模型卡。训练报告 `report.json` 和验证轨迹 `validation_history.json` 在上级目录。训练结束后,推理至少需要下载**整个 `runs/lakun_full/best/` 文件夹**,不要只下载某个 `.safetensors`;如需保留训练记录,再下载同级的 `report.json` 和 `validation_history.json`。小样本试跑输出在 `runs/lakun_pilot/`,不是正式模型。可以用 `--out` 指定其他输出目录。最佳检查点是包括两座编码器和决策头的完整权重,推理不再需要额外读取原始两份底座;原始底座建议留下作重新训练与复现实验。
|
|
23
|
+
|
|
24
|
+
目前保存的是最佳模型的完整推理权重,不含优化器状态;如果训练中断,最佳权重可以推理,但当前脚本不能从中断位置无损续训。重新启动默认从两份原始底座开始,务必使用新的 `--out`,避免覆盖之前的最佳权重。
|
|
25
|
+
|
|
26
|
+
载入正式检查点做一次测试:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
python predict_lakun.py --checkpoint runs/lakun_full/best --input examples/text_input.json
|
|
30
|
+
python predict_lakun.py --checkpoint runs/lakun_full/best --modality image --group-index 0
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
第一条使用仓库内的纯文本输入示例,不需要本地测试集;第二条读取本地测试集与图片。若做自己的图片推理,可在输入 JSON 中添加 `image` 路径。
|
|
34
|
+
|
|
35
|
+
在自己的代码中推理:
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
from lakun import LaKunPredictor
|
|
39
|
+
|
|
40
|
+
model = LaKunPredictor.from_pretrained("runs/lakun_full/best")
|
|
41
|
+
result = model.predict(
|
|
42
|
+
[{"type": "choice", "question": "图中是什么?", "criteria": ["猫", "狗", "汽车"]}],
|
|
43
|
+
image="/path/to/your/image.jpg",
|
|
44
|
+
)
|
|
45
|
+
print(result["answers"])
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
发布到魔塔或 Hugging Face 时,上传 `runs/lakun_full/best/` 的**全部内容**到模型仓库根目录,并让用户安装 `lakun` 代码;本项目的自定义融合层不能只靠两个原始底座权重推理。GitHub 代码仓库不含权重或数据。当前推理接口接受本地检查点目录或 Hugging Face 仓库 ID;魔塔仓库须先下载到本地目录再加载。Laya 派生源码位于 `lakun/vendor/laya/`,请保留该目录的 Apache-2.0 许可证与署名。模型权重的发布许可证需另行确定,原始底座的模型卡和许可也应在发布前核对。当前测试指标基于教师伪标签,不等于人工验证效果。
|