【问题标题】:LSTM text generation with Keras: What is diversity?使用 Keras 生成 LSTM 文本:什么是多样性?
【发布时间】:2018-04-02 21:05:21
【问题描述】:

我正在开发一个使用 Keras 和 LSTM 的小型文本生成项目。 Chollet 的代码运行良好。有人可以向我解释多样性步骤 0.2、.05、1.0、1.2 吗?这里到底发生了什么?提前致谢!

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()

https://github.com/fchollet/keras/blob/master/examples/lstm_text_generation.py

【问题讨论】:

    标签: python deep-learning keras lstm


    【解决方案1】:

    这些只是 温度 超参数的不同值。

    This answer 很好地解释了温度在这种情况下的含义。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-14
      • 1970-01-01
      • 2016-08-05
      • 2018-06-13
      • 2017-05-31
      • 2019-09-07
      • 2019-02-07
      • 2023-03-10
      相关资源
      最近更新 更多