Bucketing sentences by mood
Asked Answered
S

6

5

Let's start with a simple problem. Let's say that I have a 350 char sentence and would like to bucket the sentence into either a "Good mood" bucket or a "Bad mood" bucket.

What would be the best way to design an algorithm to bucket the sentence?

Schild answered 29/7, 2011 at 8:0 Comment(0)
T
5

Hand-classify a bunch of sentences by mood. Then feed these into a naive Bayes classifier. Use something like SpamBayes as a starting point.

Tellurian answered 29/7, 2011 at 8:10 Comment(0)
A
1

A simple/naive suggestion would be to either first split each sentence down into individual words, or use a regex and scan for specific words from both a "positive" list (e.g. "like", "happy", "can", "do", etc) and a "negative" list ("dislike", "sad", "can't", "don't"), work out which is more prevalent in each sentence, and bucket it accordingly.

Depending on your requirements and data-set this may be adequate, or you might want to investigate more advanced techniques like Bayesian filtering.

Anaphora answered 29/7, 2011 at 8:13 Comment(4)
The problem with this is if I said something like "that was not bad" it would show there are 2 words that are "bad" but it's really a positive sentence. Also, you can't do the even number = positive because "that went horribly wrong" is a bad sentence.Schild
I never said it would deal with all cases in a super smart way - it really depends on his data set and how much time he wants to spend on it. It may not be worth spending the time and effort on a "flawless" solution.Anaphora
You can build on the basic idea by considering not just words, but pairs of words, triples of words, and so on. By considering all n-tuples of words for all n, you can account for all the information. Without a huge amount of data, this generally won't provide much information for high values of n (beyond pairs or triples, in practice), so you'll want to truncate at a low value of n. But this is exactly what is done in a Bayes classifier, so save the effort and build on existing ones.Tellurian
Ok. So how would the pseudo code look (assuming you could get the sentence into an array of words)? Would you just loop through the wordArray looking for words and pairs of words? I guess I'd like to start coding up this algorithm.Schild
H
1

Depending on the domain of the sentences and on the required accuracy, this might be an extremely hard problem. There are many academic papers around sentiment analysis; a good start might be here - a short and classic paper.

The steps I'd suggest to take, would gradually lead to a better and better classifier:

  1. Hand classify some documents, and use them to train a ready made algorithm. I'd suggest using SVM (e.g. using LibSVM in WEKA, or SVMLight), but Naive bayes or decision trees, as suggested above, might work too.

  2. Hand classify some more documents, and move from a unigram-based model to a more sophisticated one, e.g. bigram or parts-of-speech based. This can be done quite easily with TagHelper tools, which will take your texts and transform them to WEKA-ready files using these techniques. This will add some context to the mood of each term (eg "not" and "bad" vs. "not bad").

  3. Finally, you can add custom made rules and dictionaries, which would add domain-specific knowledge to your algorithm. They might be represented as additional features for the same classification engine, or as an additional classification step.

Henryk answered 8/9, 2011 at 8:21 Comment(0)
O
1

This is called Sentiment Analysis, and the Wikipedia article has a good description of available techniques. One easy way out would be to use the Google Prediction API, and train it with a set of positive, negative, and neutral sentiment sentences.

Octameter answered 9/9, 2011 at 1:25 Comment(0)
C
0

You can play around with the Weka tool to train some classifier that will work well in your case. I would recommend trying the J48 algorithm which I believe is an implementation of the C4.5 algorithm for training decision trees.

Cerda answered 29/7, 2011 at 18:14 Comment(0)
R
0

Try machine learning from a bunch of such sentences. Use some features, for example smilies as indicators of mood. Observe the quality and add / modify your feature set.

Reclamation answered 29/7, 2011 at 19:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.