Self-Instruct构造Prompt的例子

devtools/2024/10/18 20:20:59/
  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.ppmy.cn/devtools/57883.html

相关文章

C# 编程中互斥锁的使用

C# 中的互斥锁 互斥锁是 C# 中使用的同步原语,用于控制多个线程或进程对共享资源的访问。其目的是确保在任何给定时间只有一个线程或进程可以获取互斥锁,从而提供互斥。 C# 中互斥锁的优点 可以使用互斥锁 (Mutex) 并享受其带来的好处。 1. 共享资源…

ssrf结合redis未授权getshell

目录 漏洞介绍 SSRF Redis未授权 利用原理 环境搭建 利用过程 rockylinux cron计划任务反弹shell 写公钥免密登录 ubuntu 写公钥免密登录 漏洞介绍 SSRF SSRF(server side request forgrey)服务端请求伪造,因后端未过滤用户输入&…

深度学习之半监督学习:一文梳理目标检测中的半监督学习策略

什么是半监督目标检测? 传统机器学习根据训练数据集中的标注情况,有着不同的场景,主要包括:监督学习、弱监督学习、弱半监督学习、半监督学习。由于目标检测任务的特殊性,在介绍半监督目标检测方法之前,我…

cpp struct json相互转换

使用nlohmann的库 “安装” 把include下载到本地可以include的位置 demo 需要再struct和class中实现to_json()和from_json()函数。 貌似cpp20可以通过反射无需手动编写to_json()和from_json()&#xff0c;这里不做展开 #include <iostream> #include "nlohmann/…

TCP一定可靠吗

背景 公司某个服务发送TCP报文后,得到的响应是非预期数据 原因竟然是:TCP包的 payload 数据某个bit位被翻转,但是 checksum 的值一样,错误的包被分发给了上层服务 Checksum介绍 IP 头有自己的 Checksum,TCP、UDP 也有自己的 Checksum,分别校验不同部分的数据 IP 头的 …

在linux系统centos上面安装php7gmp扩展

ps:在ubuntu上面安装gmp(最简单) $ sudo apt-get install php7.0-gmp然后再php.ini添加extensionphp_gmp.so <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<…

1.Python学习笔记

一、环境配置 1.Python解释器 把程序员用编程语言编写的程序&#xff0c;翻译成计算机可以执行的机器语言 安装&#xff1a; 双击Python3.7.0-选择自定义安装【Customize installation】-勾选配置环境变量 如果没有勾选配置环境变量&#xff0c;输入python就会提示找不到命令…

什么是数据分析?数据分析如何创造企业发挥价值?

数据分析是在具体的业务场景下&#xff0c;如何借助工具&#xff0c;通过数据解决问题的思路 数据底层的四大优势 1.可反复读取和使用 2.客观 3.量化 4.机器可处理 使用数据指导业务&#xff0c;基于数据量化生产 只要是基于量化的信息提升生产力&#xff0c;就是数据分析&a…