Published
Edited
Jun 25, 2019
2 forks
12 stars
Insert cell
Insert cell
Insert cell
Insert cell
sentiment = {
const predictOut = model.predict(inputTensor);
const score = predictOut.dataSync()[0];
predictOut.dispose();
return score;
}
Insert cell
inputTensor = {
const inputBuffer = tf.buffer([1, metadata.max_len], "float32");
for (let i = 0; i < inputText.length; ++i) {
const word = inputText[i];
inputBuffer.set(metadata.word_index[word] + metadata.index_from, 0, i);
}
const input = inputBuffer.toTensor();
return input;
}
Insert cell
model = await tf.loadModel(
"https://storage.googleapis.com/tfjs-models/tfjs/sentiment_cnn_v1/model.json"
)
Insert cell
metadata = (await fetch(
"https://storage.googleapis.com/tfjs-models/tfjs/sentiment_cnn_v1/metadata.json"
)).json()
Insert cell
tf = require("@tensorflow/tfjs@0.10.0")
Insert cell
d3 = require('d3@5')
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more