kaggle-finetune

端到端工作流,用于使用 Kaggle 数据集对大型语言模型(LLM)进行微调。适用于从 Kaggle 下载数据、将对话或客服数据预处理为微调格式,以及与 PEFT/LoRA 训练集成,构建特定领域聊天机器人或 AI 助手。

仓库最近推送
GitHub Stars
219
Forks
38
Issues / PRs
7

安装方式

先用 Prompt 核对来源与依赖。也可下载安装包。

用 AI 助手安装

复制提示词,让助手先核对固定版本和依赖。

查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "kaggle-finetune":https://skillpi.com/zh/skills/deepskill-bbdcd391f779354f8012963bc6952f8c38d44cc6618a171e8e786dc28d0175a4。安装前核对上游来源和版本:https://github.com/TerminalSkills/skills。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。

来源与配置

github.com

配置方式待核实

请查看原始来源中的适用工具、依赖和权限要求。

安装实测待补充

端到端工作流,用于使用 Kaggle 数据集对大型语言模型(LLM)进行微调。适用于从 Kaggle 下载数据、将对话或客服数据预处理为微调格式,以及与 PEFT/LoRA 训练集成,构建特定领域聊天机器人或 AI 助手。

0 下载

介绍来源: third_party · TerminalSkills · 1.0.0 参考来源

SkillPi 解读

软件、账号及付费要求
翻译待完成,请参阅来源文档。
实测状态
未测试

文件浏览

在原站浏览文件 ↗

原始 SKILL.md

打开原文 ↗
Frontmatter
name: kaggle-finetune
description: >-
  End-to-end workflow for fine-tuning LLMs using Kaggle datasets. Use when
  downloading datasets from Kaggle for model training, preparing
  conversation/customer service data for chatbot fine-tuning, or building
  domain-specific AI assistants. Covers dataset discovery, download,
  preprocessing into chat format, and integration with PEFT/LoRA training.
license: Apache-2.0
metadata:
  author: terminal-skills
  version: 1.0.0
  category: data-ai
  tags:
    - fine-tuning
    - kaggle
    - llm
    - peft
    - lora
  use-cases:
    - Fine-tune a customer service chatbot using Kaggle conversation datasets
    - Build domain-specific AI assistants from public datasets
    - Prepare Kaggle data for LLM training with proper chat formatting
  agents:
    - claude-code
    - openai-codex
    - gemini-cli
    - cursor

Kaggle Fine-Tuning Workflow

Overview

Complete pipeline for downloading Kaggle datasets and fine-tuning LLMs. Handles dataset discovery, download via Kaggle CLI, preprocessing into HuggingFace chat format, and training with PEFT/LoRA for memory-efficient fine-tuning.

Prerequisites

pip install kaggle peft transformers accelerate bitsandbytes datasets trl

Set Kaggle API token:

export KAGGLE_API_TOKEN=KGAT_xxxxx

Instructions

Step 1: Search and download datasets

# Search for relevant datasets
kaggle datasets list -s "customer service conversation" --sort-by votes

# Download specific dataset
kaggle datasets download -d bitext/bitext-gen-ai-chatbot-customer-support-dataset -p ./data --unzip

Recommended datasets for chatbots:

Dataset Use Case
bitext/bitext-gen-ai-chatbot-customer-support-dataset Customer support
kreeshrajani/3k-conversations-dataset-for-chatbot General chat
oleksiymaliovanyy/call-center-transcripts-dataset Call center
narendrageek/mental-health-faq-for-chatbot FAQ format

Step 2: Preprocess into chat format

Convert data to HuggingFace messages format:

import pandas as pd
import json

def convert_to_chat_format(input_path, output_path, user_col, assistant_col, system_prompt=None):
    df = pd.read_csv(input_path)
    records = []

    for _, row in df.iterrows():
        messages = []
        if system_prompt:
            messages.append({"role": "system", "content": system_prompt})
        messages.append({"role": "user", "content": str(row[user_col])})
        messages.append({"role": "assistant", "content": str(row[assistant_col])})
        records.append({"messages": messages})

    with open(output_path, 'w') as f:
        for record in records:
            f.write(json.dumps(record) + '\n')

    return len(records)

# Example usage
convert_to_chat_format(
    "data/customer_support.csv", "data/train.jsonl",
    user_col="instruction", assistant_col="response",
    system_prompt="You are a helpful customer service assistant."
)

Step 3: Fine-tune with LoRA

from datasets import load_dataset
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
from peft import LoraConfig, TaskType
from trl import SFTTrainer, SFTConfig
import torch

# Model selection by VRAM: 8GB→1.5B, 16GB→7B(4-bit), 24GB→8B
model_name = "Qwen/Qwen2.5-3B-Instruct"

# 4-bit quantization for memory efficiency
bnb_config = BitsAndBytesConfig(
    load_in_4bit=True,
    bnb_4bit_quant_type="nf4",
    bnb_4bit_compute_dtype=torch.bfloat16,
)

model = AutoModelForCausalLM.from_pretrained(
    model_name, quantization_config=bnb_config, device_map="auto"
)
tokenizer = AutoTokenizer.from_pretrained(model_name)
tokenizer.pad_token = tokenizer.eos_token

lora_config = LoraConfig(
    task_type=TaskType.CAUSAL_LM, r=16, lora_alpha=32, lora_dropout=0.05,
    target_modules=["q_proj", "k_proj", "v_proj", "o_proj"],
)

dataset = load_dataset("json", data_files="data/train.jsonl", split="train")

