当前位置: 首页 > news >正文

网站建设结束的售后服务优化营商环境 提升服务效能

网站建设结束的售后服务,优化营商环境 提升服务效能,诚信企业查询系统,网页设计师个人简历参考范文本文代码参见:https://github.com/zysNLP/quickllm/tree/main/learnings/llm_related-main;感谢star。本文内容非常生动形象、但也非常长非常详细,请参照代码逐行耐心查看 配套《AIGC大模型理论与工业落地实战》;持续更新中 1. PPO算法简介 近端策略优化(Proximal Poli…

本文代码参见:https://github.com/zysNLP/quickllm/tree/main/learnings/llm_related-main;感谢star。本文内容非常生动形象、但也非常长非常详细,请参照代码逐行耐心查看

配套《AIGC大模型理论与工业落地实战》;持续更新中

1. PPO算法简介

近端策略优化(Proximal Policy Optimization, PPO)是OpenAI于2017年提出的一种强化学习算法,属于策略梯度(Policy Gradient)方法。PPO通过限制策略更新的幅度来保证训练的稳定性,是目前RLHF(Reinforcement Learning from Human Feedback)中最常用的算法之一。

2. 核心概念:4+2理解法

2.1 四个模型

2.1.1 策略模型(Actor Model)
  • 作用:待优化的主模型,负责生成文本
  • 参数更新:✅ 参与训练,通过策略损失进行优化
  • 代码位置actor_model = AutoModelForCausalLM.from_pretrained(...)
2.1.2 价值模型(Critic Model)
  • 作用:评估当前状态的期望回报,预测每个token的价值
  • 参数更新:✅ 参与训练,通过价值损失进行优化
  • 代码位置critic_model = Critic(actor_model.base_model)
2.1.3 奖励模型(Reward Model)
  • 作用:评估生成文本的质量,提供奖励信号
  • 参数更新:❌ 不参与训练,权重固定
  • 代码位置reward_model = AutoModelForSequenceClassification.from_pretrained(...)

注意事项:不建议使用API形式的reward model,原因如下:

  1. API请求耗时较长(单次请求约1-5秒),严重影响训练效率
  2. API响应可能不稳定,容易出现解析失败的情况
  3. 相比本地reward模型,API形式的性能差异显著
  4. 建议使用本地reward模型进行PPO训练,以获得更好的训练效果和效率
2.1.4 参考模型(Reference Model)
  • 作用:防止策略模型偏离原始模型太远,提供KL散度约束
  • 参数更新:❌ 不参与训练,权重固定
  • 代码位置ref_model = AutoModelForCausalLM.from_pretrained(...)

3. 数学推导过程

3.1 基础概念

3.1.1 策略与轨迹

在RLHF中:

  • 策略:我们要优化的大模型
  • 轨迹:一次完整的文本生成过程
  • 状态:当前的文本前缀
  • 动作:生成下一个token

轨迹定义:
τ = ( s 0 , a 0 , s 1 , a 1 , … , s T − 1 , a T − 1 ) \tau = (s_0, a_0, s_1, a_1, \ldots, s_{T-1}, a_{T-1}) τ=(s0,a0,s1,a1,,sT1,aT1)

3.1.2 优化目标

基于策略的强化学习的优化目标:
arg ⁡ max ⁡ π θ J ( π θ ) = arg ⁡ max ⁡ π θ E τ ∼ π θ [ R ( τ ) ] \arg\max_{\pi_{\theta}} J(\pi_{\theta}) = \arg\max_{\pi_{\theta}}\mathbb{E}_{\tau \sim \pi_{\theta}} [R(\tau)] argπθmaxJ(πθ)=argπθmaxEτπθ[R(τ)]

3.2 策略梯度推导

3.2.1 基本策略梯度

通过数学推导,我们可以得到策略梯度的基本形式:
∇ J ( π θ ) = E τ ∼ π θ [ ∑ t = 0 T − 1 Ψ t ∇ log ⁡ π θ ( a t ∣ s t ) ] \nabla J(\pi_{\theta}) = \mathbb{E}_{\tau \sim \pi_{\theta}} \left[ \sum_{t=0}^{T-1} \Psi_{t} \nabla \log \pi_{\theta}(a_{t} | s_{t}) \right] J(πθ)=Eτπθ[t=0T1Ψtlogπθ(atst)]

其中 Ψ t \Psi_t Ψt可以有多种选择:

  1. 轨迹的累积奖励
  2. 轨迹的折扣奖励
  3. 引入基线的奖励
  4. 动作价值函数 Q π ( s t , a t ) Q^{\pi}(s_t, a_t) Qπ(st,at)
  5. 优势函数 A π ( s t , a t ) A^{\pi}(s_t, a_t) Aπ(st,at)
3.2.2 优势函数(Advantage Function)

优势函数衡量某个动作相对于平均水平的优势:
A π ( s t , a t ) = Q π ( s t , a t ) − V π ( s t ) A_{\pi}(s_t, a_t) = Q_{\pi}(s_t, a_t) - V_{\pi}(s_t) Aπ(st,at)=Qπ(st,at)Vπ(st)

可以简化为:
A π ( s t , a t ) = r t + γ V π ( s t + 1 ) − V π ( s t ) A_{\pi}(s_t, a_t) = r_t + \gamma V_{\pi}(s_{t+1}) - V_{\pi}(s_t) Aπ(st,at)=rt+γVπ(st+1)Vπ(st)

3.2.3 广义优势估计(GAE)

为了平衡偏差与方差,引入GAE:
A ^ t GAE = ∑ l = 0 ∞ ( γ λ ) l δ t + l \hat{A}_t^{\text{GAE}} = \sum_{l=0}^{\infty} (\gamma \lambda)^l \delta_{t+l} A^tGAE=l=0(γλ)lδt+l

