def sample(preds, temperature=1.0):
'''
Generate some randomness with the given preds
which is a list of numbers, if the temperature
is very small, it will always pick the index
with highest pred value
'''
preds = np.asarray(preds).astype('float64')
preds = np.log(preds) / temperature
exp_preds = np.exp(preds)
preds = exp_preds / np.sum(exp_preds)
probas = np.random.multinomial(1, preds, 1)
return np.argmax(probas)
以一定概率选择lstm输出,并不是简单地argmax
最新推荐文章于 2024-08-28 11:17:46 发布