Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

305
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda