掌握 ChatGPT:法学硕士的有效总结

掌握 ChatGPT:法学硕士的有效总结

源节点: 2763303

文本摘要 ChatGPT

AI 图像生成工具 Dall-E 想象的摘要代理。

您是否是每次访问新餐厅时都会在 Google 地图上留下评论的人群中的一员?

或者,也许您是那种愿意分享您对亚马逊购买的看法的人,尤其是当您被低质量的产品触发时?

别担心,我不会责怪你——我们都有自己的时刻!

在当今的数据世界中,我们都以多种方式为数据洪流做出了贡献。 由于其多样性和解释难度,我发现特别有趣的一种数据类型是文本数据,例如每天在互联网上发布的无数评论。 您是否曾经停下来考虑标准化和压缩文本数据的重要性?
欢迎来到汇总代理的世界!

摘要代理已无缝集成到我们的日常生活中,压缩信息并提供跨多个应用程序和平台对相关内容的快速访问。

在本文中,我们将探讨如何利用 ChatGPT 作为自定义应用程序的强大摘要代理。 得益于大型语言模型(LLM)处理和理解文本的能力, 他们可以帮助阅读文本并生成准确的摘要或标准化信息。 然而,重要的是要知道如何在完成此类任务时发挥他们的潜力,并承认他们的局限性。

总结的最大限制是什么?
法学硕士在遵守特定字符或字数限制方面常常达不到要求 在他们的总结中。

让我们探索使用 ChatGPT 生成摘要的最佳实践 对于我们的自定义应用程序,以及其局限性背后的原因以及如何克服它们!

如果这些深入的教育内容对您有用,则可以 订阅我们的AI研究邮件列表 当我们发布新材料时被提醒。 

使用 ChatGPT 进行有效总结

整个互联网都使用摘要代理。 例如,网站使用摘要代理来提供简洁的文章摘要,使用户能够快速概览新闻,而无需深入了解整个内容。 社交媒体平台和搜索引擎也这样做。

从新闻聚合器和社交媒体平台到电子商务网站,摘要代理已成为我们数字环境中不可或缺的一部分。 随着法学硕士的兴起,其中一些代理现在正在使用人工智能来获得更有效的总结结果。

在使用摘要代理构建应用程序以加快阅读任务和对文本进行分类时,ChatGPT 可以成为一个很好的盟友。 例如,假设我们有一家电子商务业务,并且我们有兴趣处理所有客户评论。 ChatGPT 可以帮助我们用几句话总结任何给定的评论,将其标准化为通用格式,确定 评论的情绪和分类 相应地.

虽然我们确实可以简单地将评论提供给 ChatGPT,但有一个最佳实践列表 - 以及要避免的事情 - 在这项具体任务中利用 ChatGPT 的强大功能。

让我们通过将这个示例变为现实来探索这些选项!

示例:电子商务评论

自制gif。

考虑上面的示例,其中我们有兴趣处理电子商务网站上给定产品的所有评论。 我们有兴趣处理诸如以下有关我们明星产品的评论: 第一台儿童电脑!

prod_review = """
I purchased this children's computer for my son, and he absolutely adores it. He spends hours exploring its various features and engaging with the educational games. The colorful design and intuitive interface make it easy for him to navigate. The computer is durable and built to withstand rough handling, which is perfect for active kids. My only minor gripe is that the volume could be a bit louder. Overall, it's an excellent educational toy that provides hours of fun and learning for my son. It arrived a day earlier
than expected, so I got to play with it myself before I gave it to him. """

在这种情况下,我们希望 ChatGPT 能够:

  • 将评论分为正面或负面。
  • 提供20字的评论摘要。
  • 使用具体结构输出响应,将所有评论标准化为一种格式。

实施说明

以下是我们可以用来从自定义应用程序提示 ChatGPT 的基本代码结构。 我还提供了一个链接 Jupyter笔记本 以及本文中使用的所有示例。

import openai
import os openai.api_key_path = "/path/to/key" def get_completion(prompt, model="gpt-3.5-turbo"): """
This function calls ChatGPT API with a given prompt
and returns the response back. """ messages = [{"role": "user", "content": prompt}] response = openai.ChatCompletion.create( model=model, messages=messages, temperature=0 ) return response.choices[0].message["content"] user_text = f"""
<Any given text> """ prompt = f"""
<Any prompt with additional text> """{user_text}""" """ # A simple call to ChatGPT
response = get_completion(prompt)

该功能 get_completion() 使用给定的值调用 ChatGPT API 提示。 如果提示包含附加内容 用户文本,例如我们案例中的评论本身,它通过三引号与代码的其余部分分开。

让我们使用 get_completion() 提示ChatGPT的功能!

以下是满足上述要求的提示:

prompt = f"""
Your task is to generate a short summary of a product review from an e-commerce site. Summarize the review below, delimited by triple backticks, in exactly 20 words. Output a json with the sentiment of the review, the summary and original review as keys. Review: ```{prod_review}``` """
response = get_completion(prompt)
print(response)

