-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathsentiment-v1.js
More file actions
40 lines (31 loc) · 925 Bytes
/
sentiment-v1.js
File metadata and controls
40 lines (31 loc) · 925 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/* Sentiment Analysis
*/
let sentiment;
let status;
let submitButton;
let inputBox;
let sentimentResult;
function setup() {
noCanvas();
sentiment = ml5.sentiment('movieReviews', modelReady);
console.log('loading model');
status = select('#status');
inputBox = createInput('it is a happy moment in life');
inputBox.size('size', '25');
status.child(inputBox);
submitButton = createButton('check sentiment');
status.child(submitButton);
submitButton.mousePressed(checkSentiment);
sentimentResult = createP('getting ready to use...');
status.child(sentimentResult);
}
function checkSentiment() {
const txt = inputBox.value();
const prediction = sentiment.predict(txt);
sentimentResult.html('sentiment score: ' + prediction.score);
console.log(prediction);
}
function modelReady() {
console.log('model loaded');
sentimentResult.html('ready to try, click "check sentiment" button');
}