提示工程优化方法之一 zero shot

Table of Contents

Zero-Shot

Zero shot学习,也称为零样本学习(Zero-Shot Learning,简称ZSL),是一种机器学习范式,它允许模型在训练阶段从未见过的类别上进行预测和分类。这种学习方式特别适用于那些难以获取大量标注数据的领域,或者在面对罕见或未知类别时的场景。

在Zero shot学习中,模型通常会使用辅助信息,如类别的文本描述、属性或嵌入表示等,来理解在训练阶段未出现过的类别。这些辅助信息帮助模型建立起类别之间的语义联系,从而在没有直接样本的情况下也能进行有效的预测。

Use Emotional Language 使用情感语言

Assign a Role 分配角色

Define a Style 定义风格

#!/usr/bin/env python3
from pydantic import BaseModel
import simple_llm_agent

class Email(BaseModel):
    subject: str
    message: str

client = simple_llm_agent.LlmAgent()

def generate_email(subject, to, sender, tone):
    system_prompt = "You are a smart sesecretary"
    user_prompt = f"""
        Write an email about {subject} to {to} from {sender}.
        The email should be {tone}.
    """
    return client.get_object_response(system_prompt, user_prompt, Email )

if __name__ == "__main__":
    email = generate_email(
        subject="invitation to all-hands on Monday at 6pm",
        to="All",
        sender="Walter Fan",
        tone="formal",
    )

    print(email.subject)
    #> Invitation to All-Hands Meeting
    print(email.message)

Auto-Refine The Prompt 自动优化提示

Simulate a Perspective 模拟一个视角

Clarify Ambiguous Information 澄清模糊信息

Ask Model To Repeat Query 要求模型重复查询

Generate Follow-Up Questions 提出后续问题

Comments |0|

Legend *) Required fields are marked
**) You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>
Category: 似水流年