⚠️ 本示例中使用的提示准则(例如使用分隔符将输入文本与提示的其余部分分开以及要求结构化输出)在以下位置进行了完整解释: 我从 OpenAI 的提示工程课程中学到了什么——提示指南.

以下是 ChatGPT 的回答:

{ "sentiment": "positive", "summary": "Durable and engaging children's computer with intuitive interface and educational games. Volume could be louder.", "review": "I purchased this children's computer for my son, and he absolutely adores it. He spends hours exploring its various features and engaging with the educational games. The colorful design and intuitive interface make it easy for him to navigate. The computer is durable and built to withstand rough handling, which is perfect for active kids. My only minor gripe is that the volume could be a bit louder. Overall, it's an excellent educational toy that provides hours of fun and learning for my son. It arrived a day earlierthan expected, so I got to play with it myself before I gave it to him."
}

正如我们从输出中可以观察到的,尽管评论是准确且结构良好的 它遗漏了一些我们作为电子商务所有者可能感兴趣的信息,例如有关产品交付的信息。

总结重点

我们可以迭代地改进要求 ChatGPT 关注摘要中某些内容的提示。 在这种情况下,我们对有关运输和交付的任何详细信息感兴趣:

prompt = f"""
Your task is to generate a short summary of a product review from an ecommerce site. Summarize the review below, delimited by triple backticks, in exactly 20 words and focusing on any aspects that mention shipping and delivery of the product. Output a json with the sentiment of the review, the summary and original review as keys. Review: ```{prod_review}``` """ response = get_completion(prompt)
print(response)

这次,ChatGPT 的答复如下:

{ "sentiment": "positive", "summary": "Durable and engaging children's computer with intuitive interface. Arrived a day earlier than expected.", "review": "I purchased this children's computer for my son, and he absolutely adores it. He spends hours exploring its various features and engaging with the educational games. The colorful design and intuitive interface make it easy for him to navigate. The computer is durable and built to withstand rough handling, which is perfect for active kids. My only minor gripe is that the volume could be a bit louder. Overall, it's an excellent educational toy that provides hours of fun and learning for my son. It arrived a day earlierthan expected, so I got to play with it myself before I gave it to him."
}

现在审查更加完整。 提供有关原始审查的重点的详细信息对于避免 ChatGPT 跳过一些可能对我们的用例有价值的信息至关重要.

您是否注意到,虽然第二次试验包含有关交付的信息,但它跳过了原始评论的唯一负面方面?

让我们解决这个问题!

“摘录”代替“总结”

通过调查总结任务,我发现 如果用户提示不够准确,总结对于法学硕士来说可能是一项棘手的任务.

当要求 ChatGPT 提供给定文本的摘要时,它可以跳过可能与我们相关的信息 ——正如我们最近所经历的—— 或者它会对文本中的所有主题给予相同的重要性,仅提供要点的概述。

法学硕士专家使用这个术语 提取 以及有关其重点的其他信息,而不是 总结 在这些类型的模型的协助下完成此类任务时。

摘要旨在提供文本要点的简洁概述,包括与焦点主题无关的主题,而信息提取则侧重于检索具体细节 并且可以给我们我们正在寻找的东西。 让我们尝试提取吧!

prompt = f"""
Your task is to extract relevant information from a product review from an ecommerce site to give feedback to the Shipping department. From the review below, delimited by triple quotes extract the information relevant to shipping and delivery. Use 100 characters. Review: ```{prod_review}``` """ response = get_completion(prompt)
print(response)

在这种情况下,通过使用提取,我们只能获得有关我们关注的主题的信息: Shipping: Arrived a day earlier than expected.

自动化

该系统适用于一次审查。 然而,在为具体应用程序设计提示时, 在一批示例中对其进行测试非常重要,以便我们可以捕获模型中的任何异常值或不当行为.

如果要处理多个评论,这里有一个可以提供帮助的示例 Python 代码结构。

reviews = [ "The children's computer I bought for my daughter is absolutely fantastic! She loves it and can't get enough of the educational games. The delivery was fast and arrived right on time. Highly recommend!", "I was really disappointed with the children's computer I received. It didn't live up to my expectations, and the educational games were not engaging at all. The delivery was delayed, which added to my frustration.", "The children's computer is a great educational toy. My son enjoys playing with it and learning new things. However, the delivery took longer than expected, which was a bit disappointing.", "I am extremely happy with the children's computer I purchased. It's highly interactive and keeps my kids entertained for hours. The delivery was swift and hassle-free.", "The children's computer I ordered arrived damaged, and some of the features didn't work properly. It was a huge letdown, and the delivery was also delayed. Not a good experience overall."
] prompt = f""" Your task is to generate a short summary of each product review from an e-commerce site. Extract positive and negative information from each of the given reviews below, delimited by triple backticks in at most 20 words each. Extract information about the delivery, if included. Review: ```{reviews}``` """

以下是我们这批评论的摘要:

1. Positive: Fantastic children's computer, fast delivery. Highly recommend.
2. Negative: Disappointing children's computer, unengaging games, delayed delivery.
3. Positive: Great educational toy, son enjoys it. Delivery took longer than expected.
4. Positive: Highly interactive children's computer, swift and hassle-free delivery.
5. Negative: Damaged children's computer, some features didn't work, delayed delivery.

