【发布时间】:2020-04-22 23:54:43
【问题描述】:
我已将其精简为尽可能少的代码行,以便深入了解此问题。
目前这些是下面的配置常量(我使用长度为 1 的数组来表示我正在对其进行语义分析的标记词。
export const top_words = 10000;
export const max_review_length = 1
export const embedding_vector_length = 32
这是代码,我暂时用模拟标记或一个字长替换了张量。我收到 typescript linting 错误,显示 .print() 或 .dataSync()[0] 会因为它们不存在而失败。有问题的代码行(.predict)正在返回一个没有打印或数据同步方法的张量
const x_train = tf.tensor([[80], [86], [10], [1], [2]]);
const y_train = tf.tensor([[1],[1],[1],[0],[0]])
const x_val = tf.tensor([[1], [3], [102], [100], [104]]);
const y_val = tf.tensor([[0],[0],[1],[1],[1]])
const model = tf.sequential();
model.add(tf.layers.embedding({ inputDim: dictionary.size, inputLength: max_review_length, outputDim: 1 }))
model.add(tf.layers.lstm({units: 200, dropout: 0.2, recurrentDropout: 0.2}))
model.add(tf.layers.dense({units: 1, activation:'sigmoid'}))
model.compile({ loss:'binaryCrossentropy', optimizer:'rmsprop', metrics:['accuracy'] })
const history=model.fit(x_train, y_train,{epochs: 12, batchSize: 5})
history.then(hist => console.log(hist.history.loss)) // Show error loss vs epoch
const predictOut = model.predict(tf.tensor2d([10]))
predictOut.print() 或 predictOut.dataSync()[0] 返回
【问题讨论】:
-
它们只是检查错误还是代码真的抛出异常?
-
“张量”类型上不存在属性“dataSync”
|张量 []'。或属性“打印”... -
这是运行时异常还是 linting 错误?
-
它既是 linting 也是运行时
-
尝试
console.log(predictOut)时会记录什么?
标签: tensorflow.js