Mood & Modality and Dialogue Sentiment | Towards Data Science

In this article, we will see how verbal functional categories used in customer dialogue text and how these categories contribute to the semantics, especially the text sentiment.
Verb phrase in a sentence sometimes can carry huge semantics, sometimes hint the sentiment only by itself even though if one does not see the rest of the context words, hence contribute to sentiment analysis models as important features. For example, cross all the not-included-in-any-VP words from the following customer reviews:
The product isn't working properly. I didn't like this product.I'm not satisfied with the product quality at all.
In order to charge meaning to the sentence, many languages like the verb to admit different inflections such as tense and person. Moreover most of the time we want to express our feeling and opinions about how the proposed action by the verb happened: are we sure, did we see the action by our own eyes, do we think it’s likely or unlikely?
This is more of a semantic capability, thus one usually needs more than inflecting the verb, more than grammatical constructions. Function of the verb is a broad topic, but I will explain some basic concepts before the statistical parts. You can skip to the next section if you have this background.
Tense is a grammatical realization of time by means of verbal inflection. English has 2 tenses: past and present. Future is not a tense not having an inflectional marker, but it is rather a time . Future time is formed either by will or with adverbs such as tomorrow , 8 o'clock or next week/month etc. As you see tense is a grammatical concept and time is rather a semantic concept.
Another concept is aspect, a grammatical category which reflects the action given by the verb happened with respect to time. English has two aspects:
action complete:    perfective      has moved, had movedaction in progress: progressive     is moving, was moving
One can summarize tense and aspect as follows:
Voice in English is either passive or active, as we learnt in high school. Passive voice has further semantic subcategories, but in this article, we will stay at high school level grammar 😉
Mood is a grammatical category indicating whether a verb expresses a fact (indicative mood) or conditionality (subjunctive mood). Some examples are:
Sun rises at 6 o'clock here.                           indicativeIt is important the manager be informed of the changes subjunctive
Mood is grammatical and associates to two semantic notions: modality and illocution. Illocution of a sentence can be thought as sentence type :
Go there!                                              imperativeDo you want to go there?                               interrogativeGod save the queen!                                    optativeI will see it.                                         declarative
Modality is a semantic notion that is related to speaker’s opinion and belief about the event’s believability, obligatoriness, desirability, or reality. Modality in English can be achieved by modal verbs (will/would, can/could, may/might, shall/should, must), modal adverbs (maybe, perhaps, possibly, probably), some subordinate clauses including (wish, it’s time,possible, probable, chance, possibility ), some modal nouns (decree, demand,necessity, requirement, request) or some modal adjectives (advisable, crucial, imperative, likely, necessary, probable, possible).
I would love you if things were different                irrealisYou may go                                               permissionI may come with you too                                  possibilityI might come with you too                                possibilityI must go                                                obligationHe must be earning good money                            necessityI can ride a bike                                        abilityI can come with you too                                  possibilityIt is possible that we might see big changes around us.  possibilityIt might be the truth                                    doubtI'm sure they'll come                                    confidenceLights are on, so he must be in the office             evidentiality
From now on, we will see the different verbal features that customers use to interact with conversational agents and how those usages lead to different semantics.
Let’s begin with our Chris, our voice assistant in your car and see some typical user utterances in automotive conversational AI.
Chris datasets include many imperative sentences:
navigatenavigate homestart navigationstop naviplay Britney Spearsplay musicsend a messageread my messages 
Sometimes the utterance consists only of a noun phrase:
musicdie navigationnew messages
Particles are always a part of any voice assistant dialogue dataset:
yesnopleaseyes please
Of course, some cursing and insulting are included, some in the form of sarcasm:
you suckyou are dumbyou are miserablea**chlochyou are so intelligent (!)
Chris is a driver assistant, so it is pretty normal that the utterances are succinct and to the point. It is not due to rudeness or roughness, just because one needs to speak short while driving. Compare the following two sentences, obviously, the first one is easier if you are driving:
Hey Chris, drive me homeHey Chris, shall we drive home together?
Imperative sentences in SLU are very common and definitely does not mean rudeness nor related to any speaker sentiment. Nothing interesting here really, first groups of utterances have verbs in the imperative mood, active voice and unmarked aspect. No modal verbs, no modal expressions or past tense. Sentiment for a voice assistant, in this case, better be calculated from the speech signal.
Spoken language may not be very exciting so far, then we can switch to written language which allows longer sentences hence more verb forms 😄 I used Women’s E-Commerce Clothing Reviews dataset to explore usage of verbal features. I will use lovely spaCy matcher (definitely not just because I am a contributor 😄) in this section. The dataset includes user reviews and ratings about purchases from a e-commerce website.
Before starting, let’s remember the POS tags related to verbs as we will go over the verbs mostly. English verbs have five forms: the base (VB and VBP), -s (VBZ), -ing (VBG), past (VBD), and past participle (VBN). Again, future time has no marker. Modal verbs can , could , might , may , will , would admit the tag MD .
Let’s begin with Voice , matching patterns to passive voice are is/was adverb* past-participle-verb and have/has/had been adverb* past-participle-verb . Corresponding Matcher patterns can be:
{"TEXT": {"REGEX": "(is|was)"}}, {"POS": "ADV", "OP": "*"}, {"TAG": "VBN"}and {"LEMMA": "have"}, {"TEXT":"been"}, {"POS": "ADV", "OP": "*"}, {"TAG": "VBN"}
The first pattern is is/was , followed by any number of adverbs, then a past participle verb. POS is for UD POS tags and TAG is for extended POS. The second pattern is similar: have , has and had is represented by lemma : have .
I’ll first import spaCy, load English model then add these two rules to the Matcher object:
import spacyfrom spacy.matcher import Matchernlp = spacy.load("en_core_web_sm")matcher = Matcher(nlp.vocab)pass1 = [{"TEXT": {"REGEX": "(is|was)"}}, {"POS": "ADV", "OP": "*"}, {"TAG": "VBN"}pass2 = [{"LEMMA": "have"}, {"TEXT":"been"}, {"POS": "ADV", "OP": "*"}, {"TAG": "VBN"}]matcher.add("pass1", None, pass1)matcher.add("pass2", None, pass2)
Then I run the Matcher against the dataset and here are some passive voice examples, both from positive and negative reviews:
one wash and this was ruined!washed them according to directions and they were ruined.this could not have been returned fasteri kept it anyway because the xs has been sold out, and got it taken in a bit.it is simply stunning and indeed appears to have been designed by an artist.would buy this again in several different colors if they were offeredif these were presented in other colors, i would buy those as well
How do the number of passive voice verbs in a review correlate to the review rating? First of all, let’s see the rating distribution of the reviews:
Next, we see the distribution of passive voice verb counts in reviews. Many reviews do not include passive voice at all, some have one passive verb and few have more than one passive construction.
Do the number of passive voice verbs correlate to the review rating? From the below, indeed no (checking out the heatmap alone is enough, it points to no correlation at all).
No surprise looking at the corpus sentences, passive voice can be “designed by a famous designer” or “they are returned”. While referring to the cloths, how it is designed, tailored, done can be negative or positive; it is returned, ruined, presented can be negative or positive as well.
Let’s see how the time of the verb tense and aspect correlates to the review rating. Remember past and present tense are easy to calculate (by looking at the verb inflection), and future is not really a tense since there is no inflection. We will count number of future time occurrences by counting wills, going tos and time adverbs.
We can do the tense-aspect table again with Matcher patterns this time:
I will also count present perfect progressive tense (“have been doing”) and past perfect progressive tense (“had been doing”), they will contribute both perfective and progressive aspect counts for present and past tenses.
Here are some examples of the tense and aspects used in the reviews:
I love, love, love this jumpsuit. it's fun, flirty, and fabulous! every time i wear it, i get nothing but great compliments!fits nicely! i'm 5'4, 130lb and pregnant so i bough t medium to grow into.I have been waiting for this sweater coat to ship for weeks and i was so excited for it to arrive. this coat is not true to size and made me look short and squat.I have been searching for the perfect denim jacket and this it!I had been eyeing this coat for a few weeks after it appeared in the email, and i finally decided to purchase it to treat myself.
What about the future time? Since there is no morphological marker, we can get help from will , going to , plan to , in 2/5/10 days , next week/month/summer , the day after tomorrow ...
Corresponding Matcher patterns can be:
future_modal = [{"TEXT": "will", "TAG": "MD"}]future_adv = [{"TEXT": {"REGEX": "(plan(ning) to|(am|is|are) going to)"}}time_expr1 = [{"TEXT": {"REGEX": "((next|oncoming)(week|month|year|summer|winter|autumn|fall|)|the day after tomorrow)"}}]time_expr2 = [{"TEXT": "in"}, {"LIKE_NUM": True}, {"TEXT": {"REGEX":"(day|week|month|year)s"}}]
and examples from the corpus are:
sadly will be returning, but i'm sure i will find something to exchange it for!I love this shirt because when i first saw it, i wasn't sure if it was a shirt or dress. since it is see-through if you wear it like a dress you will need a slip or wear it with leggings.Just ordered this in a small for me (5'6", 135, size 4) and medium for my mom (5'3", 130, size 8) and it is gorgeous - beautifully draped, all the weight/warmth i'll need for houston fall and winter, looks polished snapped or unsnapped. age-appropriate for both my mom (60's) and myself (30's). will look amazing with skinny jeans or leggings.This will be perfect for the mild fall weather in texasThere's no extra buttons to replace the old one with and i'm worried more of the coat is going to fall apart.This is going to be my go to all season.i plan to wear it out to dinner for my birthday and to a house party on new years day....i am planning to exchange this and hoping it doesn't happen againit is nice addition to my wardrobe and i am planning to wear it to the multiple occasionthis is one of those rare dresses that looks good on me now and will still look good on me in 6 months when i've got a huge belly.
According to the below counts, customers used past tense a lot. Present tense is also used widely, whereas future time is used once or twice in each review.
Here are the corresponding histograms:
According to the heatmap below, usage present and future tense is not really correlated to the rating; both negative and positive ratings include these two tensed verbs. However, past tense looks a bit negatively correlated; more usage of the past tense means worse rating. Perfective and progressive aspects also do not look very bright, they are also a bit negatively correlated.
The below ridgeline plot shows some information, better reviews tends to have a spike towards 0 usage of past tense; unhappier customers tend to have a smoother usage of past tense instead. A possible explanation might be customers complained a lot: “package came late”, “waistline didn’t fit”, “I couldn’t zip”, “I didn’t like it”; whereas happy customers look to the future 😄We all look to the future when we are happier, don’t we?😉
As we saw, modality is a semantic notion and the same modal can give different modalities. Let’s see different semantics could introduced for an example:
i love that i could dress it up for a party, or down for work.                                                         possibilitythe straps are very pretty and it could easily be nightwear too.                                                         possibilitythis is a light weight bra, could be a little more supportive. pretty color, with nice lines.                              irrealisI bought this and like other reviews, agree that the quality probably could be better, but i still love it enough to keep.                                                            irrealisgot it on sale, but it still could've been cheaper.                                                            irrealisBought a large, could barely pull up over my butt.                                                             ability
could is correlated to both negative and positive sentiment. Possibility mood looks like on the positive side, where irrealis looks like being both positive or negative.
What about couldn't ? It is a whole another story, examples below show how much couldn't provides semantic richness to both negative and positive sentiment, though almost all examples include only one type of modality:
so small in fact that i could not zip it up!                 abilityi was so excited to get his dress for my wedding shower and then i couldn't wear it :(                                          abilityi really tried because the fabric is wonderful and the shirt is light and breezy for summer, i just couldn't make it work    abilityi simply couldn't resist!                                    i could not be more pleased and regret not having bought this item earlier, since i would have enjoyed wearing it during the holidays.i could not be happier with the purchase and the keyhole in the back is a beautiful detail.                                                                                                           emphasizing opinioni also thought that this was very heavy for a maxi dress and could not imagine wearing it in 80 degree weather.               ability              i think it's maybe a little too long (or short, i can't figure it out) but i couldn't pass up this skirt because the pattern is so pretty.                                                     ability                                                 i just wish it was more of a blue denim blue but nonetheless, i could not walk away from the store without this.           ability
would and wouldn't might feel different but statistically, they are similar to could and couldn't :
Irrealis happens both in negative and positive reviews. Consider:
maybe if i weren't as small chested this wouldn't be an issue for me. i definitely recommend this tee.the neckline wouldn't even stay up on my upper body, it was that loose.
Then no surprise that the presence of would/wouldn’t/could/couldn’t does not give away much about the review sentiment.
Corresponding Matcher pattern would be
[{"TEXT": {"REGEX": "(would|could|can|might|may)"}, "TAG": "MD"}]
MD being the modal verb tag and we exclude will .
Dear readers, here we reach the end of this article. We had a great time with spaCy, haven’t we (as usual)? 😃 We process huge amounts of data every day but sometimes we forget to read what is written in the corpus. Language is not just a bunch of words coming together; it has many aspects, both statistical and linguistical. Today we enjoyed both. Next time we will continue with statistical discourse for voice assistants. Till next time, you can always visit Chris on https://chris.com. You can also visit me on https://duygua.github.io always. Meanwhile stay happy, safe and tuned!
Palmer, F. (2001), Mood and Modality (2nd ed., Cambridge Textbooks in Linguistics). Cambridge: Cambridge University Press. doi:10.1017/CBO9781139167178