產生新內容

Claude 模型入門

Nikhil Rangarajan

Data Scientist

創意內容產生

  • 超越文字轉換,進入原創
    • 故事

一本攤開的書

Claude 模型入門

創意內容產生

  • 超越文字轉換,進入原創
    • 故事
    • 行銷文案

一本攤開的書與一個顯示行銷文案的網頁

Claude 模型入門

創意內容產生

  • 超越文字轉換,進入原創
    • 故事
    • 行銷文案
    • 程式碼

一本攤開的書、一個顯示行銷文案的網頁與一段程式碼

Claude 模型入門

創意內容產生

  • 超越文字轉換,進入原創
    • 故事
    • 行銷文案
    • 程式碼
    • 電子郵件

一本攤開的書、一個顯示行銷文案的網頁、一段程式碼與一封電子郵件

Claude 模型入門

創意內容產生

  • 超越文字轉換,進入原創
    • 故事
    • 行銷文案
    • 程式碼
    • 電子郵件
    • 腳本

一本攤開的書、一個顯示行銷文案的網頁、一段程式碼、一封電子郵件與一份腳本

Claude 模型入門

撰寫有效的生成提示

$$

  • 具體度
  • 含糊提示:產出通用
  • 明確提示:內容精準
# Vague prompt
prompt = "Write a product description"

# Specific prompt prompt = """Write a 150-word product description for a wireless bluetooth speaker targeting college students. Use an energetic, casual tone and highlight portability, battery life, and sound quality."""
Claude 模型入門

撰寫有效的生成提示

$$

  • 最常見的 Claude 用途:程式碼
  • 具體提示可導向精準程式輸出
    • 程式語言
    • 特定功能
    • 錯誤處理需求
    • 預期輸出
# Vague prompt
prompt = "Write some code"

# Specific prompt  
prompt = """Write a Python function 
that validates email addresses 
using regex. 
Include error handling for invalid 
inputs and return both boolean result 
and descriptive error message."""
Claude 模型入門

理解 temperature

  • Temperature 範圍:0.0(確定性)到 1.0(高創意)
    • 低溫(0.1–0.3):輸出一致、可預測
    • 中溫(0.4–0.7):創意與連貫兼顧
    • 高溫(0.8–1.0):創意最高、較難預測

從 0 到 1 的溫度刻度

Claude 模型入門

模型呼叫中的 temperature

# Conservative generation
response1 = client.messages.create(
    model="claude-sonnet-4-6",
    temperature=0.2,
    messages=[{"role": "user", "content": prompt}])

# Creative generation response2 = client.messages.create( temperature=0.8, messages=[{"role": "user", "content": prompt}])
print("Temperature 0.2 Response (Conservative)") print(response1.content[0].text)
print("Temperature 0.8 Response (Creative)") print(response2.content[0].text)
Claude 模型入門

模型呼叫中的 temperature

Temperature 0.2 Response (Conservative)
A rainbow is an optical phenomenon that occurs when sunlight and rain are present 
simultaneously. It forms when white light from the sun passes through water 
droplets in the atmosphere, causing the light to refract, reflect, and disperse 
into its component colors...

Temperature 0.8 Response (Creative)
Ah, rainbows! Those magical bridges painted across stormy skies that never fail 
to make us pause and wonder. Picture this: millions of tiny water droplets hanging 
in the air after a rainfall, each one acting like a miniature crystal ball. When 
sunlight hits these droplets, something absolutely enchanting happens...
Claude 模型入門

使用 top_p 參數

$$

  • top_p(核心取樣):控制創意的 temperature 替代方案
  • 常見值:0.1(聚焦)到 0.9(多樣)
  • 合併使用:可同時用 temperature 與 top_p 精細控制

$$

client.messages.create(
model="claude-sonnet-4-6",
temperature=0.7,
top_p=0.3, #Likely words
messages=[{"role":"user", 
           "content":prompt}])
Claude 模型入門

Claude 的安全機制

$$

  • 📝 內容強項:寫作、分析、寫程式、創意任務
  • 🚫 內建安全:拒絕有害內容,遵循倫理規範
  • ✅ 最佳做法:提示清楚、嘗試參數、檢閱輸出
Claude 模型入門

一起來練習吧!

Claude 模型入門

Preparing Video For Download...