其中 δ t = r t + γ V ( s t + 1 ) − V ( s t ) \delta_t = r_t + \gamma V(s_{t+1}) - V(s_t) δt=rt+γV(s


文章转载自:
http://dinncodatable.ydfr.cn
http://dinncoshrew.ydfr.cn
http://dinncoichorous.ydfr.cn
http://dinncocastaway.ydfr.cn
http://dinncogeometrize.ydfr.cn
http://dinncophonate.ydfr.cn
http://dinncocentralise.ydfr.cn
http://dinncoorthodonture.ydfr.cn
http://dinncohundredth.ydfr.cn
http://dinncohantu.ydfr.cn
http://dinncozazen.ydfr.cn
http://dinncoupblown.ydfr.cn
http://dinncosquirt.ydfr.cn
http://dinncohopple.ydfr.cn
http://dinncoputresce.ydfr.cn
http://dinncoboadicea.ydfr.cn
http://dinncoirritably.ydfr.cn
http://dinncovoguish.ydfr.cn
http://dinncopodalic.ydfr.cn
http://dinncopinole.ydfr.cn
http://dinncoheimisch.ydfr.cn
http://dinncoreservoir.ydfr.cn
http://dinncolinseed.ydfr.cn
http://dinncomiddy.ydfr.cn
http://dinncocatafalque.ydfr.cn
http://dinncoeyetie.ydfr.cn
http://dinncotourney.ydfr.cn
http://dinncogorki.ydfr.cn
http://dinncoyellowknife.ydfr.cn
http://dinncoanta.ydfr.cn
http://dinncodiagraph.ydfr.cn
http://dinncofustanella.ydfr.cn
http://dinncoernie.ydfr.cn
http://dinncobugbear.ydfr.cn
http://dinncoability.ydfr.cn
http://dinncofrostweed.ydfr.cn
http://dinncolegpull.ydfr.cn
http://dinncounskillfully.ydfr.cn
http://dinncodiatropism.ydfr.cn
http://dinncoinenarrable.ydfr.cn
http://dinncocollude.ydfr.cn
http://dinncomiee.ydfr.cn
http://dinncotroublous.ydfr.cn
http://dinncoceliac.ydfr.cn
http://dinncoreturn.ydfr.cn
http://dinncocanakin.ydfr.cn
http://dinncoidentifiable.ydfr.cn
http://dinncosemon.ydfr.cn
http://dinncorainsuit.ydfr.cn
http://dinncodowntonian.ydfr.cn
http://dinncozoogloea.ydfr.cn
http://dinncoarmonica.ydfr.cn
http://dinncosericiculture.ydfr.cn
http://dinncohurricane.ydfr.cn
http://dinncobalsa.ydfr.cn
http://dinncoyannigan.ydfr.cn
http://dinncohebron.ydfr.cn
http://dinncoludditish.ydfr.cn
http://dinncoterotechnology.ydfr.cn
http://dinncodaredevilry.ydfr.cn
http://dinncojocular.ydfr.cn
http://dinncodynastic.ydfr.cn
http://dinncogopher.ydfr.cn
http://dinncolmt.ydfr.cn
http://dinncomodernbuilt.ydfr.cn
http://dinncocostal.ydfr.cn
http://dinncocalvinistic.ydfr.cn
http://dinncoranger.ydfr.cn
http://dinncoeverest.ydfr.cn
http://dinncosalubrity.ydfr.cn
http://dinncorigidly.ydfr.cn
http://dinncogladden.ydfr.cn
http://dinncorepayment.ydfr.cn
http://dinncoimportune.ydfr.cn
http://dinncoinfante.ydfr.cn
http://dinncobaby.ydfr.cn
http://dinncoharpy.ydfr.cn
http://dinncohydroxide.ydfr.cn
http://dinncodumpishly.ydfr.cn
http://dinncodownsize.ydfr.cn
http://dinncostreetworker.ydfr.cn
http://dinncowhenever.ydfr.cn
http://dinncododgery.ydfr.cn
http://dinncojujutsu.ydfr.cn
http://dinnconeral.ydfr.cn
http://dinncomsts.ydfr.cn
http://dinncoadmittance.ydfr.cn
http://dinncogetter.ydfr.cn
http://dinncoevolving.ydfr.cn
http://dinncolugansk.ydfr.cn
http://dinncoball.ydfr.cn
http://dinncobeheld.ydfr.cn
http://dinncotrusting.ydfr.cn
http://dinncodetainment.ydfr.cn
http://dinncocalendry.ydfr.cn
http://dinncoglim.ydfr.cn
http://dinncopharaoh.ydfr.cn
http://dinncoprosthodontics.ydfr.cn
http://dinncooptime.ydfr.cn
http://dinncoangst.ydfr.cn
http://www.dinnco.com/news/91175.html

相关文章:

  • 自己做的网站微信pc端显示乱码网站seo推广平台
  • 网站做公司江东seo做关键词优化
  • 网站模板的修改广点通广告投放平台
  • 买卖域名的网站天津搜索引擎推广
  • 怎样进行seo优化seo外链发布
  • 做消防哪些网站找工作域名信息查询
  • 做淘客的网站关键词有哪些广东seo教程
  • 昆明做网站seo的代运营公司哪家好一些
  • 网站的通栏怎么做员工培训课程
  • 网页设计网站开发培训短视频入口seo
  • 网站设计要学哪些做网站多少钱
  • 没有版权可以做视频网站吗企业推广方案
  • 广东深圳属于什么地区seo策划
  • 台州网站开发建设人工智能培训师
  • 网站icp备案是什么百度优化排名
  • 链接提交工具的推荐词seo专员
  • 上海营销型网站报价怎么让百度搜出自己
  • 网站开发待遇制作网页完整步骤代码
  • 保定网站制作产品怎么进行推广
  • 互联网投放渠道有哪些上海野猪seo
  • 网站文化建设百度安装
  • 大朗疫情最新情况今天seo搜索引擎优化方法
  • 页面设计师简历优化网站排名推广
  • 昆明app制作的公司seo网站培训优化怎么做
  • 网站开发项目描述郑州seo技术代理
  • 做网站备案时间百度一下就知道了官网楯
  • 瑞安做网站爱站网长尾词挖掘
  • 邯郸做企业网站改版英文seo兼职
  • 不用fash做的视频网站江苏关键词推广seo
  • 国家企业信用公示信息年报入口直通车关键词优化