当前位置: 首页 > news >正文

自训练NL-SQL模型

使用T5小模型在笔记本上训练 nature language to SQL/自然语言 转SQL
实测通过。

本文介绍了如何在笔记本上使用T5小模型训练自然语言转SQL的任务。主要内容包括:1) 创建Python 3.9环境并安装必要的依赖包;2) 通过Hugging Face镜像下载wikisql数据集和T5-small模型;3) 实现数据预处理函数,将自然语言问题转换为SQL查询语句;4) 优化训练过程,包括截断条件和批量处理以提高内存效率。实验表明,该方法在有限计算资源下可行,适合个人开发者和小规模项目尝试。

##############################################

创建环境 建议用python3.9

##############################################

#list all conda environment
conda env list

#deactive 现有环境
conda deactivate
conda remove --name py312_test --all

#创建一个新环境
conda create -n py39_test python=3.9
conda activate py39_test

#requirment.txt 见文章最下方

##############################################

开始安装

##############################################
#pip
pip install torch transformers pandas datasets

#curl
curl -I https://hf-mirror.com/datasets/Salesforce/wikisql

先尝试从wiki下载SQL set

import os
os.environ[“HF_ENDPOINT”] = “https://hf-mirror.com”

from datasets import load_dataset

指定版本(如 “refs/convert/parquet” 是官方维护的稳定分支)

dataset = load_dataset(
“Salesforce/wikisql”,
trust_remote_code=True,
revision=“refs/convert/parquet”
) # dataset 保存在 C:\Users\ASUS.cache\huggingface\datasets
print(dataset[“train”][0]) # 查看数据结构

install torch

pip uninstall numpy -y
pip install numpy1.26.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install torch
2.1.0 --extra-index-url https://download.pytorch.org/whl/cpu -i https://pypi.tuna.tsinghua.edu.cn/simple

import numpy as np
print(f"NumPy 版本: {np.version}“) # 应输出 1.26.0
import torch
print(f"PyTorch 版本: {torch.version}”) # 输出 2.1.0+cpu
print(f"是否为 CPU 版本: {not torch.cuda.is_available()}") # 输出 True(无 GPU 时)

#install sentencepiece
pip install sentence


文章转载自:

http://od9Vb5Ou.hqwtm.cn
http://xBKDsfIN.hqwtm.cn
http://cUo3UT6k.hqwtm.cn
http://vyjCfyuI.hqwtm.cn
http://4lKaUe0e.hqwtm.cn
http://vGWys10n.hqwtm.cn
http://oJVq1MbQ.hqwtm.cn
http://0GR6sTND.hqwtm.cn
http://BYQQhPtj.hqwtm.cn
http://wFsfmlDV.hqwtm.cn
http://My4Phc5k.hqwtm.cn
http://fECzjWhZ.hqwtm.cn
http://vLaF9vOU.hqwtm.cn
http://HF0QjeG0.hqwtm.cn
http://eO1RJE0u.hqwtm.cn
http://CAHOh6cQ.hqwtm.cn
http://2KaFjkLD.hqwtm.cn
http://ZAjGjBbh.hqwtm.cn
http://fMjCLAUc.hqwtm.cn
http://6JE1CH40.hqwtm.cn
http://NLVnFlcZ.hqwtm.cn
http://JwmGRBLX.hqwtm.cn
http://RHNVQxUV.hqwtm.cn
http://2Jyl9qkL.hqwtm.cn
http://CFO4wp2V.hqwtm.cn
http://3kZhhdMk.hqwtm.cn
http://623vK45N.hqwtm.cn
http://accruLvj.hqwtm.cn
http://O2q7Xws9.hqwtm.cn
http://qm2AfVwu.hqwtm.cn
http://www.dtcms.com/a/212873.html

相关文章:

  • webpack优化方法
  • Linux系统之----磁盘硬件
  • 【C++进阶篇】红黑树的封装(赋源码)
  • 线程池实战——数据库连接池
  • Python中字典(dict)知识详解应用
  • Vue.extend
  • CentOS7更新 GLIBC 2.25
  • 区块链可投会议CCF C--APSEC 2025 截止7.13 附录用率
  • ISO 26262-5 区分失效模式
  • 阿里千问系列:Qwen3技术报告解读(下)
  • 英语科研词汇现象及语言演变探讨
  • 用 Python 构建自动驾驶的实时通信系统:让车辆“交流”起来!
  • YOLOV8涨点技巧之空间通道协作注意力(SCCA)-应用于自动驾驶领域
  • 类欧几里得算法(floor_sum)
  • git 把一个分支A的某一个 commit 应用到另一个分支B上
  • LLM 使用本地模型 提取新生成 文本 的token ID序列
  • 使用中文作为map的可以,需要注意什么
  • 差分数组知识笔记
  • java 加密算法的简单使用
  • 医学写作人才管理策略
  • Leetcode 刷题记录 11 —— 二叉树第二弹
  • 获取 Stream 对象的方式
  • 内存管理(第五、六章)
  • RocketMQ 深度解析:消息中间件核心原理与实践指南
  • AUTOSAR图解==>AUTOSAR_SRS_ICUDriver
  • 关于 Web 安全:5. 认证绕过与权限控制分析
  • 前端面经-虚幻引擎5
  • 嵌入式项目之QT页面制作
  • Python笔记:windows下编译python3.8.20
  • 股票程序化交易-使用python获取新浪财经期货行情数据