Created
November 4, 2020 08:34
-
-
Save oscar-defelice/0f7ef608012965301a112c4cfbc0a926 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function predict() { | |
const predictedClass = tf.tidy(() => { | |
const text = document.getElementById("myText").value; | |
const tokenisation = tokenise(text, word2index); | |
const predictions = model.predict(tf.tensor2d(tokenisation, [1, maxLen])); | |
return predictions.as1D().argMax(); | |
}); | |
const classId = (await predictedClass.data())[0]; | |
var predictionText = ""; | |
switch(classId){ | |
case 0: | |
predictionText = "Text is classified as Business News"; | |
break; | |
case 1: | |
predictionText = "Text is classified as Science-Technology News"; | |
break; | |
case 2: | |
predictionText = "Text is classified as Sport News"; | |
break; | |
case 3: | |
predictionText = "Text is classified as World News"; | |
break; | |
} | |
document.getElementById("prediction").innerText = predictionText; | |
predictedClass.dispose(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment