Building a Sentiment Analyzer Application

So far in this chapter, one of the subjects that has been discussed is what is called as “Sentiment Analysis.” With this, the AI application is trying to gauge what the literal mood is of the end user when any communication is received in a written text format. Even when the message is spoken, given the sheer levels of sophistication of both the AWS and Azure, the Biometric modality of Voice Recognition can be used to gauge the particular mood of the individual as well. This kind of concept is typically deployed in real-time market research, especially when it comes to test marketing a brand new product or service before it is launched to the mass public. In this application, we make use of hypothetical movie review files illustrated in the last application.

Here is the Python source code:

From nltk.classify import NaiveBayesClassifier From nltk.classify.util import accuracy as nltk_accuracy #Extract features from the input list of words Def extract_features (words):

Return dict([word, True) for word in words])


#Load the data from the corpus Fields_pos = movie_reviews.fields (‘pos’)

Fields_neg = movie_reviews.fields (‘neg’)

#Extract the features form the movie reviews Features_pos = [(extract_features (movie_reviews.words(

Fileside=[f])), ‘Positive’) for fin fields_pos]

Features_neg = [(extract_features (movie_reviews.words(

Fileside=[f])), ‘Negat’) for fin fields_pos]

#Define the train and test split (80% and 20%)

Threshold = 0.8

Num_pos = int (threshold = len (features_pos))

Num_neg = int (threshold = len (features_neg))

#Create training and training datasets

Features_train = features_pos [:num_pos] + features_neg [:num_neg] Features_test = features_pos [:num_pos] + features_neg [:num_neg]

#Print the number of datapoints that are used

Print (‘ Number of training datapoints:’, len (features_train))

Print (‘Number of test datapoints: len (features_test))

#Train a Naive Bayes classifier

Classifier = NaiveBayesClassifier.train (features_train)

Print (‘ Accuracy of the classifier:’, nltk_accuracy(

Classifier, features_test))


Print (‘ Top ‘ + str(N) + most informative words:’)

For I, item in enumerate (classifier.most_informative_features()]:

Print (str (i+1) + ‘, ‘ + item[0])

If I ==N-1 Break

#Test input movie reviews Input_reviews = [

‘Movie was great’,

‘Movie was good’,

‘Movie was OK’,

‘Movie was bad’,

‘Movie was horrible’,

‘I would not recommend this movie’,

‘I would recommend this movie’,


Print(“ Movie review predictions:”)

For review in input_reviews:

Print(“ Review:”, review)

#Compute the statistical probabilities Probabilities = classifier.prob_classify (extract_

Features (review.split()))

#Pick the maximum value Predicted_sentiment = probabilities.max ()

#Print outputs

Print (“Predicted sentiment:”, predicted_sentiment)

Print (“Probability:”, round (probabilities.prob (predicted_sentiment),))

(Artasanchez & Joshi, 2020).

Application of Neural Networks to Predictive Maintenance

Preventing equipment failures and accidents is critical for companies and governments. Unnecessary downtime can reduce revenues and increase costs significantly, negatively impacting profitability. In military and defense, not only is this expensive, but critical missions can be impacted or canceled. These can also result in significant human injury or death. Thus, significant value is attached to predicting and avoiding these failures and accidents. Predictive maintenance can be a key to avoiding such events.

Physics-based models have typically been used to identify when a complex machine or process is trending toward failure. Completely accurate physics modeling of all of the complex interactions between subsystems is not currently possible. Furthermore, as the assets age, undergo maintenance, and have parts replaced, the behavior of the system begins to drift from the original physics models. What is required are models that can learn how the system is changing over time. Machine Learning models using Neural Networks are capable of doing just that.

As has been emphasized before, Machine Learning models require lots of training data, and that is even more true for Neural Networks. Fortunately, modern machinery and processes have a large number of sensors measuring temperature, pressure, vibration, fluid flow, etc. which are collected and stored in data historians. So, more than enough data is generally available for training Neural Network models.

However, as described in the previous chapters, Machine Learning techniques use supervised learning which requires that the training data be labeled with the expected results. In this case, this means labeled examples of equipment or process failures. Labeled training data of this type could be generated by running a collection of these industrial assets to failure in all of the possible failure modes. Obviously, this is impractical given the complexity and expense of these industrial systems. Furthermore, these systems are inherently highly reliable, which further complicates collecting data of actual failures. Thus, what is available is a large quantity of historical data with a very limited subset of past failure modes. This limited amount of labeled training data usually makes supervised Machine Learning techniques ineffective.

< Prev   CONTENTS   Source   Next >