【图嵌入】DeepWalk原理与代码实战

【论文逐句精读】DeepWalk,随机游走实现图向量嵌入,自然语言处理与图的首次融合 这是一篇划时代的论文,标志着图机器学习向图深度学习的转变,主要贡献在于取代人工图特征标注,转化为无监督图嵌入向量描述。 阅读详情

DeepWalk

基础理论

了解过 NLP 的同学对 word2vec 应该不陌生,word2vec 通过句子中词与词之间的共现关系来学习词的向量表示,如果你忘记了,可以看看我之前的博客:

  1. 【word2vec】篇一:理解词向量、CBOW与Skip-Gram等知识
  2. 【word2vec】篇二:基于Hierarchical Softmax的 CBOW 模型和 Skip-gram 模型
  3. 【word2vec】篇三:基于Negative Sampling 的 CBOW 模型和 Skip-gram 模型

DeepWalk 出自论文:DeepWalk: Online Learning of Social Representations,它的思想与 word2vec 类似,从一个初始节点沿着图中的边随机游走一定的步数,将经过的节点序列视为句子。那么,从不同的起点开始的不同游走路线就构成了不同的句子。当获取到足够数量的句子(节点访问序列)后,可以使用 skip-gram 模型对每个节点学习其向量表示。这个过程如下图所示:

在这里插入图片描述

以下是对 DeepWalk 的一些思考与个人理解:

DeepWalk 利用类似深度优先遍历的方式将复杂的图结构转换为序列,进而实现节点的Embedding。这个遍历的过程相当于对图中的节点进行采样,捕获局部上下文信息。上图中B与D都是A与E共有的邻居,那么在经过节点B、D的随机游走序列中,节点A或者节点E出现的频率也比较高,说明节点A和E具有相似的上下文语境,那么A和E的Embedding表示也应该相似。

下面再来看个更直观的例子,如下图中的节点1、4是节点2、3共有的邻居:

在这里插入图片描述

那么在经过节点1、4的随机游走序列中,节点2或者节点3出现的频率也比较高,例如:

  • 0,4,3
  • 0,4,2
  • 1,2
  • 1,3
  • 1,4,3
  • 1,4,2
  • …

那么根据 skip-gram 模型的思想,节点2,3的局部上下文语境比较相似,于是最终学习到的节点2、3的Embedding表示也就比较相似。这也意味着,当两个节点共有的邻居节点越多,那么这两个节点就越相似。

代码实现

结合上面的理论基础,要使用 DeepWalk 得到节点的向量表示,需要分为三个步骤:

1,构造图

主要是使用 networkx 这个库来从文件中读取边的信息来构造图,文件的每一行分别是:<

图机器学习--DeepWalk&Node2Vec 图机器学习,图嵌入算法deepwalk和node2vec讲解及论文精读 阅读详情

相关推荐

Graph Embedding(DeepWalk,LINE,Node2vec)

Graph Embedding 属于表示学习。主要是将图中的节点/图表示成低维,实值,稠密的向量形式,使得到的向量能够做进一步的推理,对下游任务会很有帮助。图嵌入(顶点嵌入/图嵌入)方法主要有矩阵分解,随机游走和深度学习。 矩阵分解: 基于矩阵分解的方法是将节点间的关系用矩阵的形式加以表达,然后分解该矩阵以得到嵌入向量。通常用于表示节点关系的矩阵包括邻接矩阵,拉普拉斯矩阵,节点转移概率矩阵,节点...

nakaizura 6564

拉普拉斯矩阵_图嵌入专题(四):图嵌入与矩阵分解

//本文是图嵌入专题的第四篇文章//引言在图嵌入专题的前三篇文章中,我们分别从图嵌入算法的整体概况、基于深度学习的图嵌入算法以及基于skip-gram的图嵌入算法三个方面进行了介绍。本文从图嵌入算法与矩阵分解算法的关系出发,对图嵌入算法进行进一步的介绍。1图嵌入与矩阵的关系图嵌入算法的基本思想,是通过一种学习方式,将复杂网络中的节点表达成一个低维的向量,使其能够反映出该节...

weixin_40008884的博客 2377

LINE vs Node2Vec vs DeepWalk:三大经典图嵌入算法实战对比与选型指南

本文对比分析了LINE、Node2Vec和DeepWalk三大经典图嵌入算法的原理、性能及工程实践,帮助开发者在推荐系统、社交网络分析等场景中做出精准选型。LINE凭借显式邻近度保留和高效计算在大规模网络中表现突出,Node2Vec通过灵活游走策略捕捉复杂模式,而DeepWalk则适合作为基线方法快速验证效果。文章还提供了详细的参数调优指南和选型决策框架。

weixin_30680385的博客 572

图神经网络实战(3)——基于DeepWalk创建节点表示

DeepWalk 是机器学习技术在图数据中的成功应用之一,其引入了嵌入等重要概念,这些概念是图神经网络的核心。在本节中,我们了解了 DeepWalk 架构及其主要组件。然后,使用随机游走将图数据转化为序列,并应用了 Word2Vec 算法,使用图的拓扑信息创建节点嵌入,得到的嵌入结果可用于发现节点间的相似性,或作为其他算法的输入。最后,我们使用监督方法解决了节点分类问题。

盼小辉丶的博客 1万+

图嵌入】DeepWalk原理与代码实战

https://blog.youkuaiyun.com/bqw18744018044/article/details/106530702?utm_medium=distribute.pc_relevant.none-task-blog-baidujs_title-0&spm=1001.2101.3001.4242

