文本摘要与扩写

使用 OpenAI API 的 Prompt Engineering

Fouad Trad

Machine Learning Engineer

文本摘要

  • 将文本压缩为更短格式
  • 精简业务流程
    • 财务 -> 概括冗长报告
    • 市场 -> 将客户反馈转为可执行洞见
  • 通过有效提示让 LLM 进行摘要

一张图,展示摘要如何把一摞书变成一页概要。

使用 OpenAI API 的 Prompt Engineering

无效提示

  • 仅给出需摘要的文本
text = "I recently purchased your XYZ Smart Watch and wanted to provide some feedback
based on my experience with the product. I must say that I'm impressed with the sleek design 
and build quality of the watch. It feels comfortable on the wrist and looks great with any 
outfit. The touchscreen is responsive and easy to navigate through the various features."

prompt = f"""Summarize the text delimited by triple backticks: ```{text}```""" print(get_response(prompt))
The author purchased the XYZ Smart Watch and is impressed with its sleek design, build 
quality, and comfortable fit on the wrist. They find the touchscreen responsive and 
user-friendly for navigating the watch's features.
使用 OpenAI API 的 Prompt Engineering

改进提示

  • 输出限制
  • 输出结构
  • 摘要聚焦

一幅图:人物从低阶跃上高阶,表示改进。

使用 OpenAI API 的 Prompt Engineering

有效提示:输出限制

  • 指定句子、词或字符数
text = "I recently purchased your XYZ Smart Watch and wanted to provide some feedback
based on my experience with the product. I must say that I'm impressed with the sleek design 
and build quality of the watch. It feels comfortable on the wrist and looks great with any 
outfit. The touchscreen is responsive and easy to navigate through the various features."

prompt = f"""Summarize the text delimited by triple backticks in one sentence: ```{text}```""" print(get_response(prompt))
The customer is impressed with the sleek design, build quality, comfort, and responsiveness 
of the XYZ Smart Watch's touch screen.
使用 OpenAI API 的 Prompt Engineering

有效提示:输出结构

  • 指定输出结构
text = "I recently purchased your XYZ Smart Watch and wanted to provide some feedback
based on my experience with the product. I must say that I'm impressed with the sleek design 
and build quality of the watch. It feels comfortable on the wrist and looks great with any 
outfit. The touchscreen is responsive and easy to navigate through the various features."

prompt = f"""Summarize the text delimited by triple backticks, in at most three bullet points. ```{text}```""" print(get_response(prompt))
- The XYZ Smart Watch has a sleek and impressive design with  excellent build quality.
- It feels comfortable on the wrist and complements any outfit.
- The touch screen is responsive and user-friendly for easy navigation through the features.
使用 OpenAI API 的 Prompt Engineering

有效提示:摘要聚焦

  • 要求模型关注文本特定部分
text = "I recently purchased your XYZ Smart Watch and wanted to provide some feedback
based on my experience with the product. I must say that I'm impressed with the sleek design 
and build quality of the watch. It feels comfortable on the wrist and looks great with any 
outfit. The touchscreen is responsive and easy to navigate through the various features."

prompt = f"""Summarize the review delimited by triple backticks, in three sentences, focusing on the key features and user experience: ```{text}```""" print(get_response(prompt))
使用 OpenAI API 的 Prompt Engineering

有效提示:摘要聚焦

The customer purchased the XYZ Smart Watch and was impressed with its sleek design 
and build quality. 
They found it comfortable to wear and versatile enough to match any outfit. 
The touch screen was responsive and user-friendly, making it easy to navigate 
through the watch's features.
使用 OpenAI API 的 Prompt Engineering

文本扩写

  • 从要点或想法生成文本
  • 提高效率与生产力
  • 通过精心设计的提示让 LLM 扩写文本

一张图,说明文本扩写是基于少量想法或需求生成完整文本。

使用 OpenAI API 的 Prompt Engineering

扩写型提示

  • 要求模型扩写定界文本
  • 指明需关注的要点
  • 给出输出要求(语气、长度、结构、受众)

图标:铅笔在笔记本上书写。

使用 OpenAI API 的 Prompt Engineering

扩写服务描述

service_description = """Service: Social XYZ
- Social Media Strategy Development
- Content Creation and Posting 
- Audience Engagement and Community Building
- Increased Brand Visibility
- Enhanced Customer Engagement
- Data-Driven Marketing Decisions"""
prompt = f"""Expand the description for the Social XYZ service delimited by triple 
backticks to provide an overview of its features and benefits, without bypassing 
the limit of two sentences. Use a professional tone.
```{service_description}```"""
print(get_response(prompt))
使用 OpenAI API 的 Prompt Engineering

扩写服务描述

Social XYZ is a comprehensive social media service that offers strategic 
development, content creation, and posting to help businesses effectively engage 
with their target audience and build a strong online community. 

With a focus on increasing brand visibility and enhancing customer engagement, 
Social XYZ enables businesses to make data-driven marketing decisions for optimal 
results.
使用 OpenAI API 的 Prompt Engineering

Passons à la pratique !

使用 OpenAI API 的 Prompt Engineering

Preparing Video For Download...