开发者

Can I use NLTK to determine if a comment is a positive one or a negative one?

Can you show me a simple example using http://www开发者_Go百科.nltk.org/code to determine if a string about a happy or upset mood?


NLTK cannot out of the box, but if you are looking for some related research on that area, take a look at this paper on Offensive Language Detection. The same methods could be adapted to detect comments which are not offensive/unoffensive, but instead happy/unhappy. The primary software package being used in this project for text classification is called WEKA and uses multiple classifiers, trained on previous examples, to determine whether language is offensive or not (and in this method uses a tunable threshold).


Pattern is something worthwhile a test drive too: you can see two opinion mining experiments right on the project homepage.

http://www.clips.ua.ac.be/pages/pattern-examples-100days

http://www.clips.ua.ac.be/pages/pattern-examples-elections


Nopey.

This is a task far beyond the capabilities of NLTK or any grammatical parser that is known or can be realistically imagined. Look at the NLTK Book to see what sorts of tasks it can accomplish which are far, far from your stated purpose.

As a cheap example:

I really enjoyed using your paper to train my dog.

Parse that up with NLTK and you can get

[('I', 'PRP'), ('really', 'RB'), ('enjoyed', 'VBD'), 
 ('using', 'VBG'), ('your', 'PRP$'), ('paper', 'NN'), 
 ('to', 'TO'), ('train', 'VB'), ('my', 'PRP$'), ('dog', 'NN')]

Where the parse tree would tell me that 'enjoyed' is the central (past-tense) verb of the simple sentence. To enjoy something is good. To train something is generally a good thing. Gerunds, nouns, comparatives, and such are relatively neutral. So give this a Good score of 0.90.

Except I really mean that I either hit my dog with your paper or let it excrete on the paper which you'd probably consider a not Good thing.

Hire a person for this recognition task.

Added for those who imagine that even trained classifiers are of much use:

Classify this real entry from a real customer review corpus using any classifier you like trained on any dataset you like:

This camera keeps on autofocussing in auto mode with a buzzing sound which can't be stopped. It would be really good if they have given an option to stop this autofocussing. If you want to have the date and time on the image, it's only through their software which reads the image's date and time from the image's meta-data. So if you use your card reader and copy images - you got to once again open them through their software to put the date and time. In that too, there isn't a direct way to add date and time - you got to say 'print images' to a different directory in which there is an option to specify the date and time . Even the slightest of the shakes totally distorts your image. Indoor images weren't so clear. You got to have flash 'on' to get it even though your room is well lit. The lens cap is a really annoying. the movie clips taken will always have some 'noise' in it - you can't avoid that.

The worst mood classification I obtained was "totally equivocal" yet humans can easily determine that this is anything but complimentary. This wasn't a randomly picked datum, rather one that was selected for negative bias without "hate" or "suxz" or similar.


You're looking for a technique that uses a machine learning classifier to determine whether a piece of text is positive or negative. There have been various different attempts at this by a number of research teams (e.g. http://research.yahoo.com/pub/2387 and http://lingcog.iit.edu/doc/appraisal_sentiment_cikm.pdf) we can get about 80% to 90% accuracy at determining whether a product review is positive or negative.

Due to the brevity of your question, it's not obvious to me whether determining whether a product review is positive or negative is the same task you're trying to accomplish, or merely a related task, but I'd suggest starting simple with bag-of-words classification with a Bayesian classifier (which NLTK should be able to handle), and then improve your techniques from there depending on how the accuracy turns out.

Unfortunately, I've never used NLTK (nor Python for that matter) so I can't give you a code example of how to use NLTK for this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