【Prompting】ChatGPT Prompt Engineering开发指南(5)

ChatGPT Prompt Engineering开发指南: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)

执行结果:

Hola, me gustaría ordenar una licuadora.

另外三个案例:

prompt = f"""
Tell me which language this is:
```Combien coûte le lampadaire?```
"""
response = get_completion(prompt)
print(response)

执行结果:

This is French.
prompt = f"""
Translate the following  text to French and Spanish
and English pirate: \
```I want to order a basketball```
"""
response = get_completion(prompt)
print(response)

执行结果:

French pirate: ```Je veux commander un ballon de basket```
Spanish pirate: ```Quiero pedir una pelota de baloncesto```
English pirate: ```I want to order a basketball```
prompt = f"""
Translate the following text to Spanish in both the \
formal and informal forms:
'Would you like to order a pillow?'
"""
response = get_completion(prompt)
print(response)

执行结果:

Formal: ¿Le gustaría ordenar una almohada?
Informal: ¿Te gustaría ordenar una almohada?

通用翻译器

想象一下,您负责大型跨国电子商务公司。用户在其所有母语中都向您发送IT问题。您的员工来自世界各地,只会说他们的母语。您需要一个通用翻译器!

user_messages = [
  "La performance du système est plus lente que d'habitude.",  # System performance is slower than normal
  "Mi monitor tiene píxeles que no se iluminan.",              # My monitor has pixels that are not lighting
  "Il mio mouse non funziona",                                 # My mouse is not working
  "Mój klawisz Ctrl jest zepsuty",                             # My keyboard has a broken control key
  "我的屏幕在闪烁"                                               # My screen is flashing
]
for issue in user_messages:
    prompt = f"Tell me what language this is: ```{issue}```"
    lang = get_completion(prompt)
    print(f"Original message ({lang}): {issue}")

    prompt = f"""
    Translate the following  text to English \
    and Korean: ```{issue}```
    """
    response = get_completion(prompt)
    print(response, "\n")

执行结果

音调转换

写作可以根据预期受众的不同而有所不同。ChatGPT可以产生不同的音调。

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可以在不同格式之间进行转换。提示应该描述输入和输出格式。

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}
"""
response = get_completion(prompt)
print(response)
<table>
  <caption>Restaurant Employees</caption>
  <thead>
    <tr>
      <th>Name</th>
      <th>Email</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Shyam</td>
      <td>shyamjaiswal@gmail.com</td>
    </tr>
    <tr>
      <td>Bob</td>
      <td>bob32@gmail.com</td>
    </tr>
    <tr>
      <td>Jai</td>
      <td>jai87@gmail.com</td>
    </tr>
  </tbody>
</table>

显示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)

执行结果

text = f"""
Got this for my daughter for her birthday cuz she keeps taking \
mine from my room.  Yes, adults also like pandas too.  She takes \
it everywhere with her, and it's super soft and cute.  One of the \
ears is a bit lower than the other, and I don't think that was \
designed to be asymmetrical. It's a bit small for what I paid for it \
though. I think there might be other options that are bigger for \
the same price.  It arrived a day earlier than expected, so I got \
to play with it myself before I gave it to my daughter.
"""
prompt = f"proofread and correct this review: ```{text}```"
response = get_completion(prompt)
print(response)

执行结果:
执行结果
批改模式:

from redlines import Redlines

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

执行结果
补充:Redlines生成一个Markdown文本,显示两个字符串/文本之间的差异。这些更改用删除线和下划线表示,看起来类似于Microsoft Word的跟踪更改。这种显示变化的方法对律师来说更为熟悉,对长系列的角色来说更为紧凑。
pip install redlines

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

执行结果:
执行结果

内容来源

  1. DeepLearning.AI: 《ChatGPT Prompt Engineering for Developers》

http://www.niftyadmin.cn/n/330540.html

相关文章

【git】Git基础入门:安装和初次设置

引言 对于一位想要向版本控制系统问好的新手,Git无疑是个好选择。 一、安装Git 安装Git就像是招募一个帮手,需要你在你的操作系统中找到他。 1.1 Windows系统 在Windows系统中,你需要访问Git的“家”:https://git-scm.com/downloads ,并下载Windows版本。双击安装程序…

【数据结构】数据结构概念 ( 数据结构中常见的存储结构 | 数据结构中常见的逻辑结构 )

文章目录 一、数据结构概念二、数据结构中常见的存储结构二、数据结构中常见的逻辑结构 一、数据结构概念 数据结构 是 计算机内存 中 组织 和 存储 数据 的方式 , 有以下两部分组成 : 逻辑结构 : 数据的存放形式 ;操作 : 数据如何操作 , 如 : 排序 , 查询 , 删除 , 增加 , 修…

〖技术人必学的职业规划白宝书 - 职业规划篇②〗- 进入职场前必须要考虑的问题

历时18个月&#xff0c;采访 850 得到的需求。 不管你是在校大学生、研究生、还是在职的小伙伴&#xff0c;该专栏有你想要的职业规划、简历、面试的答案。说明&#xff1a;该文属于 技术人必学的职业规划白宝书 专栏&#xff0c;购买任意白宝书体系化专栏可加入TFS-CLUB 私域社…

leecode 数据库:585. 2016年的投资

数据导入&#xff1a; Create Table If Not Exists Insurance (pid int, tiv_2015 float, tiv_2016 float, lat float, lon float); Truncate table Insurance; insert into Insurance (pid, tiv_2015, tiv_2016, lat, lon) values (1, 10, 5, 10, 10); insert into Insurance…

『python爬虫』23. selenium之窗口切换与iframe(保姆级图文)

目录 1. 窗口切换2. 抓取拉勾网职务信息2.1 拉勾网查看职务详情与价格2.2 完整代码 3. iframe的处理总结 欢迎关注 『python爬虫』 专栏&#xff0c;持续更新中 欢迎关注 『python爬虫』 专栏&#xff0c;持续更新中 1. 窗口切换 窗口句柄的定义&#xff1a;WebDriver对象有wi…

LLM大模型开源案例集,需带有:数据集+模型微调+项目代码(三)

文章目录 1 ChatGLM-Med: 基于中文医学知识的ChatGLM模型微调1.1 数据集1.2 ChatGLM+P-tuning V2微调1.3 Llama + Alpaca的Lora微调版本2 LawGPT_zh:中文法律大模型(獬豸)2.1 数据集2.1.1 利用ChatGPT清洗CrimeKgAssitant数据集得到52k单轮问答:2.1.2 带有法律依据的情景问…

大模型训练数据多样性的重要性

大家好,我是herosunly。985院校硕士毕业,现担任算法研究员一职,热衷于机器学习算法研究与应用。曾获得阿里云天池比赛第一名,CCF比赛第二名,科大讯飞比赛第三名。拥有多项发明专利。对机器学习和深度学习拥有自己独到的见解。曾经辅导过若干个非计算机专业的学生进入到算法…

【ARMv8 编程】A64 流控制指令

A64 指令集提供了许多不同种类的分支指令。对于简单的相对分支&#xff0c;即那些从当前地址偏移的分支&#xff0c;使用 B 指令。无条件简单相对分支可以从当前程序计数器位置向后或向前分支最多 128MB。 有条件的简单相对分支&#xff0c;其中条件代码附加到 B&#xff0c;具…