从这一节开始,我开始使用1800组数据构成的数据集。
NO.1
设置random_state=1,网络结构与学习率为:
model = tf.keras.Sequential([
# 0-255共256个,故第一个参数为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-255共256个,故第一个参数为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-255共256个,故第一个参数为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-255共256个,故第一个参数为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-255共256个,故第一个参数为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-255共256个,故第一个参数为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-255共256个,故第一个参数为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-255共256个,故第一个参数为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