生成新内容

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 范围:0.0(确定性)到 1.0(高度创意)
    • 低温度(0.1-0.3):输出一致、可预测
    • 中温度(0.4-0.7):创意与连贯平衡
    • 高温度(0.8-1.0):创意最大、可预测性下降

从 0 到 1 的温度范围

Claude 模型入门

模型调用中的温度参数

# 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 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(核采样):控制创意度的温度替代方案
  • 常用取值:0.1(更聚焦)到 0.9(更多样)
  • 组合使用:与 temperature 搭配精细控制

$$

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...