{"id":1663,"date":"2016-08-19T14:19:43","date_gmt":"2016-08-19T05:19:43","guid":{"rendered":"http:\/\/blog.themusio.com\/?p=1663"},"modified":"2024-05-01T10:56:50","modified_gmt":"2024-05-01T01:56:50","slug":"musios-emotion-classifier","status":"publish","type":"post","link":"https:\/\/blog.themusio.com\/?p=1663","title":{"rendered":"Musio&#8217;s emotion classifier"},"content":{"rendered":"<div id=\"table-of-contents\">\n<h2>Table of Contents<\/h2>\n<div id=\"text-table-of-contents\">\n<ul>\n<li><a href=\"#org7a8d122\">1. Musio&#8217;s emotion classifier&#xa0;&#xa0;&#xa0;<span class=\"tag\"><span class=\"emotion\">emotion<\/span>&#xa0;<span class=\"classifier\">classifier<\/span><\/span><\/a>\n<ul>\n<li><a href=\"#org616c594\">1.1. goal<\/a><\/li>\n<li><a href=\"#orga728007\">1.2. motivation<\/a><\/li>\n<li><a href=\"#org401cf68\">1.3. ingredients<\/a><\/li>\n<li><a href=\"#orgbc59fe7\">1.4. steps<\/a><\/li>\n<li><a href=\"#orga44741a\">1.5. outlook<\/a><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<h1>Musio&#8217;s emotion classifier     <a id=\"org7a8d122\"><\/a><\/h1>\n<h2>goal<a id=\"org616c594\"><\/a><\/h2>\n<p>In today&#8217;s summary we take a look at the emotion classifier applied in Musio and layout some details of the data and models we use.<\/p>\n<h2>motivation<a id=\"orga728007\"><\/a><\/h2>\n<p>Sentiment classification is in general an important task, since as humans our intention is never to only convey plain content.<br \/>\nThe way we phrase things is as important as the message itself in human interaction.<br \/>\nAnd sometimes misinterpreting the emotions of one&#8217;s counterpart will lead to awkward situations.<br \/>\nHence, Musio has to learn to read the emotional status of it&#8217;s users to take part in their daily life.<\/p>\n<h2>ingredients<a id=\"org401cf68\"><\/a><\/h2>\n<p>emotion, sentiment analysis, MLP, spacy, facial expressions<\/p>\n<h2>steps<a id=\"orgbc59fe7\"><\/a><\/h2>\n<p>As every task or problem in machine learning, we started by gathering the appropriate data set for building an emotional system for Musio.<br \/>\nData sets for sentimental analysis are rather limited to the domain of movie ratings and consequently text fragments are most often only labeled with either positive or negative opinion.<br \/>\nSimilar limitations hold also for product reviews and ratings.<br \/>\nThat&#8217;s why we create our own data set consisting of the following features and labels.<br \/>\nWe labeled sentences by one out of 9 emotional states.<br \/>\nThese are joy, trust, anticipation, surprise, sadness, fear, disgust, anger and a neutral label.<br \/>\nIn addition we came up with three additional features that allow us characterize the pleasure a user experiences, the physiological and psychological state a user is in, also called arousal, and the dominance that is exerted.<br \/>\nTo give an example, we have a look at the following sentence.<\/p>\n<p><em>&#8220;Playing games is always fun and relaxing.&#8221;<\/em><\/p>\n<p>First we associate an emotion with it, say joy in this case.<br \/>\nThen we fix a value for the pleasure between -9 and +9, here maybe 3, for the arousal between 0 and 9, say 5, and for the dominance we pick 6 between 0 and 9.<\/p>\n<p>Before we come to discussing the models, we spent some more time on properly handling the data.<br \/>\nFor the encoding part of our language models, we again rely on spacy which generates word vectors and whole sentence vectors for us.<br \/>\nIn a next step we normalize the values for pleasure, arousal and dominance by computing the mean and the variance.<br \/>\nAs a last step we have to take care of some bias in our data set which is related to the neutral label being quite frequent compared to the other emotional states.<\/p>\n<p>For the task at hand which is to label sentences by an emotion, we use the deep learning library Keras for fast building of our models and easy experimenting.<br \/>\nAs our model we choose a Multi-Layer-Perceptron and feed it with sentence vectors created by spacy.<\/p>\n<pre><code class=\"python\">model = Sequential()\nmodel.add(Dense(input_dim=300,output_dim=100, init='uniform'))\nmodel.add(Activation('tanh'))\nmodel.add(Dropout(0.05))\nmodel.add(Dense(input_dim=100,output_dim=50))\nmodel.add(Activation('tanh'))\nmodel.add(Dropout(0.05))\nmodel.add(Dense(input_dim=50,output_dim=20))\nmodel.add(Activation('tanh'))\nmodel.add(Dropout(0.05))\nmodel.add(Dense(input_dim=20,output_dim=nb_classes))\nmodel.add(Activation('softmax'))\n\nmodel.compile(optimizer='adagrad',\n              loss='mse',\n              metrics=['accuracy'])\n\nmodel.fit(x_train,y_train,nb_epoch=1000,batch_size=100)\n<\/code><\/pre>\n<p>We reduce the dimension of the layers towards the end and finally end up with a distribution over the different emotional states.<br \/>\nIn between we apply non-linear activation functions in terms of tanh and use dropout to a certain degree.<br \/>\nInstead of using spacy&#8217;s given sentence vectors we also experimented with building an encoder model consisting of LSTMs and initiated the word embedding layer using word2vec.<\/p>\n<p>We additionally use a similar model that allows us to infer the pleasure, arousal and dominance values from a given user utterance.<br \/>\nActually, it is the outcome of this model at inference that goes into the control of Musio&#8217;s physiology.<br \/>\nWe use the pleasure, arousal and dominance value to coordinate Musio&#8217;s facial expressions and to decide on the color of his heart.<br \/>\nFurther we intend to adjust the sound of Musio&#8217;s voice according to these values.<br \/>\nFinally, Musio&#8217;s emotional state changes depending on the classification of the user utterance which then might lead to distinct sentimental responses.<\/p>\n<h2>outlook<a id=\"orga44741a\"><\/a><\/h2>\n<p>In an upcoming blog post, we are going to take a look at the entity recognition system implemented in Musio and his ability to distinguish gender.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Table of Contents 1. Musio&#8217;s emotion classifier&#xa0;&#xa0;&#xa0;emotion&#xa0;classifier 1.1. goal 1.2.  [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3640,3644],"tags":[3650,3760,3656,3762,3658,3700,3704,3910,3912,3838,3914,3710,3714,3916,3918],"class_list":["post-1663","post","type-post","status-publish","format-standard","hentry","category-all-en","category-musio-en","tag-ai-ja-en","tag-artificial-intelligence-en","tag-baggage-en","tag-children-book-ja-en","tag-christmas-en","tag-cmos-en","tag-emotion-ja-en","tag-facial-expressions-en","tag-iot-ja-en","tag-learn-english-en","tag-mlp-en","tag-musio-en","tag-recurrent-neural-network-en","tag-sentiment-analysis-en","tag-spacy-en"],"aioseo_notices":[],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/blog.themusio.com\/index.php?rest_route=\/wp\/v2\/posts\/1663","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.themusio.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.themusio.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.themusio.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.themusio.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1663"}],"version-history":[{"count":4,"href":"https:\/\/blog.themusio.com\/index.php?rest_route=\/wp\/v2\/posts\/1663\/revisions"}],"predecessor-version":[{"id":10872,"href":"https:\/\/blog.themusio.com\/index.php?rest_route=\/wp\/v2\/posts\/1663\/revisions\/10872"}],"wp:attachment":[{"href":"https:\/\/blog.themusio.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1663"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.themusio.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1663"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.themusio.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1663"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}