debug tensorflow的seq2seq的attention_decoder方法
来源:互联网 发布:网络用语马克啥意思 编辑:程序博客网 时间:2024/05/16 00:33
写这个attention_decoder的testcase来用debug的方式看看注意力机制的实现
import tensorflow as tffrom tensorflow.python.ops import rnnfrom tensorflow.python.ops import rnn_cellfrom tensorflow.contrib.legacy_seq2seq.python.ops import seq2seq as seq2seq_libwith tf.Session() as sess: batch_size = 16 step1 = 20 step2 = 10 input_size = 50 output_size = 40 gru_hidden = 30 cell_fn = lambda: rnn_cell.GRUCell(gru_hidden) cell = cell_fn() inp = [tf.constant(0.8, shape=[batch_size, input_size])] * step1 enc_outputs, enc_state = rnn.static_rnn(cell, inp, dtype=tf.float32) attn_states = tf.concat([ tf.reshape(e, [-1, 1, cell.output_size]) for e in enc_outputs ], 1) dec_inp = [tf.constant(0.3, shape=[batch_size, output_size])] * step2 dec, mem = seq2seq_lib.attention_decoder( dec_inp, enc_state, attn_states, cell_fn(), output_size=7) sess.run([tf.global_variables_initializer()]) res = sess.run(dec) print(len(res)) print(res[0].shape) res = sess.run([mem]) print(len(res)) print(res[0].shape)
改编自https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/legacy_seq2seq/python/kernel_tests/seq2seq_test.py
阅读全文
0 0
- debug tensorflow的seq2seq的attention_decoder方法
- tensorflow中的seq2seq的代码详解
- Tensorflow 自动文摘: 基于Seq2Seq+Attention模型的Textsum模型
- Tensorflow 自动文摘: 基于Seq2Seq+Attention模型的Textsum模型
- Tensorflow 自动文摘: 基于Seq2Seq+Attention模型的Textsum模型
- seq2seq 的 keras 实现
- ChatGirl 一个基于 TensorFlow Seq2Seq 模型的聊天机器人[中文文档]
- Seq2Seq in Tensorflow
- Seq2Seq in Tensorflow
- [Note] TensorFlow seq2seq tutorial
- TensorFlow实现seq2seq
- TensorFlow实现seq2seq
- TensorFlow中seq2seq库函数
- tensorflow seq2seq代码学习
- 深度学习的seq2seq模型
- 深度学习的seq2seq模型
- 深度学习的seq2seq模型
- 深度学习的seq2seq模型
- 实验楼_TCP/IP网络协议基础_Note03_S7S8
- K-means聚类算法及变种
- 基于QT 5.8.0 for Android 的 Windows 10 开发环境搭建
- FYN OI奋斗之路1~
- 「python」局部变量与全局变量
- debug tensorflow的seq2seq的attention_decoder方法
- Windows下安装drozer
- 【剑指】面试题50 字符串中第一个只出现一次的字符
- spring学习笔记四 bean之间的关系
- Number Sequence(KMP之子串首次出现的位置)
- python读取txt
- number theory 基础数论
- java简结
- windows核心编程之进程(3)