Text Generation
Safetensors
Chinese
English
qwen2
text-to-sql
mysql
elasticsearch
es-dsl
patent
chinese
agent
qwen2.5-coder
unsloth
lora
conversational
Instructions to use tcjszy/PatentSQL-Qwen2.5-Coder-7B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Local Apps Settings
- Unsloth Desktop
File size: 2,772 Bytes
a7b8380 ad00767 a7b8380 ad00767 a7b8380 ad00767 a7b8380 ad00767 a7b8380 ad00767 a7b8380 ad00767 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | ---
language:
- zh
- en
license: apache-2.0
base_model: Qwen/Qwen2.5-Coder-7B-Instruct
tags:
- text-to-sql
- mysql
- elasticsearch
- es-dsl
- patent
- chinese
- agent
- qwen2.5-coder
- unsloth
- lora
datasets:
- tcjszy/cn-patent-text2sql-es-dataset
pipeline_tag: text-generation
---
# PatentSQL-Qwen2.5-Coder-7B — 中文专利 MySQL + Elasticsearch 双引擎查数专精模型
面向企业级专利数据检索与统计场景的私有化部署 7B 专精小模型,基于 `Qwen/Qwen2.5-Coder-7B-Instruct` 使用 **Unsloth + QLoRA + Response-Only Loss Masking** 微调而成。
## 核心特性
1. **双引擎支持**:同时支持 **MySQL 8.0 Text-to-SQL**(多表 JOIN、枚举黑话解码、窗口函数、授权率/有效率计算)与 **Elasticsearch 8.x Query DSL**(`multi_match` 权重全文搜索、`bool` 排除、`terms`/`date_histogram` 分面聚合)。
2. **可解释 `<think>` 推理链**:先输出中文业务口径拆解与字段定位思路,再输出标准可执行 SQL/JSON 代码块。
3. **内置报错自修复(Self-Correction)能力**:训练集中专门注入了 MySQL 报错修复样本,适配 Agent 的 `try-catch` 自动重试流水线。
4. **保留跨库泛化能力**:混入非专利通用中文业务库训练,在未见过的新库 DDL 上依然稳定可用。
5. **私有化低成本部署**:同步提供 [GGUF 量化版](https://huggingface.co/tcjszy/PatentSQL-Qwen2.5-Coder-7B-GGUF),消费级单卡或个人电脑通过 Ollama 即可运行。
## 快速开始
### 1) Ollama 一行命令运行(推荐)
```bash
ollama run hf.co/tcjszy/PatentSQL-Qwen2.5-Coder-7B-GGUF:Q4_K_M
```
### 2) Transformers Python 推理
```python
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
model_id = "tcjszy/PatentSQL-Qwen2.5-Coder-7B"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.bfloat16, device_map="auto")
messages = [
{"role": "system", "content": "你是一位精通 MySQL 8.0 与中国专利业务的数据查询专家..."},
{"role": "user", "content": "统计广东省目前有多少件有效发明专利"},
]
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer([text], return_tensors="pt").to(model.device)
out = model.generate(**inputs, max_new_tokens=512, do_sample=False)
print(tokenizer.decode(out[0][inputs.input_ids.shape[1]:], skip_special_tokens=True))
```
## 训练与评测数据
- 开源数据集:[tcjszy/cn-patent-text2sql-es-dataset](https://huggingface.co/datasets/tcjszy/cn-patent-text2sql-es-dataset)
- 评测对比表(Base vs SFT vs SFT + Agent Self-Correction):将在第 5 步全量自动化评测后补充更新。
|