concept sentiment analyzer in category nlp

appears as: sentiment analyzer, sentiment alyzer
Real-World Natural Language Processing

This is an excerpt from Manning's book Real-World Natural Language Processing.

In Section 1.1.2, we saw how not to do NLP. In this chapter, we are going to discuss how to do NLP in a more principled, modern way. Specifically, we’d like to build a sentiment analyzer using a neural network. Even though the sentiment analyzer we are going to build is a simple application and the library (AllenNLP) takes care of most heavy-lifting, it is a full-fledged NLP application which covers a lot of basic components of modern NLP and machine learning. I’ll introduce important terms and concepts along the way. Don’t worry if you don’t understand some concepts at the first try. Later chapters will revisit most of the concepts introduced here.

Figure 2.10: Running the sentiment analyzer on web browser
Listing 4.2:  Training pipeline for the sentiment analyzer
EMBEDDING_DIM = 128
HIDDEN_DIM = 128
 
reader = StanfordSentimentTreeBankDatasetReader()
 
train_dataset = reader.read('path/to/sst/dataset/train.txt')
dev_dataset = reader.read('path/to/sst/dataset/dev.txt')
 
vocab = Vocabulary.from_instances(train_dataset + dev_dataset,
                                  min_count={'tokens': 3})
 
token_embedding = Embedding(
    num_embeddings=vocab.get_vocab_size('tokens'),
    embedding_dim=EMBEDDING_DIM)
 
word_embeddings = BasicTextFieldEmbedder({"tokens": token_embedding})
 
encoder = PytorchSeq2VecWrapper(
    torch.nn.LSTM(EMBEDDING_DIM, HIDDEN_DIM, batch_first=True))
 
model = LstmClassifier(word_embeddings, encoder, vocab)    #A
optimizer = optim.Adam(model.parameters())    #B
 
iterator = BucketIterator(batch_size=32,    #C
                          sorting_keys=[("tokens", "num_tokens")])
 
iterator.index_with(vocab)
 
trainer = Trainer(model=model,    #D
                  optimizer=optimizer,
                  iterator=iterator,
                  train_dataset=train_dataset,
                  validation_dataset=dev_dataset,
                  patience=10,
                  num_epochs=20)
 
trainer.train()
Getting Started with Natural Language Processing

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

You are planning an evening out with some friends and you’d like to go to a cinema to watch one of the recently released movies. Your friends’ preferences seem to have divided between a superhero movie and an action movie. Both start around the same time and you like both genres. To choose which group of friends to join at the cinema, you decide to check what those who have already seen these movies think about them. You visit a movie review website and find out that there are hundreds of reviews about both movies. Reading through all these reviews would not be feasible, so you decide to apply a sentiment analyzer to see how many positive and negative opinions there are about each of these movies and then make up your mind.

Figure 7.9 Mental Model for this task: two ways of implementing a sentiment analyzer
A screenshot of a cell phone Description automatically generated