Self-Instruct构造Prompt的例子

  1. 人工构造一批Prompt做种子。(Starting with a small seed set of human-written tasks)
  2. 每次把一些种子+后来生成的Prompt,放到Input里做few-shot examples,用LLM生成更多的Prompt;(Using the LLM to generate new instructions based on the seed tasks)
  3. 过滤掉质量太差的,修正能要的;(Filtering and refining the generated instructions)
  4. 把生成的所有Prompt,输入LLM得到输出结果;(Creating input-output instances for the new instructions)
  5. Input+Output,做LLM的训练样本(Using the generated dataset to fine-tune the LLM)

第2步,LLM生成:

复制代码
import random
from transformers import AutoTokenizer, AutoModelForCausalLM

# Load a pre-trained language model
model_name = "bigcode/starcoderbase-1b"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)

# Seed tasks (simplified for demonstration)
seed_tasks = [
    "Write a function to calculate the factorial of a number.",
    "Create a class to represent a bank account.",
    "Implement a binary search algorithm."
]

def generate_instruction(prompt):
    inputs = tokenizer(prompt, return_tensors="pt")
    outputs = model.generate(**inputs, max_new_tokens=50)
    return tokenizer.decode(outputs[0], skip_special_tokens=True)

def self_instruct(num_iterations):
    generated_tasks = []
    
    for _ in range(num_iterations):
        # Sample existing tasks
        sampled_tasks = random.sample(seed_tasks + generated_tasks, min(3, len(seed_tasks) + len(generated_tasks)))
        
        # Create a prompt for generating new instructions
        prompt = "Generate a new programming task based on these examples:\n\n"
        prompt += "\n".join(sampled_tasks)
        prompt += "\n\nNew task:"
        
        # Generate a new instruction
        new_task = generate_instruction(prompt)
        
        # In practice, you would filter and refine the generated task here
        
        generated_tasks.append(new_task)
    
    return generated_tasks

# Run Self-Instruct
new_tasks = self_instruct(5)
for i, task in enumerate(new_tasks, 1):
    print(f"Task {i}: {task}")

第3步过滤:

人工定义一些规则,过滤掉太差的;(也可以用LLM来做裁判)

目的:确保质量和多样性;

  • Filter out instructions that are too short or too long
  • Filter out instructions containing keywords unsuitable for language models (e.g. "image", "graph", "file", "plot")
  • Filter out instructions starting with punctuation
  • Filter out instructions starting with non-English characters
  • Filter out instructions that have high ROUGE-L similarity (above 0.7) with any existing instruction in the task pool
相关推荐
2zcode26 分钟前
基于Matlab融合深度学习的视频电梯乘客人数检测平台研究
深度学习·matlab·音视频
xiaoxiaoxiaolll27 分钟前
多尺度建模新范式:当神经网络融入ABAQUS,复合材料仿真迎来“物理+数据“双引擎!
人工智能·深度学习·神经网络·学习
盼小辉丶1 小时前
TensorFlow深度学习实战(29)——自监督学习(Self-Supervised Learning)
深度学习·tensorflow·自监督学习
max5006005 小时前
基于深度学习的污水新冠RNA测序数据分析系统
开发语言·人工智能·python·深度学习·神经网络
max5006006 小时前
深度学习的视觉惯性里程计(VIO)算法优化实践
人工智能·深度学习·算法
坐在地上想成仙6 小时前
计算机视觉(3)深度学习模型部署平台技术选型与全栈实践指南
人工智能·深度学习
无规则ai8 小时前
动手学深度学习(pytorch版):第一章节——引言
人工智能·pytorch·深度学习·算法·机器学习
格林威8 小时前
工业相机使用 YOLOv8深度学习模型 及 OpenCV 实现目标检测简单介绍
人工智能·深度学习·数码相机·opencv·yolo·目标检测·计算机视觉
人邮异步社区9 小时前
学深度学习,有什么好的建议或推荐的书籍?
人工智能·深度学习
路人蛃11 小时前
Scikit-learn - 机器学习库初步了解
人工智能·python·深度学习·机器学习·scikit-learn·交友