Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

310
Views
How to perform text classification using tensorflowjs

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.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!