Message Boards Message Boards

[WSS18] Hearty- A Microsite That Helps You Reflect on Your Day

Posted 2 months ago
154 Views
|
0 Replies
|
3 Total Likes
|

This program uses machine learning with the Classify function in the Wolfram Language to analyze the sentiment of text input and face expressions to identify actions and sources of positive, negative, and neutral influences on your mood. It outputs word clouds that show the user how much certain activities or actions may influence their mood. It summarizes how negative and positive the person's day may have been based on the sentiment detected from each sentence of their daily log. It also detects how the person may have felt in a given day based on the facial expression present in the profile picture they put in.

Website Link: https://www.wolframcloud.com/objects/clloo/Hearty

Here is what the home page looks like: enter image description here

How it works

This function takes in a paragraph of text and outputs how many sentences are respectively positive, negative, and neutral:

countSentiments[ text_String ] := Module[{sentences , classifyResults, countPos,countNeg,countNeut, countsAssociation},

sentences = TextCases[text, "Sentence"];

classifyResults = Classify["Sentiment", sentences];

countsAssociation = Counts [classifyResults];

countPos = countsAssociation["Positive"];
countNeg = countsAssociation["Negative"];
countNeut = countsAssociation["Neutral"];
{countPos, countNeg, countNeut} /. _Missing -> 0

];

This function takes in a paragraph and outputs how many sentences are classified as positive, negative, and neutral sentiments:

countSentimentsAssociation[ text_String ] := Module[{sentences , classifyResults, countPos,countNeg,countNeut, countsAssociation},

sentences = TextCases[text, "Sentence"];

classifyResults = Classify["Sentiment", sentences];

countsAssociation = Counts [classifyResults]


];

This function creates a pie chart by nesting the countSentimentsAssociation function:

createPieChart [ text_String ] := PieChart[ countSentimentsAssociation[text],  ChartLabels -> Automatic];

This makes a list of only the positive sentences in a paragraph (like the other following functions, based on how the Classify function categorizes the sentiment of each sentence):

posSentences[ text_String ] := Module[{sentences, posList, classifyResults},

sentences = TextCases[text, "Sentence"];
posList = {};

classifyResults = Classify["Sentiment", sentences];
For[i=1,i<= Length[sentences],i++, If[Classify["Sentiment",sentences[[i]]]=="Positive",
                                                      AppendTo [posList,sentences[[i]]] , Nothing]];
posList
];

This function makes a list of only the negative sentences in a paragraph:

negSentences[ text_String ] := Module[{sentences, negList, classifyResults},

sentences = TextCases[text, "Sentence"];
negList = {};

classifyResults = Classify["Sentiment", sentences];
For[i=1,i<= Length[sentences],i++, If[Classify["Sentiment",sentences[[i]]]=="Negative",
                                                      AppendTo [negList,sentences[[i]]] , Nothing]];
negList
];

This function makes a list of only the neutral sentences in a paragraph:

neutSentences[ text_String ] := Module[{sentences, neutList, classifyResults},

sentences = TextCases[text, "Sentence"];
neutList = {};

classifyResults = Classify["Sentiment", sentences];
For[i=1,i<= Length[sentences],i++, If[Classify["Sentiment",sentences[[i]]]=="Neutral",
                                                      AppendTo [neutList,sentences[[i]]] , Nothing]];
neutList
];

This function extracts the nouns from the positive sentences in a paragraph:

posNouns[ text_String] := Module[{sentences, words, posNouns},

sentences = posSentences[text];
posNouns = Flatten[TextCases[#, "Noun"] & /@ sentences];                                                                                    

DeleteStopwords[posNouns]
]

This function extracts the verbs from the positive sentences in a paragraph:

posVerbs[ text_String] := Module[{sentences, words, posVerbs},
sentences = posSentences[text];
posVerbs = Flatten[TextCases[#, "Verb"] & /@ sentences];                                                                                       

DeleteStopwords[posVerbs]
]

This function extracts the nouns from the negative sentences in a paragraph:

negNouns[ text_String] := Module[{sentences, words, negNouns},

sentences = negSentences[text];
negNouns = Flatten[TextCases[#, "Noun"] & /@ sentences];                                                                                    

DeleteStopwords[negNouns]
]

This function extracts the verbs from only the negative sentences in a paragraph.

negVerbs[ text_String] := Module[{sentences, words, negVerbs},
sentences = negSentences[text];
negVerbs = Flatten[TextCases[#, "Verb"] & /@ sentences];                                                                                       

DeleteStopwords[negVerbs]
]

This function extracts the nouns from the neutral sentences in a paragraph:

neutNouns[ text_String] := Module[{sentences, words, neutNouns},

sentences = negSentences[text];
neutNouns = Flatten[TextCases[#, "Noun"] & /@ sentences];                                                                                   

DeleteStopwords[neutNouns]
]

This function extracts the verbs from the neutral sentences in a paragraph:

neutVerbs[ text_String] := Module[{sentences, words, neutVerbs},
sentences = neutSentences[text];
neutVerbs = Flatten[TextCases[#, "Verb"] & /@ sentences];                                                                                     

DeleteStopwords[neutVerbs]
]     

Finally, here is the section of the code with all of the functions defined above that analyzes the input and deploys the program to the cloud. It uses WordCloud on each of the groups of nouns and verbs sorted by sentiment to look at which words are used the most in the inputted daily log. Additionally, it determines how the user is feeling based on the facial expression in their profile picture.

CloudDeploy[

FormPage[{{"text","Daily log:"} ->"String" ,
{"image","Selfie of the day:"} -><|"Interpreter"->"Image","Required"-> False, "Default"->None|>},

Grid[{{"Positive actions: ",WordCloud[posVerbs[#text]],"Positive influences: ",WordCloud[posNouns[#text]]},{"Negative actions: ",WordCloud[negVerbs[#text]],"Negative influences: ",WordCloud[negNouns[#text]]},{"Neutral actions: ",WordCloud[neutVerbs[#text]],"Neutral influences: ",WordCloud[neutNouns[#text]]},{"Pie chart: ",createPieChart[#text],"Selfie: ",If[ #image === None, "No Selfie",
Column@{Classify["FacialExpression", #image],#image}]}}]&,
AppearanceRules-> <|"Title"->![Hearty Logo][3] ,"Description"->"Welcome to Hearty! This is a fun website meant to help you reflect on your day based on a daily log describing how you are feeling and a picture of yourself.  "|>]

,"Hearty"
, Permissions->"Public"]

Here is an example of what happens when you enter in a paragraph describing your day and a picture: enter image description here

Future Work

Machine learning can be further applied to a series of daily logs and selfies to look for patterns of mood and activities that the user inputs as well as identify stress factors. If implemented in a smartphone application, the program can be made to send notifications to the user when the algorithm determines it would be beneficial to the user's wellbeing. With the use of neural networks and other sources of data such as from Apple Health, more categories can be added to identify more specific moods such as anger, excitement, and sadness.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract