ks实习总结
本文最后更新于0 天前,其中的信息可能已经过时,如有错误请发送邮件到3368129372@qq.com

时间为12.26-?

项目为大模型一站式开放平台

完成任务

一、实现prompt优化系统

调研报告:

prompt优化调研报告
pw与其他优化方法的对比
目前主流优化方式
(1)连续 Prompt 优化:
优化原理可见文档如何优化软提示
o 理论基础:将 prompt 优化视为一个连续学习问题,使用软提示 (soft prompts),通过训练可学习的向量来引导模型生成。
o 技术方法:利用贝叶斯优化或神经网络等模型,通过反馈迭代优化软提示。
o 代表性研究:
§ InstructZero (Chen et al., 2023):提出通过软提示优化指令,并使用黑盒 LLM 评估。
§ Instinct (Lin et al., 2024):使用神经 bandits 和 transformers 来优化 LLM 指令。
局限性:
o 计算成本高昂:需要额外的神经网络训练(MLP进行评分)
o 可解释性差:软提示通常难以被人理解,难以捕捉特定任务推理的深度,因此在需要细致提示的复杂任务中,适应性有限。
o 需要白盒llm
(2)离散 Prompt 优化:
o 理论基础:通过探索不同的离散提示版本,选择最佳候选,强调提示的多样性和有效性。
o 技术方法:使用蒙特卡洛搜索、进化算法或自引用策略等来生成和评估 prompt。
o 代表性研究:
§ APE (Zhou et al., 2023): 通过蒙特卡洛搜索迭代选择最佳 prompt。
§ PromptBreeder (Fernando et al., 2023):通过突变和自引用进化 prompt。
§ OPRO (Yang et al., 2024): 依赖于 prompt 突变和评估固定训练样本来优化提示.()
§ EvoPrompt (Guo et al., 2024):利用进化算法寻找最优提示。
局限性:
o 查询效率低:这些方法通常依赖于局部搜索技术,难以有效平衡探索和利用,导致查询效率低下。
o 缺乏反馈机制: 离散方法通常随机或通过突变来探索提示空间,缺乏结构化的反馈机制,导致提示优化不理想且无指导。
区别介绍可见:软提示与离散文本优化详细说明
promptwizard优化的点:
传统固定标准: 以往方法优化 prompt 和示例时,倾向于使用随机或基于多样性或对抗性技术进行选择,而 PromptWizard 则使用 LLM 分析和综合示例,动态增强提示质量。
来源于pw论文:“Our work distinguishes itself from previous approaches in several key aspects: 1. Guided Explo-ration: PromptWizard introduces a feedback-driven critique-and-synthesis mechanism, refining prompts based on performance insights. This guided exploration systematically improves prompt quality, overcoming the randomness and inefficiencies in methods like PromptBreeder (Fernando et al., 2023), OPRO (Yang et al., 2024), and EvoPrompt (Guo et al., 2024)(Section 3.1). 2. Sequen-tial Optimization of Instructions and Examples: PromptWizard dynamically and iteratively optimizes both prompt instructions and in-context examples in tandem, outperforming methods that optimize these components in isolation. This strategy allows deeper exploitation of task-specific nuances, leading to superior prompt quality (Section 3.3). 3. Efficient Example Synthesis & Error Analysis: PromptWizard enhances efficiency by utilizing a compact set of diverse examples (up to 25) and leveraging error-driven self-reflection to generate synthetic examples. Combined with Chain-of-Thought reasoning, this approach offers robust and scalable prompt refinement, setting it apart from existing methods (Section 3.4).”
翻译为:“我们的工作在以下几个关键方面区别于以往的方法:

  1. 引导式探索:PromptWizard 引入了一种基于反馈的“批判-合成”机制,通过性能反馈不断优化提示词。这种引导式探索系统性地提升了提示词的质量,克服了 PromptBreeder(Fernando et al., 2023)、OPRO(Yang et al., 2024)和 EvoPrompt(Guo et al., 2024)等方法的随机性和低效性(见第 3.1 节)。
  2. 指令与示例的序列化优化:PromptWizard 以动态、迭代的方式同时优化提示词指令和上下文示例,优于仅对这两个部分单独优化的方法。这一策略能更深入地挖掘任务的细节特性,从而提升提示词质量(见第 3.3 节)。
  3. 高效的示例合成与错误分析:PromptWizard 通过使用最多 25 个多样化示例来提升效率,并利用基于错误的自我反思机制生成合成示例。结合“思维链(Chain-of-Thought)”推理,这一方法实现了强健且可扩展的提示词优化,使其区别于现有方法(见第 3.4 节)。”
    以上几种不同的算法特征链接为:各prompt优化算法特征比对
    pw代码实现评分细节
    来源于pw论文:“ScoringComponent: Next, PW employs a scoring mechanism to evaluate the performance of the generated mutated prompts. The scoring is based on how well each prompt performs against a mini-batch of 5 training examples with ground truth. The scoring mechanism can be either using traditional metrics like F1 score or an LLM as an evaluator, PW supports both. This helps systematically identify the most effective prompt while filtering out underperforming ones. The use of multiple mini-batches ensures robustness in the evaluation. Examples of mutated prompts with their scores are shown in Figure 3 and 5.”
    翻译为:“评分组件:接下来,PromptWizard(PW)采用评分机制来评估生成的变异提示词的表现。评分基于每个提示词在包含真实标签的 5 个训练示例小批量上的表现。评分机制可以使用传统的评价指标,如 F1 分数,或使用大型语言模型(LLM)作为评估器,PW 支持这两种方式。通过这种方法,可以系统地识别最有效的提示词,并筛选出表现不佳的提示词。使用多个小批量进行评估,确保评估的鲁棒性。变异提示词及其评分的示例展示在图 3 和图 5 中。”
    指标评估介绍
    以下来源于论文,pw参考此论文进行指标评估:
    https://arxiv.org/pdf/2310.02905
    ρ(τ)表示在所有任务中,方法在某个任务的表现与该任务的最佳表现之间的差距不超过τ的任务占比。具体公式如下:

