吴恩达 ChatGPT Prompt Engineering for Developers 系列课程笔记--06 Transforming

06 Transforming

大语言模型(LLM)很擅于将输入转换为不同格式的输出,比如翻译、拼写校正或HTML格式转化。相比于复杂的正则表达式,Chat GPT实现更加准确和高效。

1) 不同语种的转换

下述语句实现了英文到西班牙语的翻译。

prompt = f"""
Translate the following English text to Spanish: \ 
```Hi, I would like to order a blender```
"""
response = get_completion(prompt)
print(response)

同样我们也可以实现其它语言之间的相互翻译,甚至通过修改prompt为prompt = f""" Translate the following text to French and Spanish and English pirate:将单句同时翻译为多个语言。另一方面,我们也可以输入Tell me which language this is: ```Combien coûte le lampadaire?让模型判断输入的是什么语言。
我们也可以增加一些具体的指示让模型生成不同风格的语言。比如输入

prompt = f"""
Translate the following text to Chineses in both the \
formal and informal forms: 
'Would you like to diner with me?'
"""

得到下述结果

Formal: 你愿意和我一起共进晚餐吗?(nǐ yuànyì hé wǒ yīqǐ gòngjìn wǎncān ma?)
Informal: 你想跟我一起吃晚饭吗?(nǐ xiǎng gēn wǒ yīqǐ chī wǎnfàn ma?)

通过上述prompt,可以将不同语言转换成统一的语言,以供实际需求。

2) 不同语气/风格的转换

类似上述formal/informal风格转换,我们也可在prompt中指定文本风格来写一封商务短信/邮件等,比如给定口语对话,可通过下述prompt将其转换为商务邮件

prompt = f"""
Translate the following from slang to a business letter: 
'Dude, This is Joe, check out this spec on this standing lamp.'
"""

得到结果为

Dear Sir/Madam,

I am writing to bring to your attention a standing lamp that I believe may be of interest to you. Please find attached the specifications for your review.

Thank you for your time and consideration.

Sincerely,

Joe

3) 不同格式的转换

通过ChatGPT,我们可以实现不同数据类型之间的转换,比如从json到HTML table:

data_json = { "resturant employees" :[ 
    {"name":"Shyam", "email":"shyamjaiswal@gmail.com"},
    {"name":"Bob", "email":"bob32@gmail.com"},
    {"name":"Jai", "email":"jai87@gmail.com"}
]}

prompt = f"""
Translate the following python dictionary from JSON to an HTML \
table with column headers and title: {data_json}
"""

HTML TABLE

4) 拼写检查

我们还可以通过ChatGPT来进行拼写校对。可采用`proofread and correct this review: ```{text}````来实现英文文本的校对,下面测试了一个中文文本的校对示例(总体来说效果不太好,经常校正错误)

text = f"""郭艾伦是我最稀饭的球星之一"""
prompt = f"校对并纠正这段文本: ```{text}```"

得到校正的结果为郭艾伦是我最喜欢的球星之一。
我们可通过在prompt中增加If you don't find any errors, just say "No errors found". 来指定找不到错误时的输出。
最后。可通过下述语句展示纠正之后的文本改动了哪些地方

from redlines import Redlines

diff = Redlines(text,response)
display(Markdown(diff.output_markdown))

上一篇:吴恩达 ChatGPT Prompt Engineering for Developers 系列课程笔记–05 Inferring

下一篇:吴恩达 ChatGPT Prompt Engineering for Developers 系列课程笔记–07 Expanding

deeplearning.ai 原课程地址

课程中文翻译地址

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值