Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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));