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

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 taskssampled_tasks = random.sample(seed_tasks + generated_tasks, min(3, len(seed_tasks) + len(generated_tasks)))# Create a prompt for generating new instructionsprompt = "Generate a new programming task based on these examples:\n\n"prompt += "\n".join(sampled_tasks)prompt += "\n\nNew task:"# Generate a new instructionnew_task = generate_instruction(prompt)# In practice, you would filter and refine the generated task heregenerated_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
http://www.lryc.cn/news/394000.html

相关文章:

  • 友好前端vue脚手架
  • SQL Server特性
  • 华为HCIP Datacom H12-821 卷25
  • 如何在 Selenium Python 中解决验证码 | 2024 完整指南
  • ASCII码对照表【2024年汇总】
  • 刷题之买股票的最佳时机(leetcode)
  • Apache Seata透过源码解决SeataAT模式整合Mybatis-Plus失去MP特性的问题
  • 1.2 如何让机器说人话?万字长文回顾自然语言处理(NLP)的前世今生 —— 《带你自学大语言模型》系列
  • 【QT】按钮类控件
  • RedHat运维-Linux软件包管理基础-RHEL9软件包管理基础
  • uniapp----- 判断小程序版本有没有更新
  • Spring Boot的无缝衔接:深入解析与实践
  • 在Linux上查找文件的2个好用的命令
  • 实现WebSocket聊天室功能
  • qt opencv 应用举例
  • QT5.12环境搭建与源码编译
  • Android中android.fg线程和android.ui线程分别代表什么?
  • MATLAB 2024b 更新了些什么?
  • SSM高校教师教学质量评估系统-计算机毕业设计源码03344
  • 【Linux进阶】文件系统5——ext2文件系统(inode)
  • 华为云简介
  • Doris数据库---建表、调整表结构操作
  • 《昇思 25 天学习打卡营第 11 天 | ResNet50 图像分类 》
  • 实现多数相加,但是传的参不固定
  • Windows环境安装Redis和Redis Desktop Manager图文详解教程
  • SQL Server 2022的组成
  • 【大语言模型系列之Transformer】
  • 操作系统-懒汉式单例模式
  • 设计模式探索:策略模式
  • 提升效能:Symfony 性能优化实用指南