例如,当τ = 0.0时,p(τ)的值分别约为:APE为0.05,InstructZero为0.105,PromptBreeder为0.157,EvoPrompt为0.210,INSTINCT为0.421,PromptWizard为0.68。这表明,PromptWizard是表现最好的方法,在68%的任务中超过了其他所有方法。

而对于任务表现的评估,
原文:“Evaluation Metrics. For instruction induction, we use the F1 score for “common concept”, “informal to formal” and SAMSum; we use the exact set matching for “orthography starts with” and “taxonomy animal”; we check whether the output label is contained in the model output for the task of “synonyms”; and we adopt the “exact match” metric for the rest of instruction induction tasks. For the SAMSum dataset, we additionally provide ROUGE-1, ROUGE-2, and ROUGE-L (Lin, 2004) as the evaluation metrics. For the arithmetic reasoning datasets, we use the same way as APE (Zhou et al., 2023) to extract the answer (e.g., numbers or choices) from the generated text and use accuracy as the metric.”
翻译:“评估指标(Evaluation Metrics)
在指令归纳(Instruction Induction)任务中,我们采用不同的评估指标来衡量模型的性能:
● F1 分数(F1 score):用于 “common concept”、“informal to formal” 和 SAMSum 任务。
● 集合精确匹配(Exact Set Matching):用于 “orthography starts with” 和 “taxonomy animal” 任务。
● 标签包含检测:对于 “synonyms” 任务,我们检查输出标签是否包含在模型生成的文本中。
● 精确匹配(Exact Match):适用于其余的指令归纳任务。
对于 SAMSum 数据集,我们额外提供 ROUGE-1、ROUGE-2 和 ROUGE-L(Lin, 2004)作为评估指标。
在算术推理(Arithmetic Reasoning)数据集上,我们参考 APE(Zhou et al., 2023)的方式,从生成文本中提取答案(如数字或选项),并使用准确率(Accuracy)作为最终评估指标。”

