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
|
Download README.md from tcjszy/PatentSQL-Qwen2.5-Coder-7B: direct link, hf CLI and curl.
- Browser
- Download file 2.77 kB
-
https://huggingface.co/tcjszy/PatentSQL-Qwen2.5-Coder-7B/resolve/main/README.md
- Command line
-
hf download hf://tcjszy/PatentSQL-Qwen2.5-Coder-7B/README.md
-
curl -L -o README.md https://huggingface.co/tcjszy/PatentSQL-Qwen2.5-Coder-7B/resolve/main/README.md
2.77 kB
| 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 步全量自动化评测后补充更新。 | |