2440

AI原生应用开发必知:知识图谱的七大核心算法

在AI原生应用开发的世界里,知识图谱就像是一个超级大宝藏。我们的目的就是要深入挖掘这个宝藏,了解其中七大核心算法的奥秘。通过这篇文章,我们会详细介绍这些算法的原理、如何操作以及它们在实际中的应用。范围涵盖了从基础概念到实战案例,希望能让大家对知识图谱的核心算法有全面的认识。接下来,我们会先介绍一些相关的术语,然后用有趣的故事引出核心概念,解释这些概念以及它们之间的关系,给出原理示意图和流程图。接着会详细讲解七大核心算法的原理和操作步骤,结合数学模型和实际案例。

AI智能探索者的博客 1468

图嵌入实战:Python实现DeepWalk与GCN对比指南

图嵌入是图神经网络领域的核心技术,旨在将不规则图结构中的节点映射为低维稠密向量,使计算机能够像处理表格数据一样高效完成节点分类、链路预测等下游任务。DeepWalk基于随机游走与Word2Vec思想,通过模拟节点共现关系学习向量表示;GCN则利用邻居消息传递机制,在图结构上逐层聚合特征,两者分别代表了浅层表示学习与深度图卷积两大技术路线。在社交网络分析、推荐系统、知识图谱等真实场景中,图嵌入方法展现出强大的泛化能力。本文从两种算法的核心原理出发,结合Python与PyTorch环境,在Cora公开数据集上给

weixin_42524499的博客 360

CST 仿真_NFC仿真

在CST中实现NFC天线单体的仿真

qq_43706810的博客 3960

解题报告-美团点评2017秋招笔试编程题--常见动态规划问题

晚上就要美团笔试了,在牛客上刷套美团的题练练手,四道题目全都是典型题目,经典的连题面都懒得改那种,也都不难,很基础的动态规划问题。[编程题] 大富翁游戏时间限制:1秒空间限制:32768K大富翁游戏,玩家根据骰子的点数决定走的步数,即骰子点数为1时可以走一步,点数为2时可以走两步,点数为n时可以走n步。求玩家走到第n步(n&lt;=骰子最大点数且是方法的唯一入参)时,总共有多少种投骰子的方法。 输...

聂小白的专栏 1718

# 芯片良率是怎么算出来的?——从泊松到负二项分布,一个芯片测试工程师的视角

- 良率=好Die/总Die,但选错模型可能差17个百分点 - Poisson模型过于悲观,Murphy居中,**Negative Binomial才是业界标配** - 关键不是良率数字,是**跟踪聚类因子α的变化**——它能早几周预警工艺漂移 - Chiplet时代,10颗90%良率的Die封在一起,整体良率只有35%

Freezeblur的博客 646

ALTERA Triple-Speed Ethernet IP核在UDP通信中的实战配置指南

本文详细介绍了在Intel FPGA(原ALTERA)平台上配置Triple-Speed Ethernet IP核以实现UDP通信的实战指南。内容涵盖从IP核选型、QSYS系统搭建、关键参数配置,到UDP数据包组装、NIOS C程序调试及上板验证的全流程,重点解析了如何利用该IP核快速构建稳定的千兆网通信基础,为FPGA网络应用开发提供清晰路径。

m3n5b7v8c9x的博客 512

Docker 环境 Playwright MCP 部署全流程指南

Docker部署Playwright MCP全流程指南 本文详细介绍了使用Docker容器化部署Playwright MCP的完整流程,涵盖镜像拉取、容器启动、配置优化和问题排查。主要内容包括: 核心部署步骤:通过官方镜像快速搭建环境,支持自定义端口和数据持久化 关键配置要点:详解网络设置、持久化目录挂载和环境变量配置 服务验证方法:通过日志检查和服务连通性测试确保部署成功 客户端集成:提供VS Code等IDE的配置示例 常见问题解决:针对浏览器启动超时、跨域限制等问题给出解决方案 实战案例:演示自动化爬

勤奋的码农 1473

从底层结构开始学习FPGA(7)----进位链CARRY4

进位链CARRY4在FPGA实现加减法运算时扮演了什么角色?

孤独的单刀 1万+

海康visionmaster-渲染结果:通过绑定流程或模块获取 渲染结果的方法

海康visionmaster-渲染结果:通过绑定流程或模块获取 渲染结果的方法

视觉人机器视觉的博客 2636

STM32F407+OV2640的DCMI+DMA双缓冲JPEG图像采集系统

在嵌入式视觉系统中,数字摄像头接口(DCMI)是MCU连接CMOS图像传感器的关键硬件通道,其与DMA协同实现零CPU干预的高速数据流采集;而JPEG作为一种基于DCT变换与量化压缩的有损图像格式,依赖传感器端硬件编码引擎才能满足实时性要求。理解DCMI三重同步时序(PCLK/HSYNC/VSYNC)与DMA双缓冲机制的流水线协作原理,是突破带宽瓶颈、避免FIFO溢出和帧丢失的技术基础。该架构广泛应用于智能硬件、工业检测与边缘AI前端等需低功耗、高可靠图像捕获的场景,本文以OV2640与STM32F407为

weixin_42103128的博客 156

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

深度学习工具包 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")

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

上一篇: CTR深度学习模型之 DIEN(Deep Interest Evolution Network) 的理解与示例
下一篇: 【图嵌入】Graph Embedding 方法之 LINE 原理解读
VariableX
博客等级 码龄7年 142粉丝 62原创
评论 3
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值