ρ(τ)计算算法原创论文
https://arxiv.org/pdf/cs/0102001
在论文第二页“2. Performance Evaluation”中介绍了算法详情
prompt优化调研报告
pw与其他优化方法的对比
目前主流优化方式
(1)连续 Prompt 优化:
优化原理可见文档如何优化软提示
o 理论基础:将 prompt 优化视为一个连续学习问题,使用软提示 (soft prompts),通过训练可学习的向量来引导模型生成。
o 技术方法:利用贝叶斯优化或神经网络等模型,通过反馈迭代优化软提示。
o 代表性研究:
§ InstructZero (Chen et al., 2023):提出通过软提示优化指令,并使用黑盒 LLM 评估。
§ Instinct (Lin et al., 2024):使用神经 bandits 和 transformers 来优化 LLM 指令。
局限性:
o 计算成本高昂:需要额外的神经网络训练(MLP进行评分)
o 可解释性差:软提示通常难以被人理解,难以捕捉特定任务推理的深度,因此在需要细致提示的复杂任务中,适应性有限。
o 需要白盒llm
(2)离散 Prompt 优化:
o 理论基础:通过探索不同的离散提示版本,选择最佳候选,强调提示的多样性和有效性。
o 技术方法:使用蒙特卡洛搜索、进化算法或自引用策略等来生成和评估 prompt。
o 代表性研究:
§ APE (Zhou et al., 2023): 通过蒙特卡洛搜索迭代选择最佳 prompt。
§ PromptBreeder (Fernando et al., 2023):通过突变和自引用进化 prompt。
§ OPRO (Yang et al., 2024): 依赖于 prompt 突变和评估固定训练样本来优化提示.()
§ EvoPrompt (Guo et al., 2024):利用进化算法寻找最优提示。
局限性:
o 查询效率低:这些方法通常依赖于局部搜索技术,难以有效平衡探索和利用,导致查询效率低下。
o 缺乏反馈机制: 离散方法通常随机或通过突变来探索提示空间,缺乏结构化的反馈机制,导致提示优化不理想且无指导。
区别介绍可见:软提示与离散文本优化详细说明
promptwizard优化的点:
传统固定标准: 以往方法优化 prompt 和示例时,倾向于使用随机或基于多样性或对抗性技术进行选择,而 PromptWizard 则使用 LLM 分析和综合示例,动态增强提示质量。
来源于pw论文:“Our work distinguishes itself from previous approaches in several key aspects: 1. Guided Explo-ration: PromptWizard introduces a feedback-driven critique-and-synthesis mechanism, refining prompts based on performance insights. This guided exploration systematically improves prompt quality, overcoming the randomness and inefficiencies in methods like PromptBreeder (Fernando et al., 2023), OPRO (Yang et al., 2024), and EvoPrompt (Guo et al., 2024)(Section 3.1). 2. Sequen-tial Optimization of Instructions and Examples: PromptWizard dynamically and iteratively optimizes both prompt instructions and in-context examples in tandem, outperforming methods that optimize these components in isolation. This strategy allows deeper exploitation of task-specific nuances, leading to superior prompt quality (Section 3.3). 3. Efficient Example Synthesis & Error Analysis: PromptWizard enhances efficiency by utilizing a compact set of diverse examples (up to 25) and leveraging error-driven self-reflection to generate synthetic examples. Combined with Chain-of-Thought reasoning, this approach offers robust and scalable prompt refinement, setting it apart from existing methods (Section 3.4).”
翻译为:“我们的工作在以下几个关键方面区别于以往的方法:

  1. 引导式探索:PromptWizard 引入了一种基于反馈的“批判-合成”机制,通过性能反馈不断优化提示词。这种引导式探索系统性地提升了提示词的质量,克服了 PromptBreeder(Fernando et al., 2023)、OPRO(Yang et al., 2024)和 EvoPrompt(Guo et al., 2024)等方法的随机性和低效性(见第 3.1 节)。
  2. 指令与示例的序列化优化:PromptWizard 以动态、迭代的方式同时优化提示词指令和上下文示例,优于仅对这两个部分单独优化的方法。这一策略能更深入地挖掘任务的细节特性,从而提升提示词质量(见第 3.3 节)。
  3. 高效的示例合成与错误分析:PromptWizard 通过使用最多 25 个多样化示例来提升效率,并利用基于错误的自我反思机制生成合成示例。结合“思维链(Chain-of-Thought)”推理,这一方法实现了强健且可扩展的提示词优化,使其区别于现有方法(见第 3.4 节)。”
    以上几种不同的算法特征链接为:各prompt优化算法特征比对
    pw代码实现评分细节
    来源于pw论文:“ScoringComponent: Next, PW employs a scoring mechanism to evaluate the performance of the generated mutated prompts. The scoring is based on how well each prompt performs against a mini-batch of 5 training examples with ground truth. The scoring mechanism can be either using traditional metrics like F1 score or an LLM as an evaluator, PW supports both. This helps systematically identify the most effective prompt while filtering out underperforming ones. The use of multiple mini-batches ensures robustness in the evaluation. Examples of mutated prompts with their scores are shown in Figure 3 and 5.”
    翻译为:“评分组件:接下来,PromptWizard(PW)采用评分机制来评估生成的变异提示词的表现。评分基于每个提示词在包含真实标签的 5 个训练示例小批量上的表现。评分机制可以使用传统的评价指标,如 F1 分数,或使用大型语言模型(LLM)作为评估器,PW 支持这两种方式。通过这种方法,可以系统地识别最有效的提示词,并筛选出表现不佳的提示词。使用多个小批量进行评估,确保评估的鲁棒性。变异提示词及其评分的示例展示在图 3 和图 5 中。”
    指标评估介绍
    以下来源于论文,pw参考此论文进行指标评估:
    https://arxiv.org/pdf/2310.02905
    ρ(τ)表示在所有任务中,方法在某个任务的表现与该任务的最佳表现之间的差距不超过τ的任务占比。具体公式如下:

例如,当τ = 0.0时,p(τ)的值分别约为:APE为0.05,InstructZero为0.105,PromptBreeder为0.157,EvoPrompt为0.210,INSTINCT为0.421,PromptWizard为0.68。这表明,PromptWizard是表现最好的方法,在68%的任务中超过了其他所有方法。

