python - 用于语音识别的 Tensorflow LSTM 在训练每个后续单词时会变慢

标签 python speech-recognition tensorflow lstm recurrent-neural-network

所以我尝试使用 TensorFlow LSTM 来识别口语单词。然而,每个训练单词通过 LSTM 后,下一个单词需要更长的时间来处理(特别是通过反向传播计算梯度并将其应用到网络中)。我目前正在使用不支持 CUDA 的 iMac,因此我必须使用 CPU 而不是 GPU(一旦可以的话,我将切换到 GPU)。

我正在使用 Python-2.7 进行编程

我使用的词汇量非常小,有 8 个词类,每个词类有 10 个训练示例,每个词都是孤立的(不是句子的一部分,只是一个词本身)。

每个单词都被预处理为梅尔频率倒谱系数,然后使用 K = 100 的 Kmeans 进行聚类。因此 LSTM 的输入是一次输入一个项目的 float32 列表。

速度减慢肯定发生在 LSTM 中,因为从列表中获取每个项目并将其传递到 LSTM 所需的时间对于每个项目都保持大致相同。每次传递给 LSTM 的每个项目的大小也是相同的(较长的单词只是具有较长的项目列表);然而,随着训练的继续,即使是较短的单词(列表中的项目较少)仍然需要逐渐更长的时间。

我正在使用梯度下降和反向传播来训练网络,并尝试将梯度裁剪为 10 个时间步长或根本不裁剪,这没有什么区别。

LSTM 实例化为:

 cell = rnn_cell.BasicLSTMCell(size, forget_bias=config.forget_bias)
 cell_layers = rnn_cell.MultiRNNCell([cell] * config.num_layers) 
 //pass inputs through the cell
 outputs, states = RNN.rnn(cell_layers, _inputs,initial_state=self._initial_state)

在 LSTM 之后,我有一个 softmax 层;使用交叉熵损失将其输出与代表正确输出的单热向量进行比较。

管道 sudo 代码:

_inputs = [[float32]*]
for input in _inputs: //input = _inputs[0][0] at time zero input = _inputs[0][1] at time 1 etc.
lstm_output = LSTM(input)
soft_out = softmax(last_output)
cost = CrossEnthalpyCost(soft_out, answer)
gradients = backprop(cost)
new_weights = gradientDecent(gradients, learning_rate)

最后,如果我不清楚我的问题是什么,以下是我的网络的计时:

Epoch: 0 Learning rate: 1.000
{'heart': 5, 'car': 1, 'dog': 3, 'cat': 2, 'book': 0, 'three': 7,   'girl': 4, 'milk': 6}
book

time to input all clusters for one word into network: 0.0293724536896
time to pass all inputs for one word and perform gradient decent:2.956
Time difference from previous word: 2.956
Epoch Number: 0 Word Number:1, Number of Pieces:247, Word ID:0

time to input all clusters for one word into network: 0.0287952423096
time to pass all inputs for one word and perform gradient decent:3.738
Time difference from previous word: 0.782
Epoch Number: 0 Word Number:2, Number of Pieces:247, Word ID:0

time to input all clusters for one word into network: 0.029797077179
time to pass all inputs for one word and perform gradient decent:4.754
Time difference from previous word: 1.015
Epoch Number: 0 Word Number:3, Number of Pieces:250, Word ID:0
...

time to input all clusters for one word into network: 0.0417804718018
time to pass all inputs for one word and perform gradient decent:25.123
Time difference from previous word: 12.255
Epoch Number: 0 Word Number:24, Number of Pieces:258, Word ID:2
...

time to input all clusters for one word into network: 0.0413291454315
time to pass all inputs for one word and perform gradient decent:40.364
Time difference from previous word: 0.932
Epoch Number: 0 Word Number:38, Number of Pieces:255, Word ID:3

如果有人对为什么需要越来越长的时间有任何想法

最佳答案

该问题是由于每次输入词段时使用 tf.assign 引起的。这会导致图形随着每次创建新变量而增长。就我而言,每个单词被分成大约 250 个部分,因此所花费的时间迅速且大幅增加。

通过删除 tf.assign 方法并用占位符替换有问题的变量来解决该问题,该占位符是使用 feed_dict 而不是 tf.assign 设置的。

感谢@mrry 帮助我!

关于python - 用于语音识别的 Tensorflow LSTM 在训练每个后续单词时会变慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36477056/

相关文章:

python - Pandas:如何添加一个组合其他列中的多个列表的新列?

delphi - 语音识别效果不佳

python - 凯拉斯图像数据生成器 : problem with data and label shape

python - TensorFlow 联合 : How can I write an Input Spec for a model with more than one input

python - 命名元组中类型名的相关性

python - 如何读取包含保存为列表的字符串表示形式的测验问题和答案的文件?

python - 对两个列表进行排序,其中一个列表包含日期(python)

python - 使用 Python 语音识别时的说话人分类

ios - iPhone 模拟器 10.0 - 语音识别不可用

python - 使用 VGG 16 作为特征提取器的类似 U-net 的架构 - 连接层的问题