CGE:基于Causal LLM的Code Embedding模型

Debain-12.9使用vllm部署内嵌模型/embedding 阅读详情

近日,CodeFuse-CGE 项目在外滩大会展出,吸引了众多技术、产品从业者的到访,部分参观者表示“文搜代码”令人耳目一新,期待模型后续的表现。

以下是 CodeFuse-CGE 项目的相关开源介绍,如果对这部分内容感兴趣,欢迎访问我们的项目主页 GitHub - codefuse-ai/CodeFuse-CGE 为我们点赞,支持我们的项目。

01简介

Code Embedding 是一种将代码片段转化为向量表示的技术。这种表示形式使得机器学习模型能够更好地理解和处理代码,在自动化程序分析、代码搜索、代码补全,以及自动化测试等领域都起到非常重要的作用。大语言模型(Large Language Models)因为其在大量的语言数据上预训练,可以获得对语义细微表示的能力。最近,LLMs 在代码生成、代码补全等任务上都有非常出色的表现。

目前 Code Embedding 模型主要基于 Encoder 架构,如 CodeBert、Unixcoder 等。又或者基于 Encoder-Decoder 架构,如 CodeT5、CodeT5+ 等。然而局限于架构设计和模型大小,他们很难获取到更丰富的语义表示能力。

我们以 CodeQwen1.5-7B-Chat 和 Phi-3.5-mini-instruct 模型作为基座模型,通过一个交叉注意力计算模块来提取输入序列的 Embedding,将文本表征和代码表征投射到同一空间中。我们的方法可以激发出基座模型强大的代码、文本的语义表示能力。实验表明我们的方法在 CSN 和 AdvTest 这 2 个 NL2Code Benchmarks 上都有着超越 SOTA 的能力。我们将开源 CGE-Large 和 CGE-Small 两种大小的模型。

TLDR

CGE 即 Code General Embedding。我们提出了一种基于大语言模型的获取 Embedding 方案,通过 Lora 微调来借助大语言模型的语义能力,激发其语义表征能力,在 2 个 NL2Code Benchmarks 上达到了 SOTA 的表现。

🏡Homepage:

https://github.com/codefuse-ai/CodeFuse-CGE

hCGE

(Please give us your support with a Star🌟 + Fork🚀 + Watch 👀)

02 开源模型

CodeFuse-CGE-Large

huggingface 地址

https://huggingface.co/codefuse-ai/CodeFuse-CGE-Large

Model Configuration

  • Base Model:CodeQwen1.5-7B-Chat
  • Model Size:7B
  • Embedding Dimension:1024

Requirements

flash_attn==2.4.2
torch==2.1.0
accelerate==0.28.0
transformers==4.39.2 
vllm=0.5.3

CodeFuse-CGE-Small

huggingface 地址

Model Configuration

  • Base Model:Phi-3.5-mini-instruct
  • Model Size:3.8B
  • Embedding Dimension:1024

Requirements

flash_attn==2.4.2
torch==2.1.0
accelerate==0.28.0
transformers>=4.43.0

How to Use?

Transformers

import torch
from transformers import AutoTokenizer, AutoModel

model_name_or_path = "codefuse-ai/CodeFuse-CGE-Large"
model = AutoModel.from_pretrained(model_name_or_path, trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained(model_name_or_path, trust_remote_code=True, truncation_side='right', padding_side='right')

if torch.cuda.is_available():
    device = 'cuda'
else:
    device = 'cpu'
model.to(device)

prefix_dict =  {'python':{'query':'Retrieve the Python code that solves the following query:', 'passage':'Python code:'},
                'java':{'query':'Retrieve the Java code that solves the following query:', 'passage':'Java code:'},
                'go':{'query':'Retrieve the Go code that solves the following query:', 'passage':'Go code:'},
                'c++':{'query':'Retrieve the C++ code that solves the following query:', 'passage':'C++ code:'},
                'javascript':{'query':'Retrieve the Javascript code that solves the following query:', 'passage':'Javascript code:'},
                'php':{'query':'Retrieve the PHP code that solves the following query:', 'passage':'PHP code:'},
                'ruby':{'query':'Retrieve the Ruby code that solves the following query:', 'passage':'Ruby code:'},
                'default':{'query':'Retrieve the code that solves the following query:', 'passage':'Code:'}
                }

text = ["Writes a Boolean to the stream.",
        "def writeBoolean(self, n): t = TYPE_BOOL_TRUE if n is False: t = TYPE_BOOL_FALSE self.stream.write(t)"]
text[0] += prefix_dict['python']['query']
text[1] += prefix_dict['python']['passage']
embed = model.encode(tokenizer, text)
score = embed[0] @ embed[1].T
print("score", score)

Vllm

我们同时适配了 vllm 的部署,来减少部署时的时延。可参考我们的 github 仓库:https://github.com/codefuse-ai/CodeFuse-CGE

from vllm import ModelRegistry
from utils.vllm_codefuse_cge_large import CodeFuse_CGE_Large
from vllm.model_executor.models import ModelRegistry
from vllm import LLM

def always_true_is_embedding_model(model_arch: str) -> bool:
    return True
ModelRegistry.is_embedding_model = always_true_is_embedding_model
ModelRegistry.register_model("CodeFuse_CGE_Large", CodeFuse_CGE_Large)


model_name_or_path = "codefuse-ai/CodeFuse-CGE-Large"
model = LLM(model=model_name_or_path, trust_remote_code=True, enforce_eager=True, enable_chunked_prefill=False)
prefix_dict =  {'python':{'query':'Retrieve the Python code that solves the following query:', 'passage':'Python code:'},
                'java':{'query':'Retrieve the Java code that solves the following query:', 'passage':'Java code:'},
                'go':{'query':'Retrieve the Go code that solves the following query:', 'passage':'Go code:'},
                'c++':{'query':'Retrieve the C++ code that solves the following query:', 'passage':'C++ code:'},
                'javascript':{'query':'Retrieve the Javascript code that solves the following query:', 'passage':'Javascript code:'},
                'php':{'query':'Retrieve the PHP code that solves the following query:', 'passage':'PHP code:'},
                'ruby':{'query':'Retrieve the Ruby code that solves the following query:', 'passage':'Ruby code:'},
                'default':{'query':'Retrieve the code that solves the following query:', 'passage':'Code:'}
                }

text = ["Return the best fit based on rsquared",
        "def find_best_rsquared ( list_of_fits ) : res = sorted ( list_of_fits , key = lambda x : x . rsquared ) return res [ - 1 ]"]
text[0] += prefix_dict['python']['query']
text[1] += prefix_dict['python']['passage']
embed_0 = model.encode([text[0]])[0].outputs.embedding
embed_1 = model.encode([text[1]])[0].outputs.embedding
注:1、在适配 Vllm 之后,模型的输入只能设置为批量大小为 1;否则会导致数组溢出错误。2、目前仅对 CodeFuse-CGE-Large 模型进行了适配,CodeFuse-CGE-Small 模型的支持将在不久后提供。

03 实验

我们以 CodeQwen1.5-7B-Chat 作为模型底座,主要在 Text2Code Retrieval 这个任务上去验证算法的有效性。用于评测的数据集包括:AdvTest、CSN 以及 CosQA 数据集。评测指标我们主要使用的 MRR。我们在 32 张 80 G A100 上运行训练。

实验结果

表1:NL2Code Benchmarks

表1:NL2Code Benchmarks

image.png

图1:NL2Code Benchmarks雷达图

从实验结果上看,CodeFuse-CGE-Large 的结果优于目前的SOTA,AdvTest 超过 CodeSAGE-Large 2.61%,在 CosQA 数据集上超过 CodeSAGE-Large 6.37% ,而在 CSN 数据集上,在 php 语言和 go 语言上和 CodeT5P-110M-embedding 表现出相当的水平,在其他语言上都超过 CodeT5P-110M-embedding 2%-4%,在 CSN 的平均水平上超过 CodeT5P-110M-embedding 1.8% 的水平。相比于目前在 Code Embedding 领域场景的两种架构, Encoder 以及 Encoder-Decoder 模型,我们模型的结果都有显著优越的结果,而对目前 OpenAI 商用的 Embedding API,我们的结果也在各个方面都超过了商用 Embedding API 的水平。

同时,我们也训练了输出更小维度的 Embedding 模型,从表 1 中可以看到,输出 384 维的模型在 AdvTest 和 CosQA 数据集上相比输出 1024 维的模型效果相当,只是在 CSN 数据集上有 3% 的下降。在实际使用中,如果考虑到存储的问题,可以使用输出 384 维的 Embedding 模型来减少存储压力,同时不会降低太多的性能。

CodeFuse-CGE-Small 的结果相较于 CodeFuse-CGE-Large 在 AdvTest 和 CSN 数据集上分别有着 9% 和 6% 的效果下降,在 CosQA 上有着 2% 的提升。如果考虑到实际使用的时延以及部署机器的限制,可以考虑使用 CodeFuse-CGE-Small 模型。

04 总结

我们基于 Code LLM 作为底座模型,通过 PMA 提取输入 text 或者 token 的 Embedding,在经过 LoRA 微调后,得到了一个对齐 text 和 code 之间语义的 Embedding 模型。实验结果表明,在 Text2Code Retrieval 测试集上都超越了目前 SOTA 的结果。

参考文献

[1] Zhu, Yutao, et al. "Large language models for information retrieval: A survey." arxiv preprint arxiv:2308.07107 (2023).

[2] Zhang, Dejiao, et al. "Code representation learning at scale." arXiv preprint arXiv:2402.01935 (2024).

[3] Feng, Zhangyin, et al. "Codebert: A pre-trained model for programming and natural languages." arXiv preprint arXiv:2002.08155 (2020).

[4] Wang, Yue, et al. "Codet5+: Open code large language models for code understanding and generation." arXiv preprint arXiv:2305.07922 (2023).

[5] Guo, Daya, et al. "Graphcodebert: Pre-training code representations with data flow." arXiv preprint arXiv:2009.08366 (2020).

[6] Zhou, Haoyi, et al. "Informer: Beyond efficient transformer for long sequence time-series forecasting." Proceedings of the AAAI conference on artificial intelligence. Vol. 35. No. 12. 2021.

[7] Guo, Daya, et al. "Unixcoder: Unified cross-modal pre-training for code representation." arXiv preprint arXiv:2203.03850 (2022).

CodeFuse 相关模型和数据集陆续开源中,如果您喜欢我们的工作,欢迎试用、指正错误和贡献代码,也可以给我们的项目增加 Star ,支持我们

技术交流与探讨,你还可以加入我们的用户交流群

code embedding研究系列二-基于AST的embedding Code Embedding系列 - AST embedding一.相关论文1.Convolutional Neural Networks over Tree Structuresfor Programming Language Processing数据集用到的工具整体架构 在Embedding技术提出后,NLP得到了极大的提升,在上一篇中我们讨论了如何将embedding技术应用到SE(Software Engineering)领域。这对于源代码分析任务(克隆检测,bug检测等)有极大的意义,在上一篇中同 阅读详情

相关推荐

基于CGE模型的碳税政策影响研究

基于2012 年社会核算矩阵( SAM),采用增加碳税模块的可计算一般均衡模型 (CGE),构建了测算中国碳税政策影响的涵盖42个部门的动态递归CGE 模型(其中包含4个化石能源生产部门和1个电力能源生产部门),以此来分析不同税率情境下碳税政策实施对我 国国内生产总值(GDP)、能源消费和碳减排的动态影响。结果表明:征收碳税将对我国GDP造成负面影响,且随着税率的不断升高,GDP的下降率将不断增大。同时,碳税政策的实施使得高 碳排放行业能源消费量明显减少,并提高了清洁能源的使用量,而总的二氧化碳减排量则随着

weixin_54697010的博客 3069

code embedding研究系列一-基于token的embedding

Code Embedding1.Automated software vulnerability detection with machine learning数据集来源数据集预处理分类方法获取token向量化表示分类模型参考文献 NLP中embedding无处不在,embedding将大型稀疏向量转换为保留语义关系的低维空间。在源代码研究领域(源代码分类,源代码克隆检测,变量,方法等重命名等)也会需要用到embedding,即code embedding。 code embedding可以分成很多种: 1

qq_44370676的博客 8210

vLLM部署实战:从零搞定BAAI/bge-m3 embedding模型(含Docker与K8s双方案)

本文详细介绍了如何使用vLLM框架部署BAAI/bge-m3 embedding模型,涵盖Docker与Kubernetes双方案,特别针对国内开发者优化模型下载路径和GPU资源调优。通过实战案例和性能测试,帮助开发者快速构建高效的语义搜索服务,提升企业知识管理和智能客服系统的响应速度与精准度。

weixin_28726671的博客 487

Code Embedding研究系列11-ContraFlow

一种Path-Sensitive的code embedding技术

qq_44370676的博客 1944

Large Language Models Meet NL2Code: A Survey

从自然语言描述(NL2Code)生成代码的任务被认为是代码智能中一个紧迫而重要的挑战。由于预训练技术的快速发展,大量的大型语言模型被提出用于代码,激发了NL2Code的进步。为了促进该领域的进一步研究和应用,在本文中,我们对NL2Code的27个现有大型语言模型进行了全面调查,并回顾了基准和指标。我们在HumanEval基准上提供了对所有现有模型的直观比较。通过深入的观察和分析,我们提供了一些见解,并得出结论,促成NL2Code大型语言模型成功的关键因素是“大尺寸、优质数据、专家调优”。

c_cpp_csharp的专栏 895

动态 CGE Model,动态cge模型源码.zip

动态 CGE Model,动态cge模型源码

vLLM实战部署embedding、reranker、senseVoice模型(上)

概述:modelscope、embedding、postman测试、py脚本测试、reranker、语音;

lonelymanontheway的博客 8454

Impala>Impala安装部署

文章目录1.安装前提2.下载安装包、依赖包3.虚拟机新增磁盘(可选)4.配置本地yum源5.安装Impala6.修改Hadoop、Hive配置7.修改impala配置8.启动、关闭impala服务 1.安装前提 集群提前安装好hadoop,hive。 hive安装包scp在所有需要安装impala的节点上,因为impala需要引用hive的依赖包。 hadoop框架需要支持C程序访问接口,查看下...

qq_44509920的博客 837

双碳”目标下资源环境中的可计算一般均衡(CGE)模型技术应用

在“双碳”目标下,可计算一般均衡(CGE)模型在资源环境中的应用具有重要意义。

AAIshangyanxiu的博客 629

从原理到代码:拆解UniFormer中动态位置嵌入(DPE)的3D卷积实现

本文深入解析了UniFormer模型中动态位置嵌入(DPE)模块的3D卷积实现原理与代码。DPE通过一个轻量的3D深度可分离卷积,替代传统静态位置编码,使模型能自动学习视频数据的时空位置关系。文章对比了其与Swin Transformer相对位置偏置的优劣,并提供了PyTorch实现代码与高级定制方案,为视频理解任务提供了高效灵活的动态位置编码解决方案。

weixin_29207149的博客 309

智慧工地算法视频分析服务器区域入侵检测AI视频分析技术在煤矿的实战应用

通过实时分析和处理井下视频资料,智慧矿山算法视频分析服务器不仅能够及时发现并预警人员违规行为和设备异常状况,还能够通过智能分析预防潜在的安全风险,从而显著提高煤矿的安全管理水平和生产效率。

EasyDarwin开源社区技术博客 559

【双碳系列】碳中和、碳排放、温室气体、弹手指、碳储量、碳循环及leap、cge、dice、openLCA模型

林业碳汇、电力、交通碳排放

weixin_xiao5kou4chang6kai4的博客 6832

告别数据丢失焦虑:用Python手把手实现Reed-Solomon码(附完整代码)

本文详细介绍了如何使用Python实现Reed-Solomon纠错码(RS码),帮助开发者有效防止数据丢失。通过基础编解码实战、文件保护方案和高级性能优化技巧,读者可以轻松掌握这一前向纠错技术,应用于物联网、文件存储和网络传输等场景,提升数据可靠性。

weixin_42527160的博客 222

用vllm快速部署大模型

在迅速发展的AI领域中,高效部署大型语言模型(LLM)对于许多应用程序至关重要。对于希望利用LLM力量的开发人员和组织来说,vLLM提供了一种简单、快速且经济高效的解决方案,用于在GPU上运行模型。本文将指导您完成vLLM的安装、在服务器上运行它以及将其集成到应用程序中的步骤。vLLM专为希望在其GPU上托管大型语言模型的人设计,这对于高吞吐量、并行处理和流式输出至关重要。无论您是在计算机上本地部署模型,还是在基于云的实例上部署,vLLM都提供了一个强大且可扩展的解决方案。

weixin_58753619的博客 4316

概念解析 | 雷达动态范围

这里存在一个动态范围的问题:强雷达发射信号和弱目标反射信号存在非常大的功率差异,比如传统的脉冲多普勒雷达动态范围可达90dB以上。随着上述技术的发展,预计未来十年雷达接收机动态范围将达到120dB以上,届时雷达的监视能力将得到极大增强。简单来说,雷达动态范围越大,表示接收机噪声越低,对强信号过载保护能力越强,就越能检测到弱信号目标。此外,部分新概念雷达对动态范围提出新的需求,如被动雷达动态范围需大于100dB。当前,随着阵列雷达和数字雷达技术的发展,对雷达接收机动态范围提出了更高要求。

NLOS的博客 1051

【tio-websocket】15、学习tio的第1步—tio-study

tio-study 是用于学习 t-io 的示范工程,tio-study 是入门 t-io 最好的方式!tio-study 工程演示的是一个典型的 TCP 长连接应用工程,分为 server(服务端) 和 client(客户端) 工程,server 和 client 共用 common(公共模块) 工程

JACKAL 1万+

【亲测免费】 推荐开源项目:NL2code - 自然语言到可执行代码的转换神器

推荐开源项目:NL2code - 自然语言到可执行代码的转换神器 项目介绍 NL2code是一个革命性的开源项目,它使用神经网络模型将自然语言描述转化为可执行的编程代码。这个项目源于2017年 ACL 大会上发表的研究成果,由 Pengcheng Yin 和 Graham Neubig 共同提出。通过训练和解码算法,NL2code 能够理解和生成符合语法规则的代码,为开发者提供了一种新颖而直观的方...

gitblog_00001的博客 1111

使用Simulink进行四足机器人的非线性动力学建模与仿真

四足机器人的运动包含多个自由度(DOF),包括腿部的摆动和支撑阶段的动力学特性。由于存在接触力、摩擦以及不同地形的影响,四足机器人的动力学行为呈现出高度的非线性特征。因此,构建准确的非线性动力学模型对于研究机器人的运动学和动力学特性至关重要。定义代表机器人状态的变量,如位置、速度、角度和角速度。matlab深色版本通过本指南,我们介绍了如何基于Simulink搭建一个四足机器人的非线性动力学模型,并进行了详细分析。

xiaoheshang_123的博客 311

code embedding研究系列八-CuBERT

Learning and Evaluating Contextual Embedding of Source Code一.概述二.数据集2.1.预训练数据集2.2.fine-tunning数据集三.源代码的tokenize四.任务4.1.预训练任务4.2.下游任务4.2.1.Variable-Misuse Classification4.2.2.Wrong Binary Operator4.2.3.Swapped Operand4.2.4.Function-Docstring Mismatch4.2.5.

qq_44370676的博客 2027

Oracle EBS 帐套(Ledger/SOB)如何定义会计主体、如何支撑多准则 / 多报告、组织与帐套的绑定关系、以及项目落地时的设计差异。下面从实现逻辑、核心要素、组织模型、多账簿、科目设计、项

本文对比了Oracle EBS R12与SAP S/4HANA在帐套(Ledger)设计上的核心差异。Oracle采用4C架构(科目/币种/日历/准则),帐套作为独立会计主体,主辅账物理隔离;SAP则以公司代码为主体,通过平行分类账在同一凭证中实现多准则核算。关键差异体现在:Oracle强调边界隔离,适合差异大的集团;SAP注重统一视图,适合实时合并需求。实施时需注意:Oracle避免过度建账套,SAP需统筹科目与维度设计。两者分别体现了"盒子"与"滤镜"的设计哲学。

金牌架构师 416

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

基于CGE模型我国低碳经济发展政策模拟分析程序源代码含数据+参考资料

可计算的一般均衡(Computable General Equilibrium,CGE)模型作为政策分析的有力工具,经过30多年的发展,已在世界上得到了广泛的应用,并逐渐发展成为应用经济学的一个分支。(完整资料数据的压缩包请在文件下载资源频道搜索 与本标题相同的 本博主提供的材料)

yushibing717的博客 1084

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

CGE模型教程

为了实现这一目标就必须应用各种二氧化碳排放量很高技术的替代技术,不仅需要考虑技术上的可靠性,也需要考虑经济上的可行性。可计算一般均衡模型(CGE模型)由于其能够模拟宏观经济系统运行和价格调节机制,分析政策工具的影响和效应而备受“双碳”目标研究者的青睐。且受经济学研究传统的影响,CGE模型多半用GAMS等工程领域研究者不熟悉的软件建立。为有利于生态及环境等领域研究者使用CGE模型,降低工程技术人员应用该模型的门槛,特召开基于R语言的CGE模型实践技术应用。7.CGE模型的环境模型比拟。

CCfz566的博客 1672

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

服务器部署LLM、Embedding

介绍在服务器下将大语言模型、embedding模型通过transformers或者vllm的方式部署为API服务的搭建步骤和脚本

青山的博客 4301

vllm方式部署Deepseek R1、Embedding、Reranker、Qwen3,并集成dify环境

服务器配置 :8块H20显卡、两颗至强白金8558P(单颗48核96线程)、2TB内存(32根64GB)操作系统:Ubuntu24。

顺其自然~专栏 5700

“双碳”目标下资源环境中的可计算一般均衡(CGE)模型实践技术

我国政府承诺在2030年实现“碳达峰”,2060年实现“碳中和”,这就是“双碳”目标。为了实现这一目标就必须应用各种二氧化碳排放量很高技术的替代技术,不仅需要考虑技术上的可靠性,也需要考虑经济上的可行性。可计算一般均衡模型(CGE模型)由于其能够模拟宏观经济系统运行和价格调节机制,分析政策工具的影响和效应而备受“双碳”目标研究者的青睐。由于CGE模型基于严格的微观经济学基础,对非经济学领域的研究人员门槛很高;且受经济学研究传统的影响,CGE模型多半用GAMS等工程领域研究者不熟悉的软件建立。为有...

weixin_xiao5kou4chang6kai4的博客 1824
上一篇: 2024 年 8 月暨 ACL 2024 57篇代码大模型论文精选
下一篇: 活动|2024 CodeFuse 「编码挑战季」活动已开启!欢迎报名参加
CodeFuse
博客等级 码龄3年 630粉丝 74原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值