基于 ChatGPT 的 Prompt 工程:文本转换任务
本文是《基于 ChatGPT 的 Prompt 工程》系列课程的第四讲,本文将探讨如何使用大型语言模型进行文本转换任务(text transformation tasks),如语言翻译(language translation),拼写和语法检查(spelling and grammar checking),音调调整(tone adjustment)和格式转换(format conversion)。
语言转换和识别
提示词如下:
- Translate the following English text to Spanish
- Tell me which language this is
- Translate the following text to French and Spanish
and English pirate: - Translate the following text to Spanish in both the formal and informal forms
万国语言转换器
为一群程序员写一个 issue 语言转换器,把所有信息都翻译成韩语和英语。
1 | user_messages = [ |
语态转换(Tone Transformation)
正式场合与非正式场合语言的转换,提示词如下:
- Translate the following from slang to a business letter:
格式转换(Format Conversation)
ChatGPT 可以在不同格式之间转换,比如 Latex、HTML、Markdown。
1 | data_json = { "resturant employees" :[ |
上面这个例子把 JSON 转换成了 Markdown。
拼写检查和语法检查
提示词如下:
- proofread and correct this review:
- Proofread and correct the following text and rewrite the corrected version. If you don’t find any errors, just say “No errors found”. Don’t use any punctuation around the text:
- proofread and correct this review. Make it more compelling. Ensure it follows APA style guide and targets an advanced reader. Output in markdown format.
举例:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19text = 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))
总结
本文介绍了大模型在文本转换任务上的出色表现。
对于科研工作者来说,ChatGPT 在写论文方面真的是最佳助手。