如何解决在LSTM Tensorflow.js模型的`.fit`中使用什么参数来输出隐藏状态和单元状态?
我正在尝试更改官方lstm-text-generation的tfjs-examples示例中使用的模型以输出其隐藏状态。为此,我在createModel
中更改了model.js
函数,如下所示:
export function createModel(sampleLen,charSetSize,lstmLayerSizes) {
const inputs = tf.input({ shape: [sampleLen,charSetSize] });
let outputs = inputs;
for (let i = 0; i < lstmLayerSizes.length; ++i) {
const lstmLayerSize = lstmLayerSizes[i];
const layer = tf.layers.lstm({
units: lstmLayerSize,// Not sure if this is necessary
returnSequences: i < lstmLayerSizes.length - 1,// As far as I understood,this returns the state
returnState: i === lstmLayerSizes.length - 1,});
outputs = layer.apply(outputs);
}
// Destructure the hidden state (optionally also the cell state in the next step)
const [lstmOutput,hiddenState] = outputs;
outputs = tf.layers
.dense({ units: charSetSize,activation: 'softmax' })
.apply(lstmOutput);
// Return the hidden state as part of the model outputs
return tf.model({ inputs,outputs: [outputs,hiddenState] });
}
我不了解我需要如何更改.fit
中fitModel
的{{1}}参数:
model.js
训练后的模型似乎还不错。但是,当我将其可视化时,就像this Standford演讲中所做的那样,隐藏状态没有任何意义。
我在做什么有意义吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。