DPO(Direct Preference Optimization)算法解释:中英双语
中文版
DPO paper: https://arxiv.org/pdf/2305.18290
DPO 算法详解:从理论到实现
1. 什么是 DPO?
DPO(Direct Preference Optimization)是一种直接基于人类偏好进行优化的算法,旨在解决从人类偏好数据中训练出表现更优的语言模型的问题。它与传统的基于奖励建模的强化学习方法(如 PPO)不同,通过引入一种基于 Bradley-Terry 模型的参数化方法,将人类偏好概率直接与语言模型的输出概率相关联,从而避免了明确训练奖励模型的过程。
2. DPO 解决什么问题?
在 RLHF(Reinforcement Learning with Human Feedback)框架中,通常需要训练一个奖励模型来对语言模型的生成进行打分。然而,训练奖励模型和使用强化学习优化策略模型(如 PPO)通常会引入一些复杂性和不稳定性:
- 奖励模型可能过拟合或偏离人类真实偏好。
- 使用强化学习优化策略模型需要平衡探索和收敛,容易引发 KL 散度爆炸等问题。
DPO 提供了一种更直接的优化方式,通过重新参数化,将偏好建模直接嵌入语言模型优化中,从而绕过奖励建模,简化了训练流程。
3. DPO 的核心公式
DPO 的核心思想是通过 Bradley-Terry 偏好模型,将偏好概率建模为语言模型输出概率的对数比值,并引入温度参数 ( β \beta β ) 来控制 KL 惩罚强度。
核心公式
人类偏好概率建模公式如下:
p ∗ ( y 1 ≻ y 2 ∣ x ) = 1 1 + exp ( β log π ∗ ( y 2 ∣ x ) π ref ( y 2 ∣ x ) − β log π ∗ ( y 1 ∣ x ) π ref ( y 1 ∣ x ) ) p^*(y_1 \succ y_2 | x) = \frac{1}{1 + \exp\left(\beta \log \frac{\pi^*(y_2|x)}{\pi_{\text{ref}}(y_2|x)} - \beta \log \frac{\pi^*(y_1|x)}{\pi_{\text{ref}}(y_1|x)}\right)} p∗(y1≻y2∣x)=1+exp(βlogπref(y2∣x)π∗(y2∣x)−βlogπref(y1∣x)π∗(y1∣x))1
在实际中,我们通过最大化以下目标函数来优化参数化的策略模型 ( π θ \pi_\theta πθ ):
L DPO ( π θ ; π ref ) = − E ( x , y w , y l ) ∼ D [ log σ ( β log π θ ( y w ∣ x ) π ref ( y w ∣ x ) − β log π θ ( y l ∣ x ) π ref ( y l ∣ x ) ) ] L_{\text{DPO}}(\pi_\theta; \pi_{\text{ref}}) = - \mathbb{E}_{(x, y_w, y_l) \sim D}\left[ \log \sigma\left(\beta \log \frac{\pi_\theta(y_w | x)}{\pi_{\text{ref}}(y_w | x)} - \beta \log \frac{\pi_\theta(y_l | x)}{\pi_{\text{ref}}(y_l | x)}\right) \right] LDPO(πθ;πref)=−E(x,yw,yl)∼D[logσ(βlogπref(yw∣x)πθ(yw∣x)−βlogπref(yl∣x)πθ(yl∣x))]
其中:
- ( σ \sigma σ ) 是 Sigmoid 函数。
- ( y w y_w yw ) 和 ( y l y_l yl ) 分别是人类标注的偏好和非偏好样本。
通过最大化该目标函数,策略模型会更倾向于生成被人类偏好的输出,同时抑制被人类不喜欢的输出。
4. 如何理解 DPO?
DPO 的优化过程可以从以下几个方面理解:
-
奖励重新参数化
通过将奖励模型嵌入策略模型输出的对数比值中,避免了显式训练奖励模型的过程。
隐式奖励定义为:
r ^ θ ( x , y ) = β log π θ ( y ∣ x ) π ref ( y ∣ x ) \hat{r}_\theta(x, y) = \beta \log \frac{\pi_\theta(y | x)}{\pi_{\text{ref}}(y | x)} r^θ(x,y)=βlogπref(y∣x)πθ(y∣x) -
梯度优化
DPO 的梯度公式为:
∇ θ L DPO = − β E ( x , y w , y l ) ∼ D [ σ ( r ^ θ ( x , y l ) − r ^ θ ( x , y w ) ) ⋅ ( ∇ θ log π θ ( y w ∣ x ) − ∇ θ log π θ ( y l ∣ x ) ) ] \nabla_\theta L_{\text{DPO}} = -\beta \mathbb{E}_{(x, y_w, y_l) \sim D}\left[ \sigma(\hat{r}_\theta(x, y_l) - \hat{r}_\theta(x, y_w)) \cdot (\nabla_\theta \log \pi_\theta(y_w | x) - \nabla_\theta \log \pi_\theta(y_l | x)) \right] ∇θLDPO=−βE(x,yw,yl)∼D[σ(r^θ(x,yl)−r^θ(x,yw))⋅(∇θlogπθ(yw∣x)−∇θlogπθ(yl∣x))]直观上,这意味着模型会:
- 提高 ( y w y_w yw ) 的生成概率。
- 降低 ( y l y_l yl ) 的生成概率。
- 偏差较大的样本(即 ( r ^ θ ( x , y l ) − r ^ θ ( x , y w ) \hat{r}_\theta(x, y_l) - \hat{r}_\theta(x, y_w) r^θ(x,yl)−r^θ(x,yw) ) 较大时)权重更高。
-
温度参数 ( β \beta β )
( β \beta β ) 控制 KL 惩罚的强度,平衡策略模型与参考模型之间的分布差异。
5. 示例解析
假设我们有一个 Prompt,生成了两个候选回复 ( y 1 y_1 y1 ) 和 ( y 2 y_2 y2 ),并根据人类偏好得到以下信息:
- ( y 1 y_1 y1 ) 被偏好 (( y w = y 1 y_w = y_1 yw=y1 )),( y 2 y_2 y2 ) 被不偏好 (( y l = y 2 y_l = y_2 yl=y2 ))。
- 模型的输出概率为:
π θ ( y 1 ∣ x ) = 0.6 , π θ ( y 2 ∣ x ) = 0.4 , π ref ( y 1 ∣ x ) = 0.5 , π ref ( y 2 ∣ x ) = 0.5 \pi_\theta(y_1|x) = 0.6, \quad \pi_\theta(y_2|x) = 0.4, \quad \pi_{\text{ref}}(y_1|x) = 0.5, \quad \pi_{\text{ref}}(y_2|x) = 0.5 πθ(y1∣x)=0.6,πθ(y2∣x)=0.4,πref(y1∣x)=0.5,πref(y2∣x)=0.5
计算隐式奖励:
r ^ θ ( x , y 1 ) = β log π θ ( y 1 ∣ x ) π ref ( y 1 ∣ x ) = β log 0.6 0.5 \hat{r}_\theta(x, y_1) = \beta \log \frac{\pi_\theta(y_1|x)}{\pi_{\text{ref}}(y_1|x)} = \beta \log \frac{0.6}{0.5} r^θ(x,y1)=βlogπref(y1∣x)πθ(y1∣x)=βlog0.50.6
r ^ θ ( x , y 2 ) = β log π θ ( y 2 ∣ x ) π ref ( y 2 ∣ x ) = β log 0.4 0.5 \hat{r}_\theta(x, y_2) = \beta \log \frac{\pi_\theta(y_2|x)}{\pi_{\text{ref}}(y_2|x)} = \beta \log \frac{0.4}{0.5} r^θ(x,y2)=βlogπref(y2∣x)πθ(y2∣x)=βlog0.50.4
偏好模型的概率:
p ∗ ( y 1 ≻ y 2 ∣ x ) = 1 1 + exp ( r ^ θ ( x , y 2 ) − r ^ θ ( x , y 1 ) ) p^*(y_1 \succ y_2 | x) = \frac{1}{1 + \exp\left(\hat{r}_\theta(x, y_2) - \hat{r}_\theta(x, y_1)\right)} p∗(y1≻y2∣x)=1+exp(r^θ(x,y2)−r^θ(x,y1))1
优化目标是让模型进一步增加 ( y 1 y_1 y1 ) 的概率,同时减少 ( y 2 y_2 y2 ) 的概率。
6. DPO 和 PPO 的区别
| 特性 | DPO | PPO |
|---|---|---|
| 核心思想 | 直接基于人类偏好优化语言模型 | 基于奖励信号,通过强化学习优化策略 |
| 是否需要奖励模型 | 不需要 | 需要 |
| 优化目标 | 最大化偏好概率 | 最大化累计奖励 |
| 实现复杂度 | 较低 | 较高 |
| 稳定性 | 较高 | 可能出现 KL 爆炸等问题 |
关于KL爆炸问题,可以参考笔者的另一篇博客:PPO 可能出现 KL 爆炸等问题的详细分析(KL Explosions in PPO): 中英双语
7. 总结
DPO 提供了一种高效、稳定的语言模型优化方法,适合在大规模人类偏好数据上训练更优的模型。相比于传统的 RLHF 方法,DPO 不仅简化了实现过程,还具备更强的理论一致性和实践可靠性。
Direct Preference Optimization (DPO): A Comprehensive Overview
What Problem Does DPO Solve?
Direct Preference Optimization (DPO) addresses the limitations of Reinforcement Learning with Human Feedback (RLHF) by offering a simpler and more direct optimization method. RLHF traditionally uses reward models and Proximal Policy Optimization (PPO) to align language models with human preferences. However, PPO introduces complexity due to the need for dynamic reward modeling and reinforcement learning updates, which involve policy rollouts and value function estimation.
DPO simplifies this process by directly optimizing the likelihood of human-preferred responses relative to dispreferred ones without requiring an explicit reward model or reinforcement learning steps. Instead, it reformulates the optimization as a maximum likelihood estimation (MLE) problem.
Core Formula of DPO
The central idea of DPO is to use a Bradley-Terry preference model to define probabilities for human preferences based on the log-probabilities output by the model.
Given:
- ( π θ \pi_\theta πθ ): The policy (current model being optimized)
- ( π r e f \pi_{ref} πref ): The reference policy (pre-trained model used as a baseline)
- ( y w y_w yw ): Preferred response
- ( y l y_l yl ): Dispreferred response
- ( β \beta β ): Temperature hyperparameter controlling regularization strength
DPO models human preferences using the log-ratio of probabilities between the preferred and dispreferred outputs.
The loss function is:
L D P O ( π θ ; π r e f ) = − E ( x , y w , y l ) ∼ D [ log σ ( β ( log π θ ( y w ∣ x ) π r e f ( y w ∣ x ) − log π θ ( y l ∣ x ) π r e f ( y l ∣ x ) ) ) ] L_{DPO}(\pi_\theta; \pi_{ref}) = -E_{(x, y_w, y_l) \sim D} \left[ \log \sigma \left( \beta \left( \log \frac{\pi_\theta(y_w | x)}{\pi_{ref}(y_w | x)} - \log \frac{\pi_\theta(y_l | x)}{\pi_{ref}(y_l | x)} \right) \right) \right] LDPO(πθ;πref)=−E(x,yw,yl)∼D[logσ(β(logπref(yw∣x)πθ(yw∣x)−logπref(yl∣x)πθ(yl∣x)))]
Key Points in the Formula:
- The loss directly optimizes the relative log-probabilities of preferred (( y w y_w yw)) versus dispreferred (( y l y_l yl)) responses.
- ( β \beta β ) controls the strength of KL-regularization between the policy and the reference model.
- ( σ ( ⋅ ) \sigma(\cdot) σ(⋅) ) represents the sigmoid function, ensuring the preference probabilities are modeled effectively.
- It eliminates the need for explicit reward modeling, treating model preferences as implicit rewards.
Understanding the Formula
1. Implicit Reward Calculation
DPO implicitly defines a reward function based on the policy and reference model:
r ^ θ ( x , y ) = β log π θ ( y ∣ x ) π r e f ( y ∣ x ) \hat{r}_\theta(x, y) = \beta \log \frac{\pi_\theta(y | x)}{\pi_{ref}(y | x)} r^θ(x,y)=βlogπref(y∣x)πθ(y∣x)
This means the reward is proportional to the log-likelihood ratio between the current and reference models.
2. Optimization Objective
DPO optimizes the probability of preferred completions being ranked higher than dispreferred completions.
Specifically, it increases the likelihood of preferred completions (( y w y_w yw)) while decreasing the likelihood of dispreferred ones (( y l y_l yl)).
The gradient of the loss is:
∇ θ L D P O = − β E ( x , y w , y l ) ∼ D [ σ ( r ^ θ ( x , y l ) − r ^ θ ( x , y w ) ) ( ∇ θ log π θ ( y w ∣ x ) − ∇ θ log π θ ( y l ∣ x ) ) ] \nabla_\theta L_{DPO} = -\beta E_{(x, y_w, y_l) \sim D}\left[ \sigma(\hat{r}_\theta(x, y_l) - \hat{r}_\theta(x, y_w)) \left( \nabla_\theta \log \pi_\theta(y_w | x) - \nabla_\theta \log \pi_\theta(y_l | x) \right) \right] ∇θLDPO=−βE(x,yw,yl)∼D[σ(r^θ(x,yl)−r^θ(x,yw))(∇θlogπθ(yw∣x)−∇θlogπθ(yl∣x))]
3. Weighting by Confidence
The weighting term ( σ ( r ^ θ ( x , y l ) − r ^ θ ( x , y w ) ) \sigma(\hat{r}_\theta(x, y_l) - \hat{r}_\theta(x, y_w)) σ(r^θ(x,yl)−r^θ(x,yw)) ) penalizes errors when the model incorrectly assigns higher rewards to dispreferred completions. This ensures that updates focus on examples where the model is most uncertain or wrong, leading to more effective training.
Example Analysis
Suppose we have the following preferences for prompts:
Input Prompt:
“What is the capital of France?”
Completions:
- ( y w y_w yw ): “The capital of France is Paris.” (Preferred)
- ( y l y_l yl ): “The capital of France is London.” (Dispreferred)
The log-probabilities from the current model (( π θ \pi_\theta πθ )) and reference model (( π r e f \pi_{ref} πref )) are:
- ( π θ ( y w ∣ x ) = − 0.2 \pi_\theta(y_w | x) = -0.2 πθ(yw∣x)=−0.2 ), ( π θ ( y l ∣ x ) = − 0.8 \pi_\theta(y_l | x) = -0.8 πθ(yl∣x)=−0.8 )
- ( π r e f ( y w ∣ x ) = − 0.3 \pi_{ref}(y_w | x) = -0.3 πref(yw∣x)=−0.3 ), ( π r e f ( y l ∣ x ) = − 0.7 \pi_{ref}(y_l | x) = -0.7 πref(yl∣x)=−0.7 )
Using the DPO loss formula:
-
Calculate the log-probability ratios:
r w = log π θ ( y w ∣ x ) π r e f ( y w ∣ x ) = log ( − 0.2 ) − log ( − 0.3 ) = − 0.17 r_w = \log \frac{\pi_\theta(y_w | x)}{\pi_{ref}(y_w | x)} = \log(-0.2) - \log(-0.3) = -0.17 rw=logπref(yw∣x)πθ(yw∣x)=log(−0.2)−log(−0.3)=−0.17
r l = log π θ ( y l ∣ x ) π r e f ( y l ∣ x ) = log ( − 0.8 ) − log ( − 0.7 ) = 0.06 r_l = \log \frac{\pi_\theta(y_l | x)}{\pi_{ref}(y_l | x)} = \log(-0.8) - \log(-0.7) = 0.06 rl=logπref(yl∣x)πθ(yl∣x)=log(−0.8)−log(−0.7)=0.06 -
Compute the preference difference:
Δ r = β ( r w − r l ) = β ( − 0.17 − 0.06 ) = β ( − 0.23 ) \Delta r = \beta (r_w - r_l) = \beta(-0.17-0.06)=\beta(-0.23) Δr=β(rw−rl)=β(−0.17−0.06)=β(−0.23) -
Final loss:
L = − log σ ( Δ r ) = − log σ ( − 0.23 β ) L = -\log \sigma(\Delta r) = -\log \sigma(-0.23\beta) L=−logσ(Δr)=−logσ(−0.23β)
The optimization encourages increasing the likelihood of ( y w y_w yw ) while reducing ( y l y_l yl ).
DPO vs PPO: Key Differences
| Aspect | DPO | PPO |
|---|---|---|
| Reward Model | Implicitly modeled via log-probabilities. | Requires an explicit, learned reward model. |
| Algorithm Type | Maximum Likelihood Estimation (MLE). | Reinforcement Learning with Policy Gradients. |
| Training Complexity | Simpler and requires fewer hyperparameters. | More complex with value function updates and clipping mechanisms. |
| Stability | More stable due to direct optimization. | Requires careful tuning to avoid divergence. |
| Data Requirement | Relies on preference data directly. | Requires preference data and rollout data for updates. |
| KL Regularization | Controlled by parameter ( β \beta β ). | Controlled by PPO clipping. |
Why is DPO Effective?
- Simplified Training Process: No need for reward model training or complex PPO pipelines.
- Implicit Reward Modeling: Avoids separate reward models and leverages pre-trained probabilities.
- Theoretical Guarantees: Based on Bradley-Terry models, ensuring consistency under reasonable assumptions.
- Practical Applicability: Compatible with public preference datasets without requiring new data collection.
Implementation Example
import torch
import torch.nn.functional as Fdef dpo_loss(pi_logps, ref_logps, yw_idxs, yl_idxs, beta):pi_yw_logps, pi_yl_logps = pi_logps[yw_idxs], pi_logps[yl_idxs]ref_yw_logps, ref_yl_logps = ref_logps[yw_idxs], ref_logps[yl_idxs]pi_logratios = pi_yw_logps - pi_yl_logpsref_logratios = ref_yw_logps - ref_yl_logpslosses = -F.logsigmoid(beta * (pi_logratios - ref_logratios))rewards = beta * (pi_logps - ref_logps).detach()return losses, rewards
Conclusion
DPO offers a lightweight alternative to PPO for preference optimization by directly leveraging preference data without relying on complex reinforcement learning frameworks. It is particularly effective for aligning language models with human preferences and offers theoretical guarantees grounded in Bradley-Terry models. Given its simplicity and effectiveness, DPO is increasingly used for tasks requiring preference-based fine-tuning of large language models.
后记
2024年12月26日20点52分于上海,在GPT4o大模型辅助下完成。
相关文章:
DPO(Direct Preference Optimization)算法解释:中英双语
中文版 DPO paper: https://arxiv.org/pdf/2305.18290 DPO 算法详解:从理论到实现 1. 什么是 DPO? DPO(Direct Preference Optimization)是一种直接基于人类偏好进行优化的算法,旨在解决从人类偏好数据中训练出表现…...
Hostapd2.11解析笔记
最近在调试Hostapd,尝试通过配置使能一个支持MLO的AP,不过不知道hostapd conf里面哪些选项开启后可以使能,所以对Hostapd做一个整体解析. 简介 hostapd 是用于接入点和身份验证服务器的用户空间守护程序。它实现 IEEE 802.11 接入点管理、IEEE 802.1X/WPA/WPA2/WPA3/EAP 身份…...
js控制文字溢出显示省略号
.text{display: -webkit-box;overflow: hidden;white-space: normal;text-overflow: ellipsis;word-wrap: break-word;-webkit-line-clamp: 2;-webkit-box-orient: vertical; }本人有个需求就是在一个盒子内有一段文本,然后控制文本显示两行,第二行要显示…...
WPF+MVVM案例实战与特效(四十七)-实现一个路径绘图的自定义按钮控件
文章目录 1、案例效果2、创建自定义 PathButton 控件1、定义 PathButton 类2、设计样式与控件模板3、代码解释3、控件使用4、直接在 XAML 中绑定命令3、源代码获取4、总结1、案例效果 2、创建自定义 PathButton 控件 1、定义 PathButton 类 首先,我们需要创建一个新的类 Pat…...
操作002:HelloWorld
文章目录 操作002:HelloWorld一、目标二、具体操作1、创建Java工程①消息发送端(生产者)②消息接收端(消费者)③添加依赖 2、发送消息①Java代码②查看效果 3、接收消息①Java代码②控制台打印③查看后台管理界面 操作…...
odoo中@api.model, @api.depends和@api.onchange 装饰器的区别
文章目录 1. api.model用途特点示例 2. api.depends用途特点示例 3. api.onchange用途特点示例 总结 在 Odoo 中,装饰器(decorators)用于修饰方法,以指定它们的行为和触发条件。api.model、api.depends 和 api.onchange 是三个常用…...
有哪些精益工具可以帮助企业实现转型?
为了在激烈的市场竞争中立于不败之地,许多企业开始寻求通过精益转型来优化运营、降低成本、提高效率和客户满意度。然而,精益转型并非一蹴而就,而是需要一系列精益工具的辅助,这些工具能够帮助企业识别浪费、优化流程、提升质量&a…...
以太网帧结构
以太网帧结构 目前,我们局域网当中应用最广的技术或者协议啊,就是以太网。我们首先来看一下以太网的真结构。这块内容这里边再系统的来给大家去展开说一下,以太网真格式就如下面这个图。所示前面有八个字节,是用于时钟同步的&…...
QT调用Sqlite数据库
QT设计UI界面,后台访问数据库,实现数据库数据的增删改查。 零售商店系统 数据库表: 分别是顾客表,订单详情表,订单表,商品表 表内字段详情如下: 在QT的Pro文件中添加sql,然后添加头…...
前端
前端页面 Web页面 PC端程序页面 移动端APP页面 ... HTML页面 HTML超文本标记页面 超文本:文本,声音,图片,视频,表格,链接 标记:由许多标签组成 HTML页面运行到浏览器上面 vscode便捷插件使用 vs…...
【Git】—— 使用git操作远程仓库(gitee)
目录 一、远程仓库常用命令 1、从远程仓库克隆项目 2、查看关联的远程仓库 3、添加关联的远程仓库 4、移除关联的远程仓库 5、将本地仓库推送到远程仓库 6、从远程仓库拉取项目 二、分支命令 1、查询分支 2、创建分支 3、切换分支 4、推送到远程分支 5、合并分支 …...
Paddler负载均衡器
Paddler负载均衡器 Paddler本身是用Go语言编写的,没有直接的Python接口,但可以通过以下方式在Python中使用: 执行命令行调用 在Python中可以使用 subprocess 模块来调用Paddler的命令行工具,实现负载均衡功能 。例如: import subprocessdef start_paddler_agent():com…...
OSCP - Proving Grounds - Slort
主要知识点 文件包含 windows的reveseshell 具体步骤 执行nmap,依旧是很多端口开放,尝试了ftp,smb等均失败 Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-10-13 12:00 UTC Nmap scan report for 192.168.53.53 Host is up (0.00095s latency). Not sho…...
YoloV9改进策略:Head改进|DynamicHead,利用注意力机制统一目标检测头部|即插即用
摘要 论文介绍 本文介绍了一种名为DynamicHead的模块,该模块旨在通过注意力机制统一目标检测头部,以提升目标检测的性能。论文详细阐述了DynamicHead的工作原理,并通过实验证明了其在COCO基准测试上的有效性和效率。 创新点 DynamicHead模块的创新之处在于它首次尝试在一…...
BFD综合详细实验配置案例
前言 本实验的目的是通过配置BGP(边界网关协议)、OSPF(开放式最短路径优先协议)、VRRP(虚拟路由冗余协议)以及BFD(双向转发检测)等网络协议,模拟企业级网络环境中的多协…...
自然语言处理与知识图谱的融合与应用
目录 前言1. 知识图谱与自然语言处理的关系1.1 知识图谱的定义与特点1.2 自然语言处理的核心任务1.3 二者的互补性 2. NLP在知识图谱构建中的应用2.1 信息抽取2.1.1 实体识别2.1.2 关系抽取2.1.3 属性抽取 2.2 知识融合2.3 知识推理 3. NLP与知识图谱融合的实际应用3.1 智能问答…...
c# RSA加解密工具,.netRSA加解密工具
软件介绍 名称: c# RSA加解密工具,.netRSA加解密工具依赖.net版本: .net 8.0工具类型: WinForm源码下载 c# RSA加解密工具,.netRSA加解密工具 依赖项 WinFormsRSA.csproj <Project...
Metricbeat安装教程——Linux——Metricbeat监控ES集群
Metricbeat安装教程——Linux 一、安装 下载安装包: 官网下载地址:https://www.elastic.co/cn/downloads/beats/metricbeat 上传包到linux 切换到安装目录下 解压:tar -zxvf metricbeat-7.17.1-linux-x86_64.tar.gz 重命名安装文件夹 mv met…...
一万多字拆解java中——“ 注解 ”的一切(三)(已完结)
前言: 咱们书接上回,上次按照框架讲了 第一篇,我们讲到了: ①注解的引入(简单概述):在jdk5.0的时候 ②注解与注释的区别: 注释 是为了帮助人类阅读代码,不会对程序的执…...
记一次rac故障原因分析(虚拟化平台)
一 现象描述 XX客户于1月14号凌晨业务中断,检查数据库发现数据库集群宕机。 XX客户于2月14号春节初五早上业务异常,连接数据库无响应。 二 问题详细诊断 1月14号故障 1月14号凌晨2点,客户反馈业务中断,发现节点1无法连接&…...
uniapp 对接腾讯云IM群组成员管理(增删改查)
UniApp 实战:腾讯云IM群组成员管理(增删改查) 一、前言 在社交类App开发中,群组成员管理是核心功能之一。本文将基于UniApp框架,结合腾讯云IM SDK,详细讲解如何实现群组成员的增删改查全流程。 权限校验…...
【大模型RAG】拍照搜题技术架构速览:三层管道、两级检索、兜底大模型
摘要 拍照搜题系统采用“三层管道(多模态 OCR → 语义检索 → 答案渲染)、两级检索(倒排 BM25 向量 HNSW)并以大语言模型兜底”的整体框架: 多模态 OCR 层 将题目图片经过超分、去噪、倾斜校正后,分别用…...
Java 语言特性(面试系列1)
一、面向对象编程 1. 封装(Encapsulation) 定义:将数据(属性)和操作数据的方法绑定在一起,通过访问控制符(private、protected、public)隐藏内部实现细节。示例: public …...
uni-app学习笔记二十二---使用vite.config.js全局导入常用依赖
在前面的练习中,每个页面需要使用ref,onShow等生命周期钩子函数时都需要像下面这样导入 import {onMounted, ref} from "vue" 如果不想每个页面都导入,需要使用node.js命令npm安装unplugin-auto-import npm install unplugin-au…...
[ICLR 2022]How Much Can CLIP Benefit Vision-and-Language Tasks?
论文网址:pdf 英文是纯手打的!论文原文的summarizing and paraphrasing。可能会出现难以避免的拼写错误和语法错误,若有发现欢迎评论指正!文章偏向于笔记,谨慎食用 目录 1. 心得 2. 论文逐段精读 2.1. Abstract 2…...
屋顶变身“发电站” ,中天合创屋面分布式光伏发电项目顺利并网!
5月28日,中天合创屋面分布式光伏发电项目顺利并网发电,该项目位于内蒙古自治区鄂尔多斯市乌审旗,项目利用中天合创聚乙烯、聚丙烯仓库屋面作为场地建设光伏电站,总装机容量为9.96MWp。 项目投运后,每年可节约标煤3670…...
在鸿蒙HarmonyOS 5中使用DevEco Studio实现录音机应用
1. 项目配置与权限设置 1.1 配置module.json5 {"module": {"requestPermissions": [{"name": "ohos.permission.MICROPHONE","reason": "录音需要麦克风权限"},{"name": "ohos.permission.WRITE…...
学习 Hooks【Plan - June - Week 2】
一、React API React 提供了丰富的核心 API,用于创建组件、管理状态、处理副作用、优化性能等。本文档总结 React 常用的 API 方法和组件。 1. React 核心 API React.createElement(type, props, …children) 用于创建 React 元素,JSX 会被编译成该函数…...
数据库优化实战指南:提升性能的黄金法则
在现代软件系统中,数据库性能直接影响应用的响应速度和用户体验。面对数据量激增、访问压力增大,数据库性能瓶颈经常成为项目痛点。如何科学有效地优化数据库,提升查询效率和系统稳定性,是每位开发与运维人员必备的技能。 本文结…...
【见合八方平面波导外腔激光器专题系列】用于干涉光纤传感的低噪声平面波导外腔激光器2
----翻译自Mazin Alalus等人的文章 摘要 1550 nm DWDM 平面波导外腔激光器具有低相位/频率噪声、窄线宽和低 RIN 等特点。该腔体包括一个半导体增益芯片和一个带布拉格光栅的平面光波电路波导,采用 14 引脚蝶形封装。这种平面波导外腔激光器设计用于在振动和恶劣的…...
