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?
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?
Hand-classify a bunch of sentences by mood. Then feed these into a naive Bayes classifier. Use something like SpamBayes as a starting point.
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.
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:
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.
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").
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.
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.
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.
© 2022 - 2024 — McMap. All rights reserved.