当前位置:网站首页>lstm pipeline 过程理解(输入输出)
lstm pipeline 过程理解(输入输出)
2022-08-04 05:29:00 【TigerZ*】



step1, raw text:接触LSTM模型不久,简单看了一些相关的论文,还没有动手实现过。然而至今仍然想不通LSTM神经网络究竟是怎么工作的。……step2, tokenize (中文得分词):sentence1: 接触 LSTM 模型 不久 ,简单 看了 一些 相关的 论文 , 还 没有 动手 实现过 。sentence2: 然而 至今 仍然 想不通 LSTM 神经网络 究竟是 怎么 工作的。……step3, dictionarize:sentence1: 1 34 21 98 10 23 9 23sentence2: 17 12 21 12 8 10 13 79 31 44 9 23……step4, padding every sentence to fixed length:sentence1: 1 34 21 98 10 23 9 23 0 0 0 0 0sentence2: 17 12 21 12 8 10 13 79 31 44 9 23 0……step5, mapping token to an embeddings:sentence1:
,每一列代表一个词向量,词向量维度自行确定;矩阵列数固定为time_step length。sentence2:……step6, feed into RNNs as input:假设 一个RNN的time_step 确定为l, 则padded sentence length(step5中矩阵列数)固定为l。一次RNNs的run只处理一条sentence。每个sentence的每个token的embedding对应了每个时序t的输入。一次RNNs的run,连续地将整个sentence处理完。
step7, get output:看图,每个time_step都是可以输出当前时序t的隐状态;但整体RNN的输出
是在最后一个time_step t=l 时获取,才是完整的最终结果。
step8, further processing with the output:我们可以将output根据分类任务或回归拟合任务的不同,分别进一步处理。比如,传给cross_entropy&softmax进行分类……或者获取每个time_step对应的隐状态,做seq2seq 网络……或者搞创新……

import tensorflow as tf
import numpy as np
def dynamic_rnn(rnn_type='lstm'):
X=np.random.rand(3,6,4)
X[1,4:]=0
X_length=[6,4,6]
rnn_hidden_size=5
if(rnn_type=='lstm'):
cell=tf.contrib.rnn.BasicLSTMCell(num_units=rnn_hidden_size,state_is_tuple=True)
else:
cell=tf.contrib.rnn.GRUCell(num_units=rnn_hidden_size)
num=cell.output_size
outputs,last_states = tf.nn.dynamic_rnn(
cell=cell,
dtype=tf.float64,
sequence_length=X_length,
inputs=X
)
with tf.Session() as session:
session.run(tf.global_variables_initializer())
o1,s1 = session.run([outputs,last_states])
print(X)
print(np.shape(o1))
print(o1)
print(np.shape(s1))
print(s1)
print(num)
if __name__ == '__main__':
dynamic_rnn(rnn_type='lstm')边栏推荐
- MFC读取点云,只能正常显示第一个,显示后面时报错
- TensorFlow:tf.ConfigProto()与Session
- 【深度学习21天学习挑战赛】0、搭建学习环境
- The use of the attribute of the use of the animation and ButterKnife
- 0, deep learning 21 days learning challenge 】 【 set up learning environment
- Deep Adversarial Decomposition: A Unified Framework for Separating Superimposed Images
- YOLOV4流程图(方便理解)
- Briefly say Q-Q map; stats.probplot (QQ map)
- 彻底搞懂箱形图分析
- Usage of Thread, Handler and IntentService
猜你喜欢

(六)递归

fill_between in Matplotlib; np.argsort() function
![[Deep Learning 21 Days Learning Challenge] Memo: What does our neural network model look like? - detailed explanation of model.summary()](/img/99/819ccbfed599ffd52307235309cdc9.png)
[Deep Learning 21 Days Learning Challenge] Memo: What does our neural network model look like? - detailed explanation of model.summary()

多项式回归(PolynomialFeatures)

【深度学习21天学习挑战赛】2、复杂样本分类识别——卷积神经网络(CNN)服装图像分类

【论文阅读】Mining Cross-Image Semantics for Weakly Supervised Semantic Segmentation

(九)哈希表

动手学深度学习_线性回归

【CV-Learning】卷积神经网络预备知识

RecyclerView的用法
随机推荐
pgsql函数中的return类型
动手学深度学习_softmax回归
[CV-Learning] Convolutional Neural Network Preliminary Knowledge
2020-10-29
光条提取中的连通域筛除
SQL练习 2022/7/3
ConnectionRefusedError: [Errno 111] Connection refused问题解决
【论文阅读】Mining Cross-Image Semantics for Weakly Supervised Semantic Segmentation
【CV-Learning】Image Classification
yolov3中数据读入(一)
SQL的性能分析、优化
线性回归简介01---API使用案例
【CV-Learning】目标检测&实例分割
PP-LiteSeg
基于PyTorch的FCN-8s语义分割模型搭建
【论文阅读】Further Non-local and Channel Attention Networks for Vehicle Re-identification
图像形变(插值方法)
postgresql 游标(cursor)的使用
Data reading in yolov3 (1)
图像线性融合
