Skip to content

Problem with the bert analysis in a site #7662

@Aub16

Description

@Aub16

Hello,

While trying to include and try Bert on a website (code attached), I have this error (attached) I do not know if the error comes from an inconsistency in my code or an error from you (as it is already the case with BlazeFace). Could you help me?

<!DOCTYPE html>
<html>
<head>
  <title>Utiliser l'API BERT de TensorFlow.js</title>
  <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@3.7.0/dist/tf.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/bert@2.0.4/dist/bert.min.js"></script>
</head>
<body>
  <textarea id="input" rows="4" cols="50">Entrez votre texte ici</textarea>
  <button id="run-btn">Exécuter</button>
  <br />
  <div id="output"></div>
  <script>
    const input = document.getElementById('input');
    const output = document.getElementById('output');
    const runBtn = document.getElementById('run-btn');

    async function runBERT() {
      // Charger le modèle BERT
      const model = await bert.load();

      // Traitement du texte d'entrée
      const sentences = input.value.split('.').map(sentence => sentence.trim()).filter(sentence => sentence.length > 0);

      // Encodage des phrases avec BERT
      const encodedSentences = await model.encode(sentences);

      // Afficher les vecteurs d'encodage
      encodedSentences.array().forEach((sentence, i) => {
        output.innerHTML += `<p>Phrase ${i + 1}: ${sentence.join(',')}</p>`;
      });
    }

    runBtn.addEventListener('click', runBERT);
  </script>
</body>
</html>

image

Thank
Aubin DEVOGELAERE
aub1devo@gmail.com

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions