标题: Building Systems with the ChatGPT API [打印本页] 作者: 罪恶克星 时间: 2024-6-22 15:06 标题: Building Systems with the ChatGPT API 目录
提问范式与token
评估输入--分类
检查输入--审核
审核
Prompt注入
使用适当的分隔符
进行监视分类
处置惩罚输入--思维链推理
思维链提示计划
内心独白
处置惩罚输入--链式
提取产品和种别
检索具体信息
生成查询答案
检查结果
搭建一个带评估的端到端问答体系 提问范式与token
token
LLM 现实上并不是重复预测下一个单词,而是重复预测下一个 token 。对于一个句子,语言模型会先使用分词器将其拆分为一个个 token ,而不是原始的单词。对于生僻词,大概会拆分为多个 token 。这样可以大幅降低字典规模,提高模型训练和推断的效率。比方,对于 "Learning new things is fun!" 这句话,每个单词都被转换为一个 token ,而对于较少使用的单词,如 "rompting as powerful developer tool",单词 "prompting" 会被拆分为三个 token,即"prom"、"pt"和"ing"。
# 为了更好展示效果,这里就没有翻译成中文的 Prompt
# 注意这里的字母翻转出现了错误,吴恩达老师正是通过这个例子来解释 token 的计算方式
response = get_completion("Take the letters in lollipop \
and reverse them")
print(response) # "lollipop" 反过来应该是 "popillol"
"""
The reversed letters of "lollipop" are "pillipol".
"""
复制代码
这时可以通过在字母间添加分隔,让每个字母成为一个token,以资助模型准确理解词中的字母顺序
response = get_completion("""Take the letters in \
'category': <包括以下几个类别:Computers and Laptops、Smartphones and Accessories、Televisions and Home Theater Systems、Gaming Consoles and Accessories、Audio Equipment、Cameras and Camcorders>,
以及
'products': <必须是下面的允许产品列表中找到的产品列表>
类别和产品必须在客户服务查询中找到。
如果提到了某个产品,它必须与允许产品列表中的正确类别关联。
如果未找到任何产品或类别,则输出一个空列表。
除了列表外,不要输出其他任何信息!
允许的产品:
Computers and Laptops category:
TechPro Ultrabook
BlueWave Gaming Laptop
PowerLite Convertible
TechPro Desktop
BlueWave Chromebook
Smartphones and Accessories category:
SmartX ProPhone
MobiTech PowerCase
SmartX MiniPhone
MobiTech Wireless Charger
SmartX EarBuds
Televisions and Home Theater Systems category:
CineView 4K TV
SoundMax Home Theater
CineView 8K TV
SoundMax Soundbar
CineView OLED TV
Gaming Consoles and Accessories category:
GameSphere X
ProGamer Controller
GameSphere Y
ProGamer Racing Wheel
GameSphere VR Headset
Audio Equipment category:
AudioPhonic Noise-Canceling Headphones
WaveSound Bluetooth Speaker
AudioPhonic True Wireless Earbuds
WaveSound Soundbar
AudioPhonic Turntable
Cameras and Camcorders category:
FotoSnap DSLR Camera
ActionCam 4K
FotoSnap Mirrorless Camera
ZoomMaster Camcorder
FotoSnap Instant Camera
只输出对象列表,不包含其他内容。
"""
user_message_1 = f"""
请告诉我关于 smartx pro phone 和 the fotosnap camera 的信息。