NLP-Highway Network代码实现
记录Highway Network的代码实现部分,以备日后使用。。。
Highway Network
1.作用or概念部分
1.https://blog.csdn.net/u011534057/article/details/51819691
2.https://blog.csdn.net/l494926429/article/details/51737883
3.https://www.cnblogs.com/jie-dcai/p/5803220.html
上一个链接3中的截图,简单浅显易懂:
2.代码实现部分
def highway(input_, size, scope='highway',reuse=None,layer_size=1, bias=-2, f=tf.nn.tanh):"""Highway Network (cf. http://arxiv.org/abs/1505.00387).t = sigmoid(Wy + b)z = t * g(Wy + b) + (1 - t) * ywhere g is nonlinearity, t is transform gate, and (1 - t) is carry gate."""output=input_with tf.variable_scope(scope,reuse=reuse):for idx in range(layer_size):output = tf.tanh(dense(input_,size,scope='dense1'))transform_gate = tf.sigmoid(dense(input_,size,scope='dense2'))carry_gate = 1. - transform_gateoutput = transform_gate * output + carry_gate * input_return output
def dense(inputs, output_size, bias=True,seq_len=None,max_len=None,mode='mul',scope='dense'):with tf.variable_scope(scope):input_size = int(inputs.shape[-1])W = tf.Variable(tf.random_uniform([input_size, output_size], -0.1, 0.1))#W = tf.get_variable("W",# [input_size,output_size],# dtype = tf.float32,# regularizer=regularizer,# initializer = initializer())if bias:b = tf.Variable(tf.random_uniform([output_size], -0.05, 0.05))#b = tf.get_variable("b",# [output_size],# regularizer=regularizer,# initializer = tf.zeros_initializer())else:b = 0outputs = tf.matmul(tf.reshape(inputs, (-1, input_size)), W) + boutputs = tf.reshape(outputs, \tf.concat([tf.shape(inputs)[:-1], [output_size]], 0))if seq_len != None:outputs = Mask(outputs, seq_len, max_len,mode=mode)return outputs
NLP-Highway Network代码实现相关推荐
- highway network
Highway Network highway network 主要解决了因网络深度的加深,梯度信息回流受阻,从而造成网络训练困难的问题. 它其实就是一个门结构,用这个门来控制输入的信息中有多少信息被 ...
- 在lasagne中自定义层,实现highway network layer
一.自定义lasagne层 比如我要定义一个Highway network层(关于highway network的知识在网上有很多) 1)首先需要继承lasagne的基础层: 可以看到,自定义 ...
- shortcut connection和highway network
CNN演化 先引入一张CNN结构演化图: 2012年AlexNet做出历史突破以来,直到GoogLeNet出来之前,主流的网络结构突破大致是网络更深(层数),网络更宽(神经元数).所以大家调侃深度学习 ...
- NLP常用损失函数代码实现——SoftMax/Contrastive/Triplet/Similarity
NLP常用损失函数代码实现 NLP常用的损失函数主要包括多类分类(SoftMax + CrossEntropy).对比学习(Contrastive Learning).三元组损失(Triplet ...
- Github标星5.4k+:常见NLP模型的代码实现(基于TensorFlow和PyTorch)
推荐github上的一个NLP代码教程:nlp-tutorial,教程中包含常见的NLP模型代码实现(基于TensorFlow和Pytorch),而且教程中的大多数NLP模型都使用少于100行代码. ...
- 推荐:常见NLP模型的代码实现(基于TensorFlow和PyTorch)
推荐github上的一个NLP代码教程:nlp-tutorial,教程中包含常见的NLP模型代码实现(基于TensorFlow和Pytorch),而且教程中的大多数NLP模型都使用少于100行代码. ...
- MPN (Learning Normal Dynamics in Videos with Meta Prototype Network)代码阅读
Learning Normal Dynamics in Videos with Meta Prototype Network Hui Lv1, Chen Chen2, Zhen Cui1*, Chun ...
- 【CS231n】Two Layer Neural Network 代码实现
1. 代码实现 github:https://github.com/GIGpanda/CS231n 主要包括连个.py文件,一个是two_layer_net.py,另外一个是neural_net.py ...
- python回声程序echo 一行代码_回声状态网络法echo state network代码(简单)
[实例简介] esn作者在官网的简单版代码,给英文不好的同学拿过来,免得再去找地方下载 [实例截图] [核心代码] ESN_Toolbox └── ESN_Toolbox ├── analogToUn ...
最新文章
- python 去除list 里面的重复元素
- 【C/C++】计时函数比较
- FastDFS 使用经验分享
- 实验二 初始化阶段-source.c
- *PAT_B_1030_Java(22分)_C++(25分)
- SpringBoot系列: 单元测试2
- php 微盘系统教程,新版微盘API接口调用方法
- 《我的WCF之旅》博文系列汇总
- autoLayout+sizeClass屏幕适配
- HDU2072 单词数(解法二)【废除!!!】
- 十大Excel函数(一)
- 英文文献调研方法综述
- 哀悼日很多网站都变成了灰色,这是怎么做到的?
- Linux操作系统安装及服务控制
- 将图和双向transformers融合的分子性质预测新工具 简称AGBT - 论文阅读
- 云计算基础2-什么是云存储?
- 自学JavaScript第一天- JS 基础
- 当心Azure跨区域数据传输产生额外费用
- GPU-Z查看显卡参数和显卡状态
- 计算机毕业设计ssm基于SSM框架的中医养生系统i9830系统+程序+源码+lw+远程部署