⚠️ 请注意,尽管我们的提示中摘要的字数限制足够清楚,但我们可以很容易地看到,在任何迭代中都没有实现此字数限制。

字数统计中出现这种不匹配的情况是因为法学硕士对字数或字符数没有准确的理解。 这背后的原因依赖于其架构的主要重要组成部分之一: 分词器.

分词器

ChatGPT 等法学硕士旨在根据从大量语言数据中学习到的统计模式生成文本。 虽然它们在生成流畅且连贯的文本方面非常有效,但缺乏对字数的精确控制.

在上面的例子中,当我们给出了关于非常精确的字数统计的指示时, ChatGPT 正在努力满足这些要求。 相反,它生成的文本实际上短于指定的字数。

在其他情况下,它可能会生成较长的文本或只是过于冗长或缺乏细节的文本。 此外, ChatGPT 可能会优先考虑其他因素,例如连贯性和相关性,而不是严格遵守字数统计。 这可能会导致文本在内容和连贯性方面具有高质量,但并不完全符合字数要求。

分词器是 ChatGPT 架构中的关键元素,它明显影响生成输出中的单词数量.

自制gif。

分词器架构

分词器是文本生成过程的第一步。 它负责将我们输入到 ChatGPT 的文本片段分解为各个元素 — 代币 — ,然后由语言模型处理以生成新文本。

当分词器将一段文本分解为标记时,它会根据一组旨在识别目标语言的有意义单元的规则来完成此操作。 然而,这些规则并不总是完美的,并且 在某些情况下,标记生成器会以影响文本总字数的方式拆分或合并标记.

例如,考虑以下句子: “我想吃花生酱三明治”。 如果分词器配置为根据空格和标点符号分割标记,则它可能会将此句子分解为以下标记,总字数为 8,等于标记计数。

自制图像。

但是,如果分词器配置为处理 “花生酱” 作为一个复合词,它可以将句子分解为以下标记, 总字数为 8,但标记数为 7.

因此,分词器的配置方式会影响文本的总字数,这可能会影响法学硕士遵循有关精确字数统计的说明的能力。 虽然一些分词器提供了自定义文本分词方式的选项,但这并不总是足以确保精确遵守字数统计要求。 对于本例中的 ChatGPT,我们无法控制其架构的这一部分.

这使得 ChatGPT 不太擅长完成字符或单词限制,但可以尝试使用句子,因为分词器不会影响 句子的数量,但它们的长度.

了解此限制可以帮助您为您的应用程序构建最合适的提示。 了解了 ChatGPT 上字数统计的工作原理后,让我们对电子商务应用程序的提示进行最后一次迭代!

总结:电子商务评论

让我们将从本文中学到的知识结合到最终的提示中! 在这种情况下,我们将要求以下结果 HTML 更好的输出格式:

from IPython.display import display, HTML prompt = f"""
Your task is to extract relevant information from a product review from an ecommerce site to give feedback to the Shipping department and generic feedback from the product. From the review below, delimited by triple quotes construct an HTML table with the sentiment of the review, general feedback from
the product in two sentences and information relevant to shipping and delivery. Review: ```{prod_review}``` """ response = get_completion(prompt)
display(HTML(response))

这是 ChatGPT 的最终输出:

自制截图来自 Jupyter笔记本 以及本文中使用的示例。

总结

在这篇文章中, 我们已经讨论了使用 ChatGPT 作为自定义应用程序的摘要代理的最佳实践.

我们看到,在构建应用程序时,要在第一次尝试中就得出符合您的应用程序要求的完美提示是极其困难的。 我认为一个很好的带回家的信息是 将提示视为一个迭代过程 您可以在其中完善和建模提示,直到获得完全所需的输出。

通过迭代地完善您的提示并将其应用于一批示例,然后再将其部署到生产中,您可以确保 多个示例的输出是一致的,并涵盖异常值响应。 在我们的示例中,可能有人提供随机文本而不是评论。 我们可以指示 ChatGPT 也有标准化输出来排除这些异常响应.

此外,当使用 ChatGPT 执行特定任务时,了解使用 LLM 执行目标任务的优缺点也是一个很好的实践。 这就是我们如何发现这样一个事实:当我们想要输入文本的通用的类似人类的摘要时,提取任务比摘要更有效。 我们还了解到,提供摘要的重点可以是 改变游戏规则 关于生成的内容。

最后,虽然法学硕士在生成文本方面非常有效, 它们不适合遵循有关字数统计或其他特定格式要求的精确说明。 为了实现这些目标,可能需要坚持句子计数或使用其他工具或方法,例如手动编辑或更专业的软件。

这篇文章最初发表于 走向数据科学 并在获得作者许可的情况下重新发布到TOPBOTS。

喜欢这篇文章吗? 注册以获取更多AI研究更新。

当我们发布更多像这样的摘要文章时,我们会通知您。

时间戳记:

更多来自 热门