引導非結構化回應

使用 Llama 3

Imtihan Ahmed

Machine Learning Engineer

控制模型輸出

  • ✅ 參數
  • ✅ 角色

如何精煉模型

使用 Llama 3

控制模型輸出

  • ✅ 參數
  • ✅ 角色

如何精煉模型-精煉提示

使用 Llama 3

控制模型輸出

  • ✅ 參數
  • ✅ 角色

如何精煉模型-zero-shot/few-shot 提示

使用 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 提示

  • 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

精煉 zero-shot 提示

  • 需區分任務、預期輸出與額外脈絡
  • 使用標籤的 Zero-shot 提示
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 提示

  • Few-shot 提示:使用多個範例

提示

使用 Llama 3

Few-shot 提示

  • Few-shot 提示:使用多個範例

以「aircraft model」標示重點的提示

使用 Llama 3

Few-shot 提示

  • Few-shot 提示:使用多個範例

以「passenger capacity」標示重點的提示

使用 Llama 3

Few-shot 提示

  • 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

一起來練習吧!

使用 Llama 3

Preparing Video For Download...