而对于任务表现的评估,
原文:“Evaluation Metrics. For instruction induction, we use the F1 score for “common concept”, “informal to formal” and SAMSum; we use the exact set matching for “orthography starts with” and “taxonomy animal”; we check whether the output label is contained in the model output for the task of “synonyms”; and we adopt the “exact match” metric for the rest of instruction induction tasks. For the SAMSum dataset, we additionally provide ROUGE-1, ROUGE-2, and ROUGE-L (Lin, 2004) as the evaluation metrics. For the arithmetic reasoning datasets, we use the same way as APE (Zhou et al., 2023) to extract the answer (e.g., numbers or choices) from the generated text and use accuracy as the metric.”
翻译:“评估指标(Evaluation Metrics)
在指令归纳(Instruction Induction)任务中,我们采用不同的评估指标来衡量模型的性能:
● F1 分数(F1 score):用于 “common concept”、“informal to formal” 和 SAMSum 任务。
● 集合精确匹配(Exact Set Matching):用于 “orthography starts with” 和 “taxonomy animal” 任务。
● 标签包含检测:对于 “synonyms” 任务,我们检查输出标签是否包含在模型生成的文本中。
● 精确匹配(Exact Match):适用于其余的指令归纳任务。
对于 SAMSum 数据集,我们额外提供 ROUGE-1、ROUGE-2 和 ROUGE-L(Lin, 2004)作为评估指标。
在算术推理(Arithmetic Reasoning)数据集上,我们参考 APE(Zhou et al., 2023)的方式,从生成文本中提取答案(如数字或选项),并使用准确率(Accuracy)作为最终评估指标。”

ρ(τ)计算算法原创论文
https://arxiv.org/pdf/cs/0102001
在论文第二页“2. Performance Evaluation”中介绍了算法详情

项目开发

责任链模式,每个节点抽象独立,定时任务拉起超时以及异常任务

二、qps提升

背景:快手直播间打算接入luigi,选出直播神评论

  • 写链路改造,不写库表,不发mq,不做网关鉴权
  • 压测,改线程池参数,举例为,1个请求10s响应的话,1s需要10线程处理一个请求,因此tomcat的400线程数能支持40qps
  • 优化代码,上线后发现cpu过高。young gc过于频繁,调大了年轻代发现没用。用arthus分析,发现init tokenizer的时候占用了大量cpu资源(注:大模型调用时需要使用一个model, langchain新建model的时候如果没传入tokenizer就会new一个,很消耗内存,而且之前代码有性能bug,没有复用model)

三、研发技巧

ConditionalOnBean实现懒加载
MDC控制日志map

四、核心工作

rag评估的指标:

  1. 上下文相关度-->召回片段与用户提问相关度占比
  2. 答案相关度-->ai回答与用户提问相关度占比
  3. 忠诚度-->ai回答与召回结果一一比对,是否有矛盾的地方
  4. F1分数-->准确率与召回率的加权平均值

五、中间件学习

5.1 es

5.1.1检索分数
好的,我们来说 BM25,它是 Elasticsearch 默认的全文检索相关性算法,也是现代搜索引擎常用的评分函数。

1. BM25 的作用

  • 目标:给搜索结果排序,让“最相关”的文档排在前面。
  • 核心思想

    • 词频越高(TF),相关性越高
    • 出现频率高的词(如“的”“是”)重要性降低(IDF)
    • 文档长度过长时适当惩罚,防止长文档得分过高

2. BM25 公式

BM25 对每个文档 d 和查询词 q 的打分公式:

$$
score(d, q) = \sum_{t \in q} IDF(t) \cdot \frac{f(t,d) \cdot (k_1 + 1)}{f(t,d) + k_1 \cdot (1 - b + b \cdot \frac{|d|}{avgdl})}
$$

解释:

  • $f(t,d)$ → 词 t 在文档 d 中出现次数(Term Frequency)
  • $|d|$ → 文档长度(字数或词数)
  • $avgdl$ → 平均文档长度
  • $k_1$ → 调节词频饱和度,通常 1.2\~2.0
  • $b$ → 文档长度归一化参数,通常 0.75
  • $IDF(t)$ → 逆文档频率(Inverse Document Frequency),稀有词权重高

3. ES 中 BM25

  • Elasticsearch 默认就是 BM25
  • 可以在索引创建时修改参数:
PUT my_index
{
  "settings": {
    "similarity": {
      "my_bm25": {
        "type": "BM25",
        "k1": 1.2,
        "b": 0.75
      }
    }
  },
  "mappings": {
    "properties": {
      "title": {
        "type": "text",
        "similarity": "my_bm25"
      }
    }
  }
}
  • 也可以使用内置 classic(TF-IDF)或自定义相似度函数。
感谢您的收看 祝你天天开心~
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