tensorflow实战(六)——过拟合调参(3)及网络结构、dropout与batchsize调整

从这一节开始,我开始使用1800组数据构成的数据集。

NO.1

设置random_state=1,网络结构与学习率为:

model = tf.keras.Sequential([
    # 0-255256个,故第一个参数为256,数据为三位数,故第三个参数为3
    Embedding(256, 3),
    LSTM(30, return_sequences=True),
    Dropout(0.2),
    LSTM(50),
    Dropout(0.2),
    Dense(2, activation='softmax')
])

batch=32
lr_schedule = tf.keras.optimizers.schedules.InverseTimeDecay(
    0.001,
    decay_steps=batch*1000,
    decay_rate=2,
    staircase=False)

结果:正确率为0.9828
在这里插入图片描述

NO.2

将dropout改为0.5

model = tf.keras.Sequential([
    # 0-255256个,故第一个参数为256,数据为三位数,故第三个参数为3
    Embedding(256, 3),
    LSTM(30, return_sequences=True),
    Dropout(0.5),
    LSTM(50),
    Dropout(0.5),
    Dense(2, activation='softmax')
])

结果:正确率为0.9472
在这里插入图片描述

NO.3

将dropout还原为0.2,改变记忆体个数为10

model = tf.keras.Sequential([
    # 0-255256个,故第一个参数为256,数据为三位数,故第三个参数为3
    Embedding(256, 3),
    LSTM(10, return_sequences=True),
    Dropout(0.5),
    LSTM(10),
    Dropout(0.5),
    Dense(2, activation='softmax')
])

结果:正确率为0.944
在这里插入图片描述

NO.4

改变记忆体个数

model = tf.keras.Sequential([
    # 0-255256个,故第一个参数为256,数据为三位数,故第三个参数为3
    Embedding(256, 3),
    LSTM(50, return_sequences=True),
    Dropout(0.2),
    LSTM(100),
    Dropout(0.2),
    Dense(2, activation='softmax')
])

结果:准确率为0.9472
在这里插入图片描述

NO.5

改变网络深度

model = tf.keras.Sequential([
    # 0-255256个,故第一个参数为256,数据为三位数,故第三个参数为3
    Embedding(256, 3),
    LSTM(8, return_sequences=True),
    Dropout(0.2),
    LSTM(8, return_sequences=True),
    Dropout(0.2),
    LSTM(8),
    Dropout(0.2),
    Dense(2, activation='softmax')
])

结果:准确率为0.9361
在这里插入图片描述

NO.6

改变dropout

model = tf.keras.Sequential([
    # 0-255256个,故第一个参数为256,数据为三位数,故第三个参数为3
    Embedding(256, 3),
    LSTM(8, return_sequences=True),
    Dropout(0.5),
    LSTM(8, return_sequences=True),
    Dropout(0.5),
    LSTM(8),
    Dropout(0.5),
    Dense(2, activation='softmax')
])

结果:准确率为0.9417
在这里插入图片描述

NO.7

将batch_size改为16,网络结构不变

```cpp
model = tf.keras.Sequential([
    # 0-255256个,故第一个参数为256,数据为三位数,故第三个参数为3
    Embedding(256, 3),
    LSTM(8, return_sequences=True),
    Dropout(0.5),
    LSTM(8, return_sequences=True),
    Dropout(0.5),
    LSTM(8),
    Dropout(0.5),
    Dense(2, activation='softmax')
])

结果:准确率为0.9472
在这里插入图片描述

NO.8

将batch_size改为300,发现训练提高了不少,而且曲线更加好看,网络结构不变

```cpp
model = tf.keras.Sequential([
    # 0-255256个,故第一个参数为256,数据为三位数,故第三个参数为3
    Embedding(256, 3),
    LSTM(8, return_sequences=True),
    Dropout(0.5),
    LSTM(8, return_sequences=True),
    Dropout(0.5),
    LSTM(8),
    Dropout(0.5),
    Dense(2, activation='softmax')
])

结果:准确率为0.9472
在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值