8.0
热点
AI SCORE
技术实践2026-08-11 03:51
QLoRA 微调用于 JSON 结构化提取实战
dev.to · AI#QLoRA#微调#LLM
Editor brief · 编辑速览
在 Qwen2.5-1.5B-Instruct 模型上分别用 4/8/16 比特量化训练,评估 Exact Match 和 Field Match 指标,为需要私有化部署结构化数据提取能力的团队提供量化精度参考。
我们需要从一个领域特定的非结构化文本中提取结构化的 JSON。决定分别用 4-bit、8-bit 和 16-bit 三种量化级别对 Qwen2.5-1.5B-Instruct 模型进行训练。
数据集总样本数:约 280
训练 使用 QLoRA 微调
我们按每个数据集分割测量两个分数:
Exact Match(精确匹配):每样本二元分数(所有字段完全匹配为 1,否则为 0)。在分割数据集上汇总。
Field Match(字段匹配):每样本的部分得分(正确字段数 / 总字段数)。在分割数据集上汇总。
标准 JSON
{
"first_name": "Jordan",
"last_name": "Kaur",
"employment_type": "contractor",
"employer_name": "Grounded Movement",
"employer_email": "payroll@goat.com",
"employer_address_line_1": "41 King Street",
"employer_address_line_2": "Madison, UK",
"employer_registration_number": null,
"employer_tax_number": null,
"currency": "USD",
"pay_rate": 45.0,
"pay_rate_basis": "per_shift",
"incentive_pay": 5.0,
"incentive_type": "per_reservation_over_n",
"n": 15,
"reservation_types": [
"check_ins"
],
"exclude_staff_reservations": true,
"exclude_cancelled_shifts": true,
"max_pay": null,
"payment_frequency": "weekly"
}
预测 JSON(模型输出)
{
"first_name": "Jordan",
"last_name": "Kaur",
"employment_type": "contractor",
>>"employer_name": "Grounded",<<
"employer_email": "payroll@goat.com",
"employer_address_line_1": "41 King Street",
"employer_address_line_2": "Madison, UK",
"employer_registration_number": null,
"employer_tax_number": null,
"currency": "USD",
"pay_rate": 45.0,
>>"pay_rate_basis": null,<<
"incentive_pay": 5.0,
"incentive_type": "per_reservation_over_n",
"n": 15,
"reservation_types": [
"check_ins"
],
"exclude_staff_reservations": true,
"exclude_cancelled_shifts": true,
"max_pay": null,
"payment_frequency": "weekly"
}
Mismatch 1: "employer_name": "Grounded" (Predicted) vs "Grounded Movement" (Gold)
Mismatch 2: "pay_rate_basis": null (Predicted) vs "per_shift" (Gold)
Total Fields = 20
Correct Fields = 18
Wrong Fields = 2
Exact Match
Score: 0/1
Field Level Match
Score: 18/20 = 0.9 (90%)
虽然我们用 4-bit、8-bit 和 16-bit QLoRA 进行了实验,但为简洁起见,低位数的实验结果在此省略。
-------------------------------------------------------------------
Model Exact Accuracy Field Match
-------------------------------------------------------------------
Baseline 0.00 0.54
Fine‑tuned 0.62 0.97

微调后字段匹配从约 54% 提升至约 97%。精确匹配虽然较低(62%),但从 0% 实现了零的突破。
字段级结果表明,adapter 成功学习到了大多数字段的正确键值映射。