How to use the @tensorflow/tfjs-layers.loadModel function in @tensorflow/tfjs-layers

To help you get started, we’ve selected a few @tensorflow/tfjs-layers examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rajveermalviya / language-modeling / web / main.js View on Github external
modelLoadingNotice.style.display = "block";
  btnsDiv.style.display = "none";
  inputTextField.style.display = "none";

  rippleSurface.forEach(i => MDCRipple.attachTo(i));

  let mdcTextField = new MDCTextField(inputTextField);
  MDCTopAppBar.attachTo(document.querySelector("#app-bar"));
  let drawer = new MDCTemporaryDrawer(document.querySelector("#drawer"));

  document.querySelector("#menu").addEventListener("click", () => {
    drawer.open = true;
  });

  const model = await loadModel("/web_model/model.json");

  /**
   * Predict next word
   * @param {string} string Input String.
   * @param {number} numPrediction Total number of prediction to get.
   */
  window.predictNextWord = async (string, numPrediction) => {
    isQuestion = false;
    string = string.toLowerCase().split(" ");
    let indexes = stringToIndexes(string);
    if (indexes.length >= NUMBER_OF_WORDS) {
      notice.style.display = "none";
      indexes = indexes.slice(-NUMBER_OF_WORDS);
      let prediction = await model.predict(tensor([indexes]));
      prediction = (await prediction.data()).slice(forSlicingPredictionArray_A, forSlicingPredictionArray_B);
      let predictionString = indexesToString(await doArgMax(prediction, numPrediction));