引导非结构化回答

使用 Llama 3

Imtihan Ahmed

Machine Learning Engineer

控制模型输出

  • ✅ 参数
  • ✅ 角色

如何优化模型

使用 Llama 3

控制模型输出

  • ✅ 参数
  • ✅ 角色

如何优化模型 - 优化提示

使用 Llama 3

控制模型输出

  • ✅ 参数
  • ✅ 角色

如何优化模型 - 零/少样本提示

使用 Llama 3

控制模型输出

  • ✅ 参数
  • ✅ 角色

如何优化模型 - 使用 stop 词

使用 Llama 3

优化提示

  • 示例:摘要
text_choice1 = "Summarize key trends in the aviation industry from the last year, 
                focusing on fuel efficiency innovations."

text_choice2 = "Tell me about the aviation industry."
output = llm(text_choice1) # 更具体的提示更有效 print(output['choices'][0]['text'])
The aviation industry has made significant strides in fuel efficiency innovations 
over the last year, driven by the need to reduce greenhouse gas emissions and 
operating costs. Sustainable Aviation Fuels (SAFs) have emerged as a key trend...
使用 Llama 3

高效提示的组成要素

高效提示的组成要素

使用 Llama 3

高效提示的组成要素

高效提示的组成要素 - 精确性

使用 Llama 3

高效提示的组成要素

高效提示的组成要素 - 歧义

使用 Llama 3

高效提示的组成要素

高效提示的组成要素 - 关键词

使用 Llama 3

高效提示的组成要素

高效提示的组成要素 - 动作词

使用 Llama 3

高效提示的组成要素

高效提示的组成要素 - 示例

使用 Llama 3

零样本提示(Zero-shot)

  • 零样本提示:单条指令
text = "Summarize recent mergers in the airline industry."

output = llm(text) print(output['choices'][0]['text'])
Recent mergers in the airline industry include Alaska Air Group's acquisition of 
Hawaiian Airlines in 2024, with both airlines continuing to operate as separate 
brands. In 2022, Delta Air Lines purchased 20% of LATAM Airlines Group...
使用 Llama 3

优化零样本提示

  • 需明确任务、期望输出、补充上下文
  • 带标签的零样本提示
text = """
       INSTRUCTION: Write concisely and in 2-3 sentences that cover only key points.
       QUESTION: Summarize recent mergers in the airline industry.
       ANSWER:
       """
使用 Llama 3

少样本提示(Few-shot)

  • 少样本提示:提供多个示例

提示

使用 Llama 3

少样本提示(Few-shot)

  • 少样本提示:提供多个示例

突出显示"aircraft model"的提示

使用 Llama 3

少样本提示(Few-shot)

  • 少样本提示:提供多个示例

突出显示"passenger capacity"的提示

使用 Llama 3

少样本提示(Few-shot)

  • 少样本提示:提供多个示例

突出显示"fuel consumption"的提示

使用 Llama 3

少样本提示(Few-shot)

$$

output = llm(f"Continue the entries: {text}") 

print(output['choices'][0]['text'])
Aircraft Model: Airbus A350-900
Passenger Capacity: 350
Fuel Consumption: 2.39 liters per seat per 100 km
使用 Llama 3

使用 stop 词

  • 需要精炼答案
  • stop 词在指定位置结束回答
  • 示例:问答应用
text = "Which airlines operate direct flights from London to Singapore?"


output = llm(text, stop=["Q:"]) # 在 "Q:" 处截断回答
print(output['choices'][0]['text'])
You can fly direct from London to Singapore with Singapore Airlines and 
British Airways.
使用 Llama 3

Vamos praticar!

使用 Llama 3

Preparing Video For Download...