Sentimental Analysis : PART 1

Sentimental Analysis refers to identify, extract, quantify, and study affective states and subjective information.
It helps to identify public emotion about certain topics/products. Humans are fairly intuitive when it comes to interpreting the tone of a piece of writing, but teaching a machine to identify emotion is tough. A negative sentence can be assumed by machine as positive. 
For example, In case of sarcastic sentence "I have lost my watch again. That's brilliant", humans can easily tell that it's a negative emotion framed in sarcasm but machine can assume that it's a positive sentence without knowing the context. Applying the contextual information, machine can identify it to be negative emotion.
Sentimental Analysis helps to gain insight from social data and to understand the consumer attitude and act accordingly. 

VOC(Voice Of The Customer) applications are primarily used by companies to determine what a customer is saying about a product or service. Sources of such data include emails, surveys, call centre logs and social media streams like blogs, tweets, forum posts, newsfeeds, and so on.

One more instance, can be for companies like Expedia who have millions of reviews on their website, from travellers all over the world. Given the nature of the site and the fact that their users are looking for a stress free experience, having to sift through hundreds of reviews to find a place to stay can be a real turn off. Text Analysis can be used here to build tools that can summarise multiple properties in 2-3 word phrases. Instead of scrolling through a list of hotel features like heated pool, massage therapy, buffet breakfast etc, you could simply say “Luxurious Hotel and Spa”.
Organisations will certainly become more aware of the applications of sentiment analysis within their marketplace, fueling the growth of sector specific services and technology delivering sentiment.


Below is a simple program written using NLP and python. The program runs and trains the model over the movie reviews data which gives an accuracy of "72.399%". 


import nltk.classify.util
from nltk.classify import NaiveBayesClassifier
from nltk.corpus import movie_reviews
from nltk.corpus import stopwords
from nltk.tokenize import word_tokenize
from nltk.corpus import wordnet


# This is how the Naive Bayes classifier expects the input
def create_word_features(words):
    useful_words =[word for word in words if word not in stopwords.words("english")]
    my_dict = dict([(word, True) for word in useful_words])
    return my_dict

print(movie_reviews.fileids)


neg_reviews = []
for fileid in movie_reviews.fileids('neg'):
    words = movie_reviews.words(fileid)
    neg_reviews.append((create_word_features(words), "negative"))

pos_reviews = []
for fileid in movie_reviews.fileids('pos'):
    words = movie_reviews.words(fileid)
    pos_reviews.append((create_word_features(words), "positive"))


train_set = neg_reviews[:750] + pos_reviews[:750]
test_set =  neg_reviews[750:] + pos_reviews[750:]
print(len(train_set),  len(test_set))

classifier = NaiveBayesClassifier.train(train_set)

accuracy = nltk.classify.util.accuracy(classifier, test_set)
print("classifier accuracy=",accuracy * 100)


review_santa = '''
   It would be impossible to sum up all the stuff that sucks about 
   this film,so I'll break it down into what I remember most strongly: 
   a man in an ingeniously fake-looking polar bear costume (funnier than the "bear" 
   from Hercules in New York);an extra with the most unnatural laugh you're ever likely 
   to hear;an ex-dope addict martian with tics; kid actors who make sure every 
   syllable of their lines are slowly and caaarreee-fulll-yyy prrooo-noun-ceeed; 
   a newspaper headline stating that Santa's been "kidnaped",and a giant robot. 
   Yes, you read that right. 
   A giant robot.The worst acting job in here must be when Mother Claus and 
   her elves have been "frozen" by the "Martians'" weapons. Could they be 
   *more* trembling? I know this was the sixties and everyone was 
   doped up, but still.
    '''

words = word_tokenize(review_santa)
words = create_word_features(words)
classifier.classify(words)


review_spirit = '''
Spirited Away' is the first Miyazaki I have seen, but from this stupendous film I
   can tell he is a master storyteller. A hallmark of a good storyteller is 
   making the audience empathise or pull them into the shoes of the central 
   character. Miyazaki does this brilliantly in 'Spirited Away'. During the first 
   fifteen minutes we have no idea what is going on. Neither does the main character 
   Chihiro. 
   We discover the world as Chihiro does and it's truly amazing to watch. 
   But Miyazaki doesn't seem to treat this world as something amazing. 
   The world is filmed just like our workaday world would. The inhabitants of the 
   world go about their daily business as usual as full with apathy as us normal 
   folks. Places and buildings are not greeted by towering establishing shots and
   majestic music.The fact that this place is amazing doesn't seem to concern Miyazaki.
   What do however, are the characters. Miyazaki lingers upon the characters as 
   if they were 
   actors. He infixes his animated actors with such subtleties that I have never 
   seen, even from animation giants Pixar. Twenty minutes into this film and I completely 
   forgot 
   these were animated characters; I started to care for them like they were living 
   and breathing. Miyazaki treats the modest achievements of Chihiro 
   with unashamed bombast. The uplifting scene where she cleanses the River 
   God is accompanied by 
   stirring music and is as exciting as watching gladiatorial combatants fight. 
   Of course, by giving the audience developed characters to care about, 
   the action and conflicts will always be more exciting, terrifying and 
uplifting than normal, generic action scenes.
''' words = word_tokenize(review_spirit) words = create_word_features(words) classifier.classify(words)

Comments

Popular posts from this blog

Arrays.sort() and Collections.sort() NullPointerException

org.xml.sax. SAXParseException: Element type "web-app" must be declared.

Project facet Java 6.0 is not supported by target runtime JBoss