简体   繁体   English

带有少量数据集的浅层神经网络的训练速度

[英]Training speed on a shallow neural network with a small dataset

My data contains of 1 feature and a label per feature ie. 我的数据包含1个要素和每个要素的标签,即。 ["smallBigTest", "toastBob"] <- feature 4 labels ["mix", "small", "big", "medium"] ["smallBigTest", "toastBob"] <-功能4个标签["mix", "small", "big", "medium"]

I have converted my features to numbers based on alphabet ie. 我已经将功能转换为基于字母的数字,即。

smallBigTest -> 18, 12,  0, 53, 53, 27,  8,  6, 45,  4, 18, 19
toastBob ->     19, 14,  0, 18, 19, 27, 14,  1, -1, -1, -1, -1

which later on I hot-encoded and reshaped so the final array of features would look like [[hotencoded(18,12,0,53,53,27,8,6,45,4,18,19)], [hotencoded(19,14,0,18,19,27,14,1,-1,-1,-1,-1)] 后来我[[hotencoded(18,12,0,53,53,27,8,6,45,4,18,19)], [hotencoded(19,14,0,18,19,27,14,1,-1,-1,-1,-1)]热编码和整形,因此最终的特征数组看起来像[[hotencoded(18,12,0,53,53,27,8,6,45,4,18,19)], [hotencoded(19,14,0,18,19,27,14,1,-1,-1,-1,-1)]

simply made it into a 2d array from 3d array to match my labels shape, i have also hot encoded labels 只需将它从3d阵列变成2d阵列​​以匹配我的标签形状,我也有热编码标签

the training data is about 60k lines of text 1.2mb csv file 训练数据大约为6万行文本1.2mb csv文件

and here is my model: 这是我的模型:

model = tf.keras.Sequential()
model.add(tf.keras.layers.Dense(16, activation=tf.nn.sigmoid))
model.add(tf.keras.layers.Dense(labelsDictSize, activation=tf.nn.softmax))

optimizer = tf.train.GradientDescentOptimizer(0.05)
model.compile(optimizer, loss=tf.losses.softmax_cross_entropy)
model.fit(featuresOneHot,labelsOneHot, steps_per_epoch=dataCount, epochs=5, verbose=1)

I'm new to ML, so I might be doing something completely wrong or completely stupid, I thought though that this amount of data would be fine. 我是ML的新手,所以我可能做的是完全错误或完全愚蠢的事情,尽管我认为这样的数据量会很好。 Training on my machine with gtx870m takes an hour per epoch and on google collaboratory around 20-30 minutes per epoch 在我的机器上使用gtx870m进行训练的时间是每个时期一个小时,而在Google合作实验室上,每个时期大约需要20-30分钟

It's not unusual for NLP models to take so much time to train. NLP模型花费这么多时间来训练并不罕见。 The only thing I would change about your model to speed up the learning process is changing the optimizer to something that doesn't have a fixed learning rate. 我要更改模型以加快学习过程的唯一一件事就是将优化器更改为没有固定学习率的东西。 That should speed up the process. 这样可以加快流程。 I would suggest using adam as it's one of the fastest optimizers with good performance. 我建议使用adam,因为它是性能最佳的最快的优化器之一。

Just replace 只需更换

model.compile(optimizer, loss=tf.losses.softmax_cross_entropy)

with

model.compile(optimizer='adam', loss=tf.losses.softmax_cross_entropy)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM