Search…
sentiment.predict
Provides sentiment analysis. Pass innerText to the sentimentPredict function and it returns a score which will evaluate to positive or negative sentiment based on value above or below 50.
Typical usage
//Generated Script id=0
var delayKey = 1000;
var sentimentkey = 'none';
var sentiment = ml5.sentiment('movieReviews', modelReady);
function modelReady() {
setTimeout(function(){
var element = document.querySelector('div > div:nth-of-type(3)');
// model is ready
var prediction = sentiment.predict(element.innerText);
var output = parseFloat(prediction.score) > 0.5 ? 'positive' : 'negative';
console.log(prediction.score + ' ' + output);
sentimentkey = prediction.score + ' ' + output;
},/*delay*/1*delayKey);
}
//endcode
Copy link