I have a binary text classification model loaded in tensorflowjs using loadGraphModel() and I wanna use the model to predict a sentence whether it is positive/negative. For example, a new sentence "I am sad" is passed into the model, and it will predict and output as negative. May I know how to do this, because model.predict() seems to work only for images.
This is my code snippet.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<p id="cat">I am sad</p>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@2.0.0/dist/tf.min.js"></script>
<script>
const MODEL_URL = './model.json';
const model = tf.loadGraphModel(MODEL_URL);
model.then(function (res){
const text = document.getElementById('cat').textContent;
const prediction = res.predict(text);
//Prediction should be 0(negative)
console.log(prediction)
});
</script>
</body>
</html>
This is the error in my console
Uncaught (in promise) Error: The dict provided in model.execute(dict) has keys: [0,1,2,3,4,5,6,7] that are not part of graph
at t.e.checkInputs (graph_executor.js:476:13)
at t.e.execute (graph_executor.js:140:10)
at t.e.execute (graph_model.js:288:34)
at t.e.predict (graph_model.js:242:17)
at test.html:18:27
Thank you.