承接上篇,继续整理关于面向开发者的Prompt Engineering教程笔记,教程之前的部分见:如何使用ChatGPT得到更满意的结果:Prompt Engineering (2)_Dorothy30的博客-CSDN博客
如何使用ChatGPT得到更满意的结果(3):面向开发者的ChatGPT Prompt Engineering (迭代式Prompt开发)_Dorothy30的博客-CSDN博客
如何使用ChatGPT得到更满意的结果(4):面向开发者的ChatGPT Prompt Engineering (Summarizing)_Dorothy30的博客-CSDN博客
如何使用ChatGPT得到更满意的结果(5):面向开发者的ChatGPT Prompt Engineering (Inferring)_Dorothy30的博客-CSDN博客
整理的内容基本上英文原文都来自于教程,有需要的朋友可以直接戳https://learn.deeplearning.ai/。这篇笔记主要整理教程中的Transforming部分。我们将探索如何使用大型语言模型进行文本转换任务,比如语言翻译、语气调整,格式转换以及拼写/语法检查。
ChatGPT经过多种语言的训练,因此该模型具备良好翻译的能力。以下是使用这一功能的示例。
prompt = f"""
Translate the following English text to Spanish: \
```Hi, I would like to order a blender```
"""
response = get_completion(prompt)
print(response)
写作可以根据预期受众而有所不同。ChatGPT也可以根据你的需求进行不同的语气文本生成。例如,下面展示了如何将slang转换为商务英语。
prompt = f"""
Translate the following from slang to a business letter:
'Dude, This is Joe, check out this spec on this standing lamp.'
"""
response = get_completion(prompt)
print(response)
ChatGPT可以在不同文本格式之间进行转换。实现该功能的prompt需要包含输入和输出的格式。以下为一个示例:
这里我们有一个包含餐厅员工姓名和电子邮件的JSON列表。然后在prompt中,我们要求模型将其从JSON格式转换成HTML格式。
data_json = { "resturant employees" :[
{"name":"Shyam", "email":"[email protected]"},
{"name":"Bob", "email":"[email protected]"},
{"name":"Jai", "email":"[email protected]"}
]}
prompt = f"""
Translate the following python dictionary from JSON to an HTML \
table with column headers and title: {data_json}
"""
response = get_completion(prompt)
print(response)
紧接着再使用IPython.display模块输出HTML的可视化表格。
from IPython.display import display, Markdown, Latex, HTML, JSON
display(HTML(response))
这里有一些常见的语法和拼写问题的例子,以及大型语言模型(LLM)针对这些问题的回答。
如果你希望使用大型语言模型(LLM)来校对您的文本,您可以提示模型行'proofread'或'proofread and correct'的操作。例如:
text = [
"The girl with the black and white puppies have a ball.", # The girl has a ball.
"Yolanda has her notebook.", # ok
"Its going to be a long day. Does the car need it’s oil changed?", # Homonyms
"Their goes my freedom. There going to bring they’re suitcases.", # Homonyms
"Your going to need you’re notebook.", # Homonyms
"That medicine effects my ability to sleep. Have you heard of the butterfly affect?", # Homonyms
"This phrase is to cherck chatGPT for speling abilitty" # spelling
]
for t in text:
prompt = f"""Proofread and correct the following text
and rewrite the corrected version. If you don't find
and errors, just say "No errors found". Don't use
any punctuation around the text:
```{t}```"""
response = get_completion(prompt)
print(response)
你也可以在使用LLM进行文本校对和修正的同时,确保文本符合APA的写作风格,并用markdown的文本格式输出。
prompt = f"""
proofread and correct this review. Make it more compelling.
Ensure it follows APA style guide and targets an advanced reader.
Output in markdown format.
Text: ```{text}```
"""
response = get_completion(prompt)
display(Markdown(response))