返回顶部
热门问答 更多热门问答
技术文章 更多技术文章

通过语义压缩文本降低LLM成本

[复制链接]
链载Ai 显示全部楼层 发表于 3 小时前 |阅读模式 打印 上一主题 下一主题

大型语言模型在处理自然语言文本方面表现出色,它们能够处理非结构化数据,并从大量信息中识别出相关内容。然而,这些模型都有一个共同的限制,即上下文窗口大小。上下文窗口是指模型能够同时处理的最大文本量,它限制了模型处理长文本或大量文本数据的能力。对于像Bazaarvoice这样的公司来说,这个限制尤为明显。Bazaarvoice一直在收集用户生成的产品评论,这些评论数量庞大且内容多样。为了提供产品评论摘要功能,Bazaarvoice需要处理数百万甚至数千万条评论,这远远超出了大多数LLM的上下文窗口限制。

ingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", "Source Han Sans CN", sans-serif, "Apple Color Emoji", "Segoe UI Emoji";color: rgb(5, 7, 59);font-weight: 600;font-size: 20px;border: none;line-height: 1.7;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(253, 253, 254);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;">一、语义压缩技术的提出

ingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", "Source Han Sans CN", sans-serif, "Apple Color Emoji", "Segoe UI Emoji";font-size: 15px;line-height: 1.7;color: rgb(5, 7, 59);font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(253, 253, 254);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;">面对上述挑战,Bazaarvoice提出了一种创新的解决方案:语义压缩(知识蒸馏:大模型(LLM)中的模型压缩与知识转移技术)。该技术的核心思想是,许多评论表达了相同或相似的观点,因此可以通过识别并去除重复或相似的文本来减少输入到LLM中的文本量。这样不仅可以避免超出上下文窗口限制,还可以降低LLM的使用成本。

ingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", "Source Han Sans CN", sans-serif, "Apple Color Emoji", "Segoe UI Emoji";color: rgb(5, 7, 59);font-weight: 600;font-size: 20px;border: none;line-height: 1.7;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(253, 253, 254);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;">二、语义压缩的实现方法

ingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", "Source Han Sans CN", sans-serif, "Apple Color Emoji", "Segoe UI Emoji";font-size: 15px;line-height: 1.7;color: rgb(5, 7, 59);font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(253, 253, 254);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;">(一)利用数据重复性


ingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", "Source Han Sans CN", sans-serif, "Apple Color Emoji", "Segoe UI Emoji";font-size: 15px;line-height: 1.7;color: rgb(5, 7, 59);font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(253, 253, 254);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;">Bazaarvoice 发现许多产品评论存在内容重复的情况,这为解决问题提供了思路。通过识别表达相同意思的文本段,减少发送给 LLM 的文本量,既能避免超出上下文窗口限制,又能降低系统运营成本。

ingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", "Source Han Sans CN", sans-serif, "Apple Color Emoji", "Segoe UI Emoji";font-size: 15px;line-height: 1.7;color: rgb(5, 7, 59);font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(253, 253, 254);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;">(二)多步骤处理流程


    ingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;" class="list-paddingleft-1">
  1. 句子分割
    首先将产品评论分割成单个句子,为后续处理奠定基础。
  2. 向量嵌入计算
    使用在语义文本相似性(STS)基准测试中表现良好的网络,为每个句子计算嵌入向量。这一步骤的关键在于选择合适的嵌入模型,确保能够准确捕捉句子的语义信息。
  3. 层次聚类
    对每个产品的所有嵌入向量进行凝聚式聚类。在聚类过程中,面临如何确保语义相似性的挑战。Bazaarvoice 通过对 STS 基准数据集的分析,计算训练数据集中所有句子对的距离,并拟合多项式来确定距离阈值,从而实现根据语义相似性目标选择合适的聚类阈值。例如,选择语义相似性分数为 3.5 的阈值,保证大多数聚类中的句子具有较高的语义等价性。
  4. 代表性句子选择
    从每个聚类中保留最接近聚类质心的句子作为代表发送给 LLM,同时丢弃其他句子。对于小聚类,将其视为异常值,随机采样后纳入 LLM 处理。此外,还会在 LLM 提示中包含每个聚类所代表的句子数量,以确保考虑到每个情感的权重。

ingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", "Source Han Sans CN", sans-serif, "Apple Color Emoji", "Segoe UI Emoji";font-size: 15px;line-height: 1.7;color: rgb(5, 7, 59);font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(253, 253, 254);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;">(三)多轮聚类策略


    ingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;" class="list-paddingleft-1">
  1. 第一轮聚类(无损压缩)
    首先使用语义相似性分数为 4 的阈值进行聚类,此轮可视为无损压缩,压缩比为 1.18(节省 15% 的空间),但对于大规模数据处理而言,无损压缩远远不够。
  2. 后续轮次聚类(有损压缩)
    选择第一轮聚类中较小的异常聚类(向量数量少的聚类),使用更低的语义相似性分数阈值(如 3)再次进行聚类。随着轮次增加,不断降低阈值,虽然会牺牲更多信息,但能获得更高的压缩比。重复这一过程,直到达到理想的压缩效果。在实际操作中,经过多次降低阈值后,仍存在大量仅含单个向量的聚类,这些被视为异常值,随机采样以确保最终提示包含 25,000 个令牌。

ingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", "Source Han Sans CN", sans-serif, "Apple Color Emoji", "Segoe UI Emoji";font-size: 15px;line-height: 1.7;color: rgb(5, 7, 59);font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(253, 253, 254);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;">(四)嵌入模型评估


为确保所选嵌入模型能有效将语义相似的句子映射到相近的向量空间,Bazaarvoice 使用 STS 基准数据集对模型进行评估,计算 Pearson 相关性。以 AWS 的 Titan Text Embedding 模型为例,评估结果显示其在嵌入语义相似句子方面表现出色,且成本极低,适合用于该任务。

(五)确保总结真实性


由于多轮聚类和随机异常值采样可能导致语义信息损失,Bazaarvoice 采取措施确保总结的真实性。对于每个产品,通过抽样部分评论,使用 LLM Evals 评估总结是否能代表和关联每条评论,以此作为衡量压缩有效性的硬指标,平衡压缩与信息完整性之间的关系。

三、语义压缩技术的效果评估

为了评估语义压缩技术(Prompt压缩:提升大型语言模型效率的关键技术)的效果,Bazaarvoice进行了一系列实验。他们选择了多个产品评论数据集,并分别使用未压缩的文本和经过语义压缩的文本作为LLM的输入。然后,他们比较了两种情况下LLM生成的摘要的准确性和代表性。

实验结果表明,经过语义压缩的文本在保持一定语义信息完整性的同时,显著降低了LLM的使用成本。具体来说,Bazaarvoice实现了97.7%的文本压缩率(即压缩比为42),这意味着他们可以将原始文本量减少到原来的2.5%左右。同时,生成摘要的成本降低了82.4%,包括嵌入句子数据并将其存储在数据库中的成本。

此外,Bazaarvoice还通过用户调查来评估摘要的准确性和代表性。他们发现,大多数用户认为经过语义压缩后生成的摘要仍然能够准确地反映原始评论中的关键信息和观点。这表明语义压缩技术在保持摘要质量方面也具有较好的表现。

四、语义压缩技术的应用场景与前景

语义压缩技术不仅适用于Bazaarvoice的产品评论摘要功能,还可以广泛应用于其他需要处理大量文本数据的场景。例如,在新闻摘要、社交媒体分析、客户服务等领域中,都可以通过语义压缩技术来降低LLM的使用成本并提高处理效率。

随着大型语言模型的不断发展和完善,语义压缩技术也将面临更多的挑战和机遇。一方面,随着模型性能的提升和上下文窗口的扩大,语义压缩技术的需求可能会逐渐减少。另一方面,随着文本数据量的不断增加和多样化,语义压缩技术仍然具有重要的应用价值和发展前景。

为了进一步提高语义压缩技术的效果和应用范围,未来的研究可以关注以下几个方面:一是探索更先进的文本嵌入模型和聚类算法,以提高语义相似性的判断准确性和聚类效果;二是研究如何结合上下文信息和用户反馈来优化语义压缩策略;三是探索将语义压缩技术与其他自然语言处理技术相结合的新方法和新应用。


语义压缩技术是一种有效的降低LLM使用成本的方法。通过减少输入到LLM中的文本量并保持一定语义信息完整性,该技术可以显著提高处理效率并降低成本。Bazaarvoice的实践表明,语义压缩技术在产品评论摘要功能中取得了显著的效果,并具有重要的应用价值和发展前景。随着大型语言模型的不断发展和完善,我们期待语义压缩技术能够在更多领域中得到广泛应用和推广。

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

链载AI是专业的生成式人工智能教程平台。提供Stable Diffusion、Midjourney AI绘画教程,Suno AI音乐生成指南,以及Runway、Pika等AI视频制作与动画生成实战案例。从提示词编写到参数调整,手把手助您从入门到精通。
  • 官方手机版

  • 微信公众号

  • 商务合作

  • Powered by Discuz! X3.5 | Copyright © 2025-2025. | 链载Ai
  • 桂ICP备2024021734号 | 营业执照 | |广西笔趣文化传媒有限公司|| QQ