Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

313
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda