<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>artificial intelligence Archives - Turbolab Technologies</title>
	<atom:link href="https://turbolab.in/tag/artificial-intelligence/feed/" rel="self" type="application/rss+xml" />
	<link>https://turbolab.in/tag/artificial-intelligence/</link>
	<description>Big Data and News Analysis Startup in Kochi</description>
	<lastBuildDate>Mon, 27 Sep 2021 06:30:32 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://i0.wp.com/turbolab.in/wp-content/uploads/2018/03/turbo_black_trans-space.png?fit=32%2C32&#038;ssl=1</url>
	<title>artificial intelligence Archives - Turbolab Technologies</title>
	<link>https://turbolab.in/tag/artificial-intelligence/</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">98237731</site>	<item>
		<title>Sentiment Analysis: Concepts, Models, and Examples</title>
		<link>https://turbolab.in/sentiment-analysis-concepts-models-and-examples/</link>
					<comments>https://turbolab.in/sentiment-analysis-concepts-models-and-examples/#respond</comments>
		
		<dc:creator><![CDATA[Anthony]]></dc:creator>
		<pubDate>Mon, 27 Sep 2021 06:30:32 +0000</pubDate>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[artificial intelligence]]></category>
		<category><![CDATA[data analysis]]></category>
		<category><![CDATA[Data Science]]></category>
		<category><![CDATA[machine learning]]></category>
		<category><![CDATA[natural language processing]]></category>
		<category><![CDATA[nlp]]></category>
		<category><![CDATA[Sentiment Analysis]]></category>
		<guid isPermaLink="false">https://turbolab.in/?p=607</guid>

					<description><![CDATA[<p>Sentiment analysis is a sub field of Natural Language Processing (NLP) that identifies and extracts emotions expressed in given texts. It is a machine learning tool that understands the context and determines the polarity of text, whether it is positive, neutral, or negative. This article will discuss what sentiment analysis is, where it is being [&#8230;]</p>
<p>The post <a href="https://turbolab.in/sentiment-analysis-concepts-models-and-examples/">Sentiment Analysis: Concepts, Models, and Examples</a> appeared first on <a href="https://turbolab.in">Turbolab Technologies</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><span style="font-weight: 400">Sentiment analysis is a sub field of Natural Language Processing (NLP) that identifies and extracts emotions expressed in given texts. It is a machine learning tool that understands the context and determines the polarity of text, whether it is positive, neutral, or negative.</span></p>
<p><span style="font-weight: 400">This article will discuss what sentiment analysis is, where it is being used, and how to use a pre-trained model to analyze sentiments from texts.</span></p>
<p><span style="font-weight: 400">We will also explore the approach on how Machine Learning models are used to build sentiment analytic tools.</span></p>
<h3></h3>
<h3><b>Use cases of sentiment analysis:</b></h3>
<ul>
<li style="font-weight: 400"><span style="font-weight: 400">Brand Monitoring</span></li>
<li style="font-weight: 400"><span style="font-weight: 400">Customers Feedback</span></li>
<li style="font-weight: 400"><span style="font-weight: 400">Product Analytics</span></li>
<li style="font-weight: 400"><span style="font-weight: 400">Monitoring Market Research</span></li>
<li style="font-weight: 400"><span style="font-weight: 400">Analyzing Movie Reviews</span></li>
</ul>
<p><span style="font-weight: 400">There are various pre-trained sentiment analysis tools available in Natural Language Processing (NLP) libraries. Such as NLTK’s Vader sentiment analysis tool, TextBlob, Flair sentiment classifier based on LSTM neural network, etc.</span></p>
<h3></h3>
<h3></h3>
<h3><b>Part 1- Sentiment analysis using a pre-trained model (TextBlob)</b></h3>
<p><span style="font-weight: 400">TextBlob is a python library for Natural Language Processing (NLP). It helps you perform complex analysis and operations on textual data.</span></p>
<h4><b>Steps to apply the TextBlob model to achieve sentiments are given here:</b></h4>
<p><span style="font-weight: 400">Before applying Textblob, basic text cleaning should be done. You can check NLTK or Spacy libraries for various text cleaning methods.</span></p>
<p>&nbsp;</p>
<blockquote><p><span style="font-weight: 400">from textblob import TextBlob</span></p>
<p>&nbsp;</p>
<p><span style="font-weight: 400">def sentimental(text: str) -&gt; str:</span></p>
<p><span style="font-weight: 400">    sentiment = None</span></p>
<p><span style="font-weight: 400">    if text:</span></p>
<p><span style="font-weight: 400">        text = &#8216; &#8216;.join(text.split()).strip() # removing empty strings</span></p>
<p><span style="font-weight: 400">        blob = TextBlob(text)</span></p>
<p><span style="font-weight: 400">        if blob.sentiment.polarity &gt; 0:</span></p>
<p><span style="font-weight: 400">            sentiment = &#8216;Positive&#8217;</span></p>
<p><span style="font-weight: 400">        if blob.sentiment.polarity &lt; 0:</span></p>
<p><span style="font-weight: 400">            sentiment = &#8216;Negative&#8217;</span></p>
<p><span style="font-weight: 400">        if blob.sentiment.polarity == 0:</span></p>
<p><span style="font-weight: 400">            sentiment = &#8216;Neutral&#8217;</span></p>
<p><span style="font-weight: 400">    return sentiment</span></p></blockquote>
<h4></h4>
<p>&nbsp;</p>
<h4><b>Output Result:</b></h4>
<p><em><span style="font-weight: 400">sentimental(&#8220;This is what a true masterpiece looks like. Thrillingly played with a flawless ensemble cast.&#8221;)</span></em></p>
<p><em><span style="font-weight: 400">Out: &#8216;<strong>Positive</strong>&#8216;</span></em></p>
<p><span style="font-weight: 400">TextBlob returns the ‘polarity’ of a sentence. Polarity lies between [-1,1].</span></p>
<p><span style="font-weight: 400">-1 defines </span><b>Negative</b><span style="font-weight: 400">, 0 defines </span><b>Neutral,</b><span style="font-weight: 400"> and 1 defines </span><b>Positive</b><span style="font-weight: 400">.</span></p>
<h3></h3>
<p>&nbsp;</p>
<h3><b>Part 2 &#8211; Train a Machine Learning Model for sentiment analysis</b></h3>
<p><span style="font-weight: 400">In this part, we will be using a Supervised Machine Learning model called Support Vector Machines (SVM) to train the model.</span></p>
<h4></h4>
<h4><b>Data Gathering: </b></h4>
<p><span style="font-weight: 400">Here we will choose</span><a href="http://www.cs.cornell.edu/people/pabo/movie-review-data/"> <b>sentiment polarity datasets 2.0</b></a><span style="font-weight: 400"> which is a classified movie dataset with labels, and transformed into CSVs.</span></p>
<p><span style="font-weight: 400">Data is divided into </span><b>“trainData”</b><span style="font-weight: 400"> and </span><b>“testData”. </b><span style="font-weight: 400">The dataset contains “Content” and “Label” columns.</span></p>
<p>&nbsp;</p>
<p><img data-recalc-dims="1" fetchpriority="high" decoding="async" data-attachment-id="609" data-permalink="https://turbolab.in/sentiment-analysis-concepts-models-and-examples/senti5/" data-orig-file="https://i0.wp.com/turbolab.in/wp-content/uploads/2021/09/senti5.png?fit=888%2C548&amp;ssl=1" data-orig-size="888,548" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="senti5" data-image-description="" data-image-caption="" data-medium-file="https://i0.wp.com/turbolab.in/wp-content/uploads/2021/09/senti5.png?fit=300%2C185&amp;ssl=1" data-large-file="https://i0.wp.com/turbolab.in/wp-content/uploads/2021/09/senti5.png?fit=800%2C494&amp;ssl=1" class="wp-image-609 aligncenter" src="https://i0.wp.com/turbolab.in/wp-content/uploads/2021/09/senti5.png?resize=576%2C355&#038;ssl=1" alt="" width="576" height="355" srcset="https://i0.wp.com/turbolab.in/wp-content/uploads/2021/09/senti5.png?resize=300%2C185&amp;ssl=1 300w, https://i0.wp.com/turbolab.in/wp-content/uploads/2021/09/senti5.png?resize=768%2C474&amp;ssl=1 768w, https://i0.wp.com/turbolab.in/wp-content/uploads/2021/09/senti5.png?resize=480%2C296&amp;ssl=1 480w, https://i0.wp.com/turbolab.in/wp-content/uploads/2021/09/senti5.png?w=888&amp;ssl=1 888w" sizes="(max-width: 576px) 100vw, 576px" /></p>
<p>&nbsp;</p>
<h4><b>Data Vectorization</b></h4>
<p><span style="font-weight: 400">Before feeding our model with data, we need to extract features from our textual dataset, basically converting the text data into vectors. TF-IDF is one of many methods to extract features from text documents. TF-IDF stands for &#8216;Term Frequency &#8211; Inverse Document Frequency.</span></p>
<blockquote><p><span style="font-weight: 400">from sklearn.feature_extraction.text import TfidfVectorizer</span></p>
<p>&nbsp;</p>
<p><span style="font-weight: 400"># Create feature vectors</span></p>
<p><span style="font-weight: 400">vectorizer = TfidfVectorizer(min_df = 5,</span></p>
<p><span style="font-weight: 400">                             max_df = 0.8,</span></p>
<p><span style="font-weight: 400">                             sublinear_tf = True,</span></p>
<p><span style="font-weight: 400">                             use_idf = True)</span></p>
<p><span style="font-weight: 400">train_vectors = vectorizer.fit_transform(trainData[&#8216;Content&#8217;])</span></p>
<p><span style="font-weight: 400">test_vectors = vectorizer.transform(testData[&#8216;Content&#8217;])</span></p></blockquote>
<h4></h4>
<p>&nbsp;</p>
<h4><b>Model Building</b></h4>
<p><span style="font-weight: 400">After generating vectors for both train and test input sets, we can now feed the SVC model with this data and train it.</span></p>
<blockquote><p><span style="font-weight: 400"># importing libraries</span></p>
<p><span style="font-weight: 400">from sklearn import svm</span></p>
<p><span style="font-weight: 400">from sklearn.metrics import classification_report</span></p>
<p>&nbsp;</p>
<p><span style="font-weight: 400"># Initialising SVM classifier with linear kernel</span></p>
<p><span style="font-weight: 400">svm_classifier = svm.SVC(kernel=&#8217;linear&#8217;)</span></p>
<p>&nbsp;</p>
<p><span style="font-weight: 400"># training the model with the train data</span></p>
<p><span style="font-weight: 400">svm_classifier.fit(train_vectors, trainData[&#8216;Label&#8217;])</span></p>
<p>&nbsp;</p>
<p><span style="font-weight: 400"># testing the model in test data content</span></p>
<p><span style="font-weight: 400">predicted_result = svm_classifier.predict(test_vectors)</span></p>
<p>&nbsp;</p>
<p><span style="font-weight: 400"># results</span></p>
<p><span style="font-weight: 400">report = classification_report(testData[&#8216;Label&#8217;], predicted_result, output_dict=True)</span></p>
<p><span style="font-weight: 400">print(&#8216;Model accuracy: &#8216;, report[&#8216;accuracy&#8217;])</span></p></blockquote>
<h4></h4>
<p>&nbsp;</p>
<h4><b>Model Results and Statistics:</b></h4>
<p><em><span style="font-weight: 400">Model accuracy:  <strong>0.915</strong></span></em></p>
<p><span style="font-weight: 400">Model accuracy shows the ratio of the number of correctly predicted classes to the total number of input samples. Accuracy is one of many metrics used for evaluating classification problems.</span></p>
<p><span style="font-weight: 400">Here the accuracy is 0.915, which shows that the model has learned the data quite well as the range of accuracy is calculated between 0 to 1.</span></p>
<h4><b>Testing the Model to Predict on Movie Reviews:</b></h4>
<p><em><span style="font-weight: 400">svm_classifier.predict(vectorizer.transform(&#8220;This is what a true masterpiece looks like. Thrillingly played with a flawless ensemble cast.&#8221;))</span></em></p>
<p><em><span style="font-weight: 400">Out: ‘<strong>Positive</strong>’</span></em></p>
<p>&nbsp;</p>
<p><img data-recalc-dims="1" decoding="async" data-attachment-id="610" data-permalink="https://turbolab.in/sentiment-analysis-concepts-models-and-examples/sent4/" data-orig-file="https://i0.wp.com/turbolab.in/wp-content/uploads/2021/09/sent4.png?fit=996%2C644&amp;ssl=1" data-orig-size="996,644" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="sent4" data-image-description="" data-image-caption="" data-medium-file="https://i0.wp.com/turbolab.in/wp-content/uploads/2021/09/sent4.png?fit=300%2C194&amp;ssl=1" data-large-file="https://i0.wp.com/turbolab.in/wp-content/uploads/2021/09/sent4.png?fit=800%2C517&amp;ssl=1" class=" wp-image-610 aligncenter" src="https://i0.wp.com/turbolab.in/wp-content/uploads/2021/09/sent4.png?resize=545%2C353&#038;ssl=1" alt="" width="545" height="353" srcset="https://i0.wp.com/turbolab.in/wp-content/uploads/2021/09/sent4.png?resize=300%2C194&amp;ssl=1 300w, https://i0.wp.com/turbolab.in/wp-content/uploads/2021/09/sent4.png?resize=768%2C497&amp;ssl=1 768w, https://i0.wp.com/turbolab.in/wp-content/uploads/2021/09/sent4.png?resize=980%2C634&amp;ssl=1 980w, https://i0.wp.com/turbolab.in/wp-content/uploads/2021/09/sent4.png?resize=480%2C310&amp;ssl=1 480w, https://i0.wp.com/turbolab.in/wp-content/uploads/2021/09/sent4.png?w=996&amp;ssl=1 996w" sizes="(max-width: 545px) 100vw, 545px" /></p>
<p>&nbsp;</p>
<p><span style="font-weight: 400">Classification accuracy alone can be misleading if you have an unequal number of observations. A confusion matrix can give you a better idea of what our model is predicting correctly.</span></p>
<p><span style="font-weight: 400">Here we have taken 200 test samples and as shown in the matrix above, we got 9 False positives, which means it has falsely predicted the negative as positive. There were also 8 False negatives, where it has falsely predicted the positive as negative.</span></p>
<p><span style="font-weight: 400">To reduce these errors we can train the model with a larger dataset.</span></p>
<p>&nbsp;</p>
<p><img data-recalc-dims="1" decoding="async" data-attachment-id="611" data-permalink="https://turbolab.in/sentiment-analysis-concepts-models-and-examples/senti2/" data-orig-file="https://i0.wp.com/turbolab.in/wp-content/uploads/2021/09/senti2.png?fit=1338%2C916&amp;ssl=1" data-orig-size="1338,916" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="senti2" data-image-description="" data-image-caption="" data-medium-file="https://i0.wp.com/turbolab.in/wp-content/uploads/2021/09/senti2.png?fit=300%2C205&amp;ssl=1" data-large-file="https://i0.wp.com/turbolab.in/wp-content/uploads/2021/09/senti2.png?fit=800%2C548&amp;ssl=1" class="wp-image-611 aligncenter" src="https://i0.wp.com/turbolab.in/wp-content/uploads/2021/09/senti2.png?resize=559%2C382&#038;ssl=1" alt="" width="559" height="382" srcset="https://i0.wp.com/turbolab.in/wp-content/uploads/2021/09/senti2.png?resize=300%2C205&amp;ssl=1 300w, https://i0.wp.com/turbolab.in/wp-content/uploads/2021/09/senti2.png?resize=768%2C526&amp;ssl=1 768w, https://i0.wp.com/turbolab.in/wp-content/uploads/2021/09/senti2.png?resize=1024%2C701&amp;ssl=1 1024w, https://i0.wp.com/turbolab.in/wp-content/uploads/2021/09/senti2.png?resize=1080%2C739&amp;ssl=1 1080w, https://i0.wp.com/turbolab.in/wp-content/uploads/2021/09/senti2.png?resize=1280%2C876&amp;ssl=1 1280w, https://i0.wp.com/turbolab.in/wp-content/uploads/2021/09/senti2.png?resize=980%2C671&amp;ssl=1 980w, https://i0.wp.com/turbolab.in/wp-content/uploads/2021/09/senti2.png?resize=480%2C329&amp;ssl=1 480w, https://i0.wp.com/turbolab.in/wp-content/uploads/2021/09/senti2.png?w=1338&amp;ssl=1 1338w" sizes="(max-width: 559px) 100vw, 559px" /></p>
<h3></h3>
<h3></h3>
<h3></h3>
<h3><b>Conclusion</b></h3>
<p><span style="font-weight: 400">In this article, we have mentioned the TextBlob (pre-trained) Python package and SVM (Machine Learning) model to determine sentiment analysis. But the field of sentiment analysis is an exciting research direction due to a large number of real-world applications where discovering people’s opinions is important in better decision-making.</span></p>
<p><span style="font-weight: 400">Although detecting sentiment using NLP is surprisingly a difficult task, such as when we face sentences that are put in sarcastic ways. These types of textual context can mislead NLP-based model predictions. We can even see that both the model prediction results are not the same for all samples. Here the TextBlob model performs and predicts better with ‘neutral’ tagging of </span><span style="font-weight: 400">articles. This is because TextBlob is using more data to train the model and has neutral tagged data in the training set.</span></p>
<p><span style="font-weight: 400">To overcome such difficult tasks, we can use deep learning models like LSTM, RNN, etc. We can even make use of transformer-based models like GPT-3 and T5 from google for sentiment analysis.</span></p>
<p>The post <a href="https://turbolab.in/sentiment-analysis-concepts-models-and-examples/">Sentiment Analysis: Concepts, Models, and Examples</a> appeared first on <a href="https://turbolab.in">Turbolab Technologies</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://turbolab.in/sentiment-analysis-concepts-models-and-examples/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">607</post-id>	</item>
	</channel>
</rss>