trainer = SFTTrainer(
    model=model,
    args=SFTConfig(
        output_dir="./model-finetune", num_train_epochs=3,
        per_device_train_batch_size=2, gradient_accumulation_steps=8,
        learning_rate=2e-4, fp16=True, max_seq_length=512,
    ),
    train_dataset=dataset,
    peft_config=lora_config,
    tokenizer=tokenizer,
)
trainer.train()
trainer.save_model("./model-lora")

Step 4: Test and deploy

from peft import PeftModel

model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto")
model = PeftModel.from_pretrained(model, "./model-lora")

messages = [{"role": "user", "content": "How can I reset my password?"}]
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(text, return_tensors="pt").to(model.device)
outputs = model.generate(**inputs, max_new_tokens=100)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))

Examples

Example 1: Fine-tune a customer service chatbot from a Kaggle dataset

User prompt: "Download the Bitext customer support dataset from Kaggle and fine-tune Qwen2.5-3B-Instruct on it using LoRA. I have a 16GB GPU."

The agent will:

  1. Verify the Kaggle CLI is installed and KAGGLE_API_TOKEN is set.
  2. Run kaggle datasets download -d bitext/bitext-gen-ai-chatbot-customer-support-dataset -p ./data --unzip to fetch the dataset.
  3. Inspect the CSV columns to identify the user input and assistant response fields.
  4. Write and execute a preprocessing script that converts the CSV into JSONL chat format with a system prompt like "You are a helpful customer service assistant."
  5. Configure a LoRA fine-tune with r=16, 4-bit quantization, batch size 2 with gradient accumulation of 8, and train for 3 epochs.
  6. Save the LoRA adapter to ./model-lora/ and run a test inference with a sample prompt like "How do I reset my password?"

Example 2: Build a medical FAQ chatbot from Kaggle mental health data

User prompt: "Find a mental health FAQ dataset on Kaggle and prepare it for fine-tuning. I only have a CPU, so pick a small model."

The agent will:

  1. Search Kaggle with kaggle datasets list -s "mental health FAQ" --sort-by votes and select an appropriate dataset.
  2. Download and unzip the dataset to ./data/.
  3. Convert the FAQ pairs into JSONL chat format with a system prompt suited to mental health support.
  4. Select Qwen2.5-1.5B-Instruct as a CPU-friendly model and configure training with load_in_4bit=True, batch size 1, gradient accumulation 16, and max_seq_length=256 to fit in memory.
  5. Start training and monitor loss, noting it will take several hours on CPU.

Guidelines

  • Always verify the Kaggle API token is set as KAGGLE_API_TOKEN before attempting downloads; the CLI will fail silently or with cryptic errors without it.
  • Choose your base model based on available VRAM: 1.5B parameters for 8GB, 3B-7B (4-bit) for 16GB, and 8B for 24GB.
  • If you encounter out-of-memory errors during training, reduce per_device_train_batch_size to 1 and increase gradient_accumulation_steps to compensate before reducing model size.
  • Inspect the raw CSV data before preprocessing to verify column names and data quality; missing values or mismatched columns will silently produce poor training data.
  • Start with 3 training epochs and LoRA rank r=16; increase epochs to 5 and rank to 32-64 only if evaluation shows the model is underfitting.
  • Enable fp16=True (or bf16=True on Ampere+ GPUs) to halve memory usage and speed up training with minimal accuracy impact.

当前收录版本

1.0.0

核对来源版本 ↗

质量评测

满分100 · 来自 SkillPi LAB 实验室的评测报告。

场景价值92/100

亮点

  • 提供端到端 Kaggle 数据集下载、预处理、LoRA 微调完整流程
  • 适用于客服机器人、领域 AI 助手等明确场景,具备高频刚需价值
  • 包含具体模型选择建议(按 VRAM 分级)和参数配置
触发精准95/100

亮点

  • 触发词精准覆盖 'Kaggle 数据集下载'、'对话数据预处理'、'LoRA 微调' 等核心场景
  • 边界清晰,不易与其他 Skill 重叠
结构规范90/100

亮点

  • Phase 清晰(Step 1-4),每步有具体命令和代码示例
  • 包含两个端到端示例(客服机器人、医疗 FAQ),frontmatter 完整
执行可靠85/100

待提升项

  • Kaggle API token 错误处理未显式捕获 原报告严重程度:轻微

    文档提醒需设置 KAGGLE_API_TOKEN,但未在脚本中显式检查该环境变量是否存在,可能导致用户困惑

    改进建议:在预处理脚本开头添加环境变量检查,若缺失则抛出明确错误提示

亮点

  • 工具来源明确(kaggle CLI, PEFT, transformers 等),参数配置合理
  • 覆盖主要异常场景(VRAM 不足、OOM 错误)并提供降级方案
证据可验 (前四项均值)91/100

取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。

正文静态检测

100 / 100 · skillpi-20261123-no-r3-v1

正文未命中当前规则。

分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。

权限与使用前检查

根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。

  • 保存或修改文件

    先确认输出目录和同名文件是否会被覆盖;重要文件保留备份,优先写入新的输出目录。

    主文档提及 · 第 89 行
  • 安装或获取外部依赖

    使用官方来源并锁定版本,在隔离环境检查安装脚本。当前文档检查不覆盖后续下载的代码。

    主文档提及 · 第 40 行

本站展示提示不会授予权限。涉及文件改动、密钥、外部发送或费用时,仍由你使用的工具按需确认。

安全评级与访问范围

safe · 静态证据核验,不代表运行安全保证。

翻译待完成,请参阅来源文档。

使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。