小模型,大用途!用于结构化输出的小型语言模型
01.引言
小型语言模型(SLM)通常被用于端侧推理,搜索推荐query改写这类对于资源要求低,大规模并发时延要求高的场景。
Osmosis-Structure-0.6B
探索了新的场景,基于Qwen3-0.6B,专门设计了一个用于生成结构化输出的小型语言模型(SLM)。尽管其参数规模仅为0.6B,在该模型在于支持框架配合使用时,在提取结构化信息方面表现出色。
该模型的训练方法为在训练的过程中利用结构化输出,迫使模型仅关注推理引擎声明的每个键的值,显著提升了模型在各种领域(尤其是数学推理和复杂问题解决中)生成良好的,结构化回复的能力。
https://live.csdn.net/v/483284
02.模型效果
研究团队评估了 osmosis 增强的结构化生成在具有挑战性的数学推理基准测试中的有效性。以下结果展示了通过 osmosis 增强的结构化输出在不同模型家族中实现的显著性能提升 Osmosis-Structure-0.6B
。
Math DAPO 17K 数据集
模型 |
结构化输出 |
结构化 w/ Osmosis |
性能提升 |
Claude 4 Sonnet |
15.52% |
69.40% |
+347% |
Claude 4 Opus |
15.28% |
69.91% |
+357% |
GPT-4.1 |
10.53% |
70.03% |
+565% |
OpenAI o3 |
91.14% |
94.05% |
+2.9% |
表 1: 在 Math DAPO 17K 上的表现
AIME 1983-2024 数据集
模型 |
结构化输出 |
结构化 w/ Osmosis |
性能提升 |
Claude 4 Sonnet |
16.29% |
62.59% |
+284% |
Claude 4 Opus |
22.94% |
65.06% |
+184% |
GPT-4.1 |
2.79% |
39.66% |
+1322% |
OpenAI o3 |
92.05% |
93.24% |
+1.3% |
表 2: 在 AIME 1983-2024 上的表现
这些评估表明,thinking模式下的模型,会提升模型的效果,而且我们使用SLM,可以保持thinking模型的输出转化为标准的结构化。
03.模型训练
Osmosis-Structure-0.6B
是基于 Qwen3-0.6B
构建的。开发团队首先使用随机生成文本及其 JSON 解释的 10 个样本来建立基线格式。然后,我们将强化学习应用于大约 500,000 个 JSON 到自然语言对的例子,这些例子包括带有最终输出的推理轨迹或带有预期结构化格式的自然语言输出。
开发团队使用了 verl(https://github.com/volcengine/verl) 作为训练模型的框架,并使用 SGLang(https://github.com/sgl-project/sglang) 作为 rollout 后端。为了实现结构化训练,修改了 verl 代码库的部分内容,以便将 每个样本的 schema 传递到训练数据中。
模型链接:
https://modelscope.cn/models/osmosis-ai/Osmosis-Structure-0.6B
04.使用方式
从魔搭社区下载模型:
modelscope download osmosis-ai/Osmosis-Structure-0.6B --local_dir ./Osmosis-Structure-0.6B
推荐使用像 SGLang 这样的引擎来服务模型。要启动服务,请运行以下命令:
import json
from openai import OpenAI
api_key = "osmosis"
api_base_url = "http://0.0.0.0:30000/v1"
client = OpenAI(
api_key=api_key,
base_url=api_base_url,
)
# Schema for extracting structured output from reasoning traces
json_schema = json.dumps(
{
"type": "object",
"properties": {
"answer": {"type": "string"}
},
"required": ["answer"]
}
)
# You can also dump pydantic models to json schema as well
# Example reasoning trace input
reasoning_trace = """
Problem: Solve for x in the equation 2x + 5 = 13
Let me work through this step by step:
First, I need to isolate the term with x. I'll subtract 5 from both sides:
2x + 5 - 5 = 13 - 5
2x = 8
Next, I'll divide both sides by 2 to solve for x:
2x ÷ 2 = 8 ÷ 2
x = 4
Let me verify this answer by substituting back into the original equation:
2(4) + 5 = 8 + 5 = 13 ✓
Ok, which means I got the correct answer, and I'm confident about my answer.
"""
response = client.chat.completions.create(
model="osmosis-ai/Osmosis-Structure-0.6B",
messages=[
{
"role": "system",
"content": f"You are a helpful assistant that understands and translates text to JSON format according to the following schema. {json_schema}"
},
{
"role": "user",
"content": reasoning_trace,
},
],
temperature=0,
max_tokens=512,
response_format={
"type": "json_schema",
"json_schema": {"name": "reasoning_extraction", "schema": json.loads(json_schema)},
},
)
print(json.dumps(response.choices[0].message.content, indent=2))
Ollama
ollama运行
ollama run modelscope.cn/osmosis-ai/Osmosis-Structure-0.6B
注:ollama直接推理,不设置system prompt,结构化输出不稳定,也会有非常精简的输出。
或者使用ollama的推理代码
from ollama import chat
from modelscope import snapshot_download
from pydantic import BaseModel
class Answer(BaseModel):
answer: int
reasoning_trace = """
Problem: Solve for x in the equation 2x + 5 = 13
Let me work through this step by step:
First, I need to isolate the term with x. I'll subtract 5 from both sides:
2x + 5 - 5 = 13 - 5
2x = 8
Next, I'll divide both sides by 2 to solve for x:
2x ÷ 2 = 8 ÷ 2
x = 4
Let me verify this answer by substituting back into the original equation:
2(4) + 5 = 8 + 5 = 13 ✓
Ok, which means I got the correct answer, and I'm confident about my answer.
"""
response = chat(
messages=[
{
"role": "system",
"content": f"You are a helpful assistant that understands and translates text to JSON format according to the following schema. {Answer.model_json_schema()}"
},
{
'role': 'user',
'content': reasoning_trace,
}
],
model=snapshot_download("osmosis-ai/Osmosis-Structure-0.6B"),
format=Answer.model_json_schema(),
)
answer = Answer.model_validate_json(response.message.content)
print(answer)
点击 链接,即可跳转链接~
https://modelscope.cn/models/osmosis-ai/Osmosis-Structure-0.6B
更多推荐
所有评论(0)