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
相关推荐
CV矿工8 小时前
VLA(Vision-Language-Action)模型在机器人领域的action 输出编码
人工智能·深度学习·机器人
0 19 小时前
260401日志
人工智能·深度学习·nlp
追风哥哥11 小时前
transformer 注意力机制解析
人工智能·深度学习·神经网络·机器学习·语言模型·chatgpt·transformer
xingyuzhisuan11 小时前
4090部署DeepSeek-V3:CPU卸载层数实测指南
运维·深度学习·gpu算力
博士僧小星11 小时前
人工智能|大模型——模型——大模型蒸馏详解(定义/原理/关键技术/落地)
人工智能·深度学习·机器学习·知识蒸馏·模型蒸馏
AI医影跨模态组学11 小时前
Cancer Lett(IF=10.1)北京大学第一医院杨尹默等团队:基于深度学习的病理组学特征可独立于CA19-9预测胰腺导管腺癌的生存与复发
人工智能·深度学习
古希腊掌管代码的神THU12 小时前
【清华代码熊】RL后训练解析|Cursor Composer 2 技术报告
人工智能·深度学习·自然语言处理·composer
AI医影跨模态组学12 小时前
Cell Rep Med(IF=10.6)北京清华长庚医院李国新&云南省肿瘤医院放射科李振辉等团队:基于TME的深度学习模型预测胃癌治疗反应
人工智能·深度学习·医学·医学影像·医学科研
这张生成的图像能检测吗13 小时前
(论文速读)基于混合学习的边缘计算物联网系统操作视觉质量检测
人工智能·深度学习·物联网·智能制造·异常检测
龙腾AI白云13 小时前
深度学习实战:Transformer模型文本翻译应用
人工智能·深度学习