python - 具有急切执行的 TensorFlow 多项式分布
问题描述
我来自本教程,它基于来自我们的 RNN 的预测张量,在急切执行中使用多项分布来获得下一个字符的最终预测以生成文本。
# using a multinomial distribution to predict the character returned by the model
temperature = 0.5
predictions = predictions / temperature
predicted_id = tf.multinomial(predictions, num_samples=1)[-1,0].numpy()
我的问题是:
温度(这里是 0.5)不只是缩放所有预测,为什么它会影响多项式选择呢?
[0.2, 0.4, 0.3, 0.1]/温度 = [0.4, 0.8, 0.6, 0.2]
那么多项式不是对概率进行归一化吗?因此,在缩放时,我们只是增加每个字符的概率,限制为 1?
[-1, 0].numpy() 有什么作用?我完全迷失了这个。
任何提示表示赞赏。
解决方案
- [i, :] 表示所有类的非标准化对数概率。
因此,首先概率越小,温度小于 1 的概率就越小。温度大于 1 的概率越大:
math.exp(0.4)/math.exp(0.8) = 0.670
math.exp(0.3)/ math.exp(0.6) = 0.7408
math.exp(0.2)/ math.exp(0.4) = 0.818
math.exp(0.1)/ math.exp(0.2) = 0.9048
[-1, 0].numpy()
只是得到多项式张量的值
如:
tf.multinomial(predictions, num_samples=1)
tf.Tensor([[3]], shape=(1, 1), dtype=int64)
to 3
推荐阅读
- regex - 正则表达式查找单词中的所有字符是否都是相同的特定字符
- java - Oracle NoSQL 连接池和事务管理
- python - 如何避免 Python 编码中的外部错误、安全错误?
- css - 用改变数量的子视频元素填充父容器,每个元素都有纵横比
- html - 在 p-panel 内居中对齐 p-chart
- reactjs - 如何以最简洁的方式处理错误和成功响应?
- tweepy - Tweeter API:如何使用 Tweepy.cursor 按关键字搜索(例如 trump)和按关注者数量搜索(例如大于 10000)
- r - highcharter - 如何在地图上的国家/地区显示我的数据值?
- resharper - 有没有办法让 ReSharper 检查正确的文件头
- ruby-on-rails - RSpec:请求规范中的存根控制器方法