【发布时间】:2020-04-08 07:05:22
【问题描述】:
简而言之问题
在Tensorflow 的Python 版本中,有一个tf.random.categorical() 方法可以从分类分布中抽取样本。但我在TensorFlow.js API 中找不到类似的方法。 那么,在 TensorFlow.js 中从分类分布中抽取样本的正确方法是什么?
问题详情
在Text generation with an RNN 教程中,tf.random.categorical() 方法在generate_text() 函数中用于决定应该在 RNN 输入旁边传递什么字符以生成序列。
predicted_id = tf.random.categorical(predictions, num_samples=1)[-1,0].numpy()
我正在试验 TensorFlow.js 并尝试在浏览器中生成类似莎士比亚的“随机”写作。除了使用tf.random.categorical() 方法的步骤之外,本教程的所有部分似乎都可以很好地协同工作。
我想手动编写 tf.random.categorical() 函数的替代方案应该不会那么难,而且已经有几个 3rd-party JavaScript 库已经实现了这个功能,但是将它作为 TensorFlow 的一部分看起来很合乎逻辑.js API。
【问题讨论】:
标签: tensorflow machine-learning tensorflow2.0 tensorflow.js tfjs-node