keras 的 example 文件 babi_rnn.py 解析
该代码的目的和 https://blog.csdn.net/zhqh100/article/details/105193991 类似
数据集也是同一个数据集,只不过这个是从 qa2_two-supporting-facts_train.txt 中获取的文本,文本量会大一些
第一个示例
1 Mary moved to the bathroom.
2 Sandra journeyed to the bedroom.
3 Mary got the football there.
4 John went to the kitchen.
5 Mary went back to the kitchen.
6 Mary went back to the garden.
7 Where is the football? garden 3 6
单词映射为:
{'.': 1, '?': 2, 'Daniel': 3, 'John': 4, 'Mary': 5, 'Sandra': 6, 'Where': 7, 'apple': 8, 'back': 9, 'bathroom': 10, 'bedroom': 11, 'discarded': 12, 'down': 13, 'dropped': 14, 'football': 15, 'garden': 16, 'got': 17, 'grabbed': 18, 'hallway': 19, 'is': 20, 'journeyed': 21, 'kitchen': 22, 'left': 23, 'milk': 24, 'moved': 25, 'office': 26, 'picked': 27, 'put': 28, 'the': 29, 'there': 30, 'to': 31, 'took': 32, 'travelled': 33, 'up': 34, 'went': 35}
上面的材料编码后为:
[ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 5 25 31 29 10 1 6 21 31 29 11 1 5 1729 15 30 1 4 35 31 29 22 1 5 35 9 31 29 22 1 5 35 9 31 29 16 1]
[ 7 20 29 15 2]
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1. 0. 0. 0. 0. 0. 0. 0.0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
这里把ans进行了one-hot编码,所以 loss 用的是 categorical_crossentropy,而 babi_memnn.py 用的是 sparse_categorical_crossentropy,所以不用进行one-hot编码
训练数据shape
x.shape = (1000, 552)
xq.shape = (1000, 5)
y.shape = (1000, 36)
神经网络结构:
__________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
==================================================================================================
input_1 (InputLayer) (None, 552) 0
__________________________________________________________________________________________________
input_2 (InputLayer) (None, 5) 0
__________________________________________________________________________________________________
embedding_1 (Embedding) (None, 552, 50) 1800 input_1[0][0]
__________________________________________________________________________________________________
embedding_2 (Embedding) (None, 5, 50) 1800 input_2[0][0]
__________________________________________________________________________________________________
lstm_1 (LSTM) (None, 100) 60400 embedding_1[0][0]
__________________________________________________________________________________________________
lstm_2 (LSTM) (None, 100) 60400 embedding_2[0][0]
__________________________________________________________________________________________________
concatenate_1 (Concatenate) (None, 200) 0 lstm_1[0][0]lstm_2[0][0]
__________________________________________________________________________________________________
dense_1 (Dense) (None, 36) 7236 concatenate_1[0][0]
==================================================================================================
Total params: 131,636
Trainable params: 131,636
Non-trainable params: 0
__________________________________________________________________________________________________
——————————————————————
总目录
keras的example文件解析
keras 的 example 文件 babi_rnn.py 解析相关推荐
- keras 的 example 文件 cnn_seq2seq.py 解析
该代码是实现一个翻译功能,好像是英语翻译为法语,嗯,我看不懂法语 首先这个代码有一个bug,本人提交了一个pull request来修复, https://github.com/keras-team/ ...
- keras 的 example 文件 cifar10_resnet.py 解析
该代码功能是卷积神经网络进行图像识别,数据集是cifar10 同时演示了回调函数 ModelCheckpoint, LearningRateScheduler, ReduceLROnPlateau 的 ...
- keras 的 example 文件 mnist_hierarchical_rnn.py 解析
很显然,我没有看懂 HRNN 是啥意思,没有去看论文,应该就是一种RNN结构的变形吧 网络结构如下: _________________________________________________ ...
- keras 的 example 文件 mnist_denoising_autoencoder.py 解析
mnist_denoising_autoencoder.py 是一个编解码神经网络,其意义就是如果图片中有噪点的话,可以去除噪点,还原图片 其编码网络为: ______________________ ...
- keras 的 example 文件 mnist_cnn.py 解析
mnist_cnn.py 基本上就是最简单的一个卷积神经网络了,其结构如下: _____________________________________________________________ ...
- keras 的 example 文件 imdb_bidirectional_lstm.py 解析
imdb是一个文本情感分析的数据集,通过评论来分析观众对电影是好评还是差评 其网络结构比较简单 ____________________________________________________ ...
- keras 的 example 文件 lstm_text_generation.py 解析
该程序是学习现有的文章,然后学习预测下个字符,这样一个字符一个字符的学会写文章 先打印下char_indices {'\n': 0, ' ': 1, '!': 2, '"': 3, &quo ...
- keras 的 example 文件 lstm_stateful.py 解析
该程序要通过一个LSTM来实现拟合窗口平均数的功能 先看输入输出数据, print(x_train[:10]) [[[-0.08453234]][[ 0.02169589]][[ 0.07949955 ...
- keras 的 example 文件 imdb_fasttext.py 解析
该文件功能上也是文本情感分类 默认的代码中 ngram_range = 1,这就差不多是常规的NLP处理,编号跟一个 Embedding,这就比较简单 所以我们还是分析一下 ngram_range & ...
最新文章
- javascript音频管理方案:SoundManager2
- 微软 服务器和工具产品,微软服务器和工具部总裁鲍伯·穆格里亚辞职
- python指定变量类型_Python#160;变量类型_python教程
- 实现verilog设计控制交通灯
- 从二分逼近领略计算科学的魅力
- 在源文件(.c)和头文件(.h)中声明和定义的区别——C语言
- C/C++ 程序设计员应聘常见面试试题深入剖析(2)
- TNF1EGS4 OSN1800全新四路交换式千兆以太网处理板
- 体检预约系统软件测试计划书,体检中心-管理软件需求分析.doc
- celeste第二章_『第二章』 蔚蓝的剑
- 555555555555555555555
- 在我们人生的大道上,肯定会遇到许许多多的困难。但我们是不是都知道,在前进的道路上,搬开别人脚下的绊脚石,有时恰恰是为自己铺路?
- pathon的基本语法
- imac 2017升级内存
- 适合公司用的电子邮箱哪家好?企业邮箱最全功能介绍~
- python 实现发送手机短信验证码后台方法
- 求素数/质数 简单Java算法
- Ubuntu不同颜色文件所代表的文件类型
- keil调试stm32MCU的时候没有黄色箭头的一个处理办法
- Extract Method(提炼函数)
热门文章
- adb install -r ,-d 等的解释
- error: unbound prefix. Message{kind=ERROR, text=error: unbound prefix., sources=[E:\work\me\fragment
- Android studio更新后出现警告:Warning:The `android.dexOptions.incremental` property is deprecated and it has
- shell eval命令
- CRM中Plugin开发如何将功能放入多个模块
- 201621123068 作业08-集合
- 2022-2028年中国商贸物流行业市场前瞻与投资战略规划分析报告
- 学习动力之“学习金字塔 (爱德加•戴尔)”理论
- Codeforces 629D Babaei and Birthday Cake(树状数组优化dp)
- 新安装Ubuntu加载时提示“为/检查磁盘时发生严重错误”的解决方法