concept sentiment in category nlp

appears as: sentiment, sentiment, sentiments
Getting Started with Natural Language Processing

This is an excerpt from Manning's book Getting Started with Natural Language Processing.

  • Let’s imagine that sentiment is a quality of a review akin to temperature: the more positive a review is, the “warmer” the feelings of a user are towards a particular movie. Then, your sentiment analyzer is some sort of a thermometer: it measures the degree of a review on the negative to positive temperature scale. Under the most straightforward approach, each positive word may add exactly one degree to the overall temperature, and each negative word may take exactly one away.
  • Natural Language Processing in Action: Understanding, analyzing, and generating text with Python

    This is an excerpt from Manning's book Natural Language Processing in Action: Understanding, analyzing, and generating text with Python.

    Imagine all the possible tweets or messages or sentences that humans might write. Even though we do repeat ourselves a lot, that’s still a lot of possibilities. And when those tokens are each treated as separate, distinct dimensions, there’s no concept that “Good morning, Hobs” has some shared meaning with “Guten Morgen, Hannes.” We need to create some reduced dimension vector space model of messages so we can label them with a set of continuous (float) values. We could rate messages and words for qualities like subject matter and sentiment. We could ask questions like

    >>> products = get_data('hutto_products')
    ...    bags_of_words = []
    >>> for text in products.text:
    ...    bags_of_words.append(Counter(casual_tokenize(text)))
    >>> df_product_bows = pd.DataFrame.from_records(bags_of_words)
    >>> df_product_bows = df_product_bows.fillna(0).astype(int)
    >>> df_all_bows = df_bows.append(df_product_bows)
    >>> df_all_bows.columns                                                   #1
    Index(['!', '"', '#', '#38', '$', '%', '&', ''', '(', '(8',
           ...
           'zoomed', 'zooming', 'zooms', 'zx', 'zzzzzzzzz', '~', '½', 'élan',
           '-', '''],
          dtype='object', length=23302)
    >>> df_product_bows = df_all_bows.iloc[len(movies):][df_bows.columns]     #2
    >>> df_product_bows.shape
    (3546, 20756)
    >>> df_bows.shape                                                         #3
    (10605, 20756)
    >>> products[ispos] = 
     (products.sentiment > 0).astype(int)
    >>> products['predicted_ispositive'] = 
     nb.predict(df_product_bows.values).astype(int)
    >>> products.head()
    id  sentiment                                     text      ispos  pred
    0  1_1      -0.90  troubleshooting ad-2500 and ad-2600 ...      0     0
    1  1_2      -0.15  repost from january 13, 2004 with a ...      0     0
    2  1_3      -0.20  does your apex dvd player only play ...      0     0
    3  1_4      -0.10  or does it play audio and video but ...      0     0
    4  1_5      -0.50  before you try to return the player ...      0     0
    >>> (products.pred == products.ispos).sum() / len(products)
    0.5572476029328821

    Enough of the excitement, back to the hard work of training. You have a goal to work toward and that’s your labels for sentiment. You take your current vector and pass it into a standard feedforward network; in Keras that is a Dense layer. The current setup has the same number of elements in your semantic vector and the number of nodes in the Dense layer, but that’s just coincidence. Each of the 250 (hidden_dims) neurons in the Dense layer has 250 weights for the input from the pooling layer. You temper that with a dropout layer to prevent overfitting.

    Why would you choose a CNN for your NLP classification task? The main benefit it provides is efficiency. In many ways, because of the pooling layers and the limits created by filter size (though you can make your filters large if you wish), you’re throwing away a good deal of information. But that doesn’t mean they aren’t useful models. As you’ve seen, they were able to efficiently detect and predict sentiment over a relatively large dataset, and even though you relied on the Word2vec embeddings, CNNs can perform on much less rich embeddings without mapping the entire language.