gpt4 book ai didi

python - 递归神经网络中的时期与迭代

转载 作者:太空宇宙 更新时间:2023-11-03 15:02:41 25 4
gpt4 key购买 nike

我正在查看 text generation example Keras 使用 RNN 和 LSTM,但仍然对术语epochiteration 之间的区别感到困惑。

尽管如此,here是前一个问题问同样的事情,我无法理解 answer ,或者这个答案与我的理解不同,也与以下示例的处理方式不同。基于此answer ,据说

one epoch = one forward pass and one backward pass of all the training examples

number of iterations = number of passes, each pass using [batch size] number of examples.

Example: if you have 1000 training examples, and your batch size is 500, then it will take 2 iterations to complete 1 epoch.

得出结论:(#training examples/batch size) = (#iterations/#epochs)

但是,以下example ,据我了解,与之前的结论不同。

# train the model, output generated text after each iteration
for iteration in range(1, 60):
print()
print('-' * 50)
print('Iteration', iteration)
model.fit(X, y, batch_size=128, nb_epoch=1)

start_index = random.randint(0, len(text) - maxlen - 1)

for diversity in [0.2, 0.5, 1.0, 1.2]:
print()
print('----- diversity:', diversity)

generated = ''
sentence = text[start_index: start_index + maxlen]
generated += sentence
print('----- Generating with seed: "' + sentence + '"')
sys.stdout.write(generated)

for i in range(400):
x = np.zeros((1, maxlen, len(chars)))
for t, char in enumerate(sentence):
x[0, t, char_indices[char]] = 1.

preds = model.predict(x, verbose=0)[0]
next_index = sample(preds, diversity)
next_char = indices_char[next_index]

generated += next_char
sentence = sentence[1:] + next_char

sys.stdout.write(next_char)
sys.stdout.flush()
print()

这里,迭代60epoch的数量设置为1,这让我很困惑很多。似乎有 60 次迭代,如for iteration in range(1, 60) 所述。对于每个迭代,一个epoch按照model.fit(X, y, batch_size=128, nb_epoch=1)所述完成对于每个for循环。同样,这里有一个 batch_size=128。那么迭代到底是什么意思?

谁能根据这个例子解释iterationepoch之间的区别

最佳答案

我认为在这个例子中,iteration 意味着不同的东西:你在学习过程中迭代,并且在每个 epoch 之后你都在用部分学习的模型做一些事情。您正在迭代地执行此操作,这就是使用迭代 词的原因。

关于python - 递归神经网络中的时期与迭代,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36133662/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com