Text Analytics
Tags: textanalytics, datamining, bigdata
Published: 2017-08-12 23:35:09

---
title: Text Analytics
published: true
description: Finding knowledge in the text through association mining and relationship discovery. 
tags: Text Analytics, Data Mining, Big Data
canonical_url: http://techscouter.blogspot.in/2017/08/text-analysis-part-1.html
cover_image: http://www.dataversity.net/wp-content/uploads/2014/09/analyticspix.jpg
---

<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-b6oEfHpnNZo/WYbl77A-x2I/AAAAAAAABps/CemAjXZhbDUdcuPVcibYL3pVujMLUtn9wCEwYBhgL/s1600/text-mining.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="337" data-original-width="598" src="https://1.bp.blogspot.com/-b6oEfHpnNZo/WYbl77A-x2I/AAAAAAAABps/CemAjXZhbDUdcuPVcibYL3pVujMLUtn9wCEwYBhgL/s1600/text-mining.jpg" /></a></div>

Hi Readers,
Recently I was going through some text analytics activities at work and learned some techniques for text analytics and mining.

In this series of posts, I will be sharing my experiences and learnings.
<h2 style="text-align: left;">
Introduction</h2>
Firstly the jargon Text Analysis and Text Mining are sub domains of the term Data Mining and are used interchangeably in most scenarios.
Broadly&nbsp;<b>Text Analysis</b>&nbsp;refers to,
Extracting information from textual data keeping the problem for which we want to get data in mind.
and&nbsp;<b>Text Mining</b>&nbsp;refers to,
the process of getting textual data.

<div style="text-align: left;">
Nowadays, a large quantity of data is produced by humans.Data is growing faster than ever before and by the year 2020, about&nbsp; 1.7 megabytes of new information will be created every second for every human being on the planet and one of the main components of this data will be textual data.</div>
Some of the main sources of textual data are

<ul style="text-align: left;">
<li>Blogs</li>
<li>Articles</li>
<li>Websites</li>
<li>Facebook</li>
<li>Comments</li>
<li>Discussion Forums</li>
<li>Reviews</li>
</ul>
<div>
<div class="separator" style="clear: both; text-align: center;">
</div>

<div class="separator" style="clear: both; text-align: center;">
<a href="https://2.bp.blogspot.com/-jgpbpNjeirM/WYbozkEV7wI/AAAAAAAABp4/R_6bOwPd2MUv34iObsXsf83IUBjZdoIlQCLcBGAs/s1600/observer.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="185" data-original-width="646" src="https://2.bp.blogspot.com/-jgpbpNjeirM/WYbozkEV7wI/AAAAAAAABp4/R_6bOwPd2MUv34iObsXsf83IUBjZdoIlQCLcBGAs/s1600/observer.png" /></a></div>

In the scenario described in the image above every observer may perceive the real world in a different manner and express accordingly e.g different persons may have a different opinion on some&nbsp;topic.
So, while analysing&nbsp;textual data this type of bias ness&nbsp;has to be kept in mind.

<h4 style="text-align: left;">
Type of information that can be extracted from the text and converted into actionable knowledge can be</h4>
<ul style="text-align: left;">
<li>Mining content of data</li>
<li>Mining knowledge about the language</li>
<li>Mining knowledge about the observer</li>
<li>Infer other&nbsp;real world variables</li>
</ul>
<h2 style="text-align: left;">
NLP</h2>
<div>
NLP stands for natural language processing, a subdomain of Machine Learning that deals with processing of natural language spoken by humans and make it understandable for a machine.

It is a fairly complex problem as understanding natural language involves common sense which machines&nbsp;lack. Many of the sentences spoken by humans involve common sense and are spoken in some context which derives the meaning of the sentence.E.g
<ul style="text-align: left;">
<li>He is an apple of my eye.(Phrase)</li>
</ul>
<h4 style="text-align: left;">
<ul style="text-align: left;">
<li><span style="font-weight: normal;">John is the star.(Movie star or celestial body)&nbsp;</span></li>
</ul>

Analyzing the Natural language can be broadly classified into 4 types of analysis</h4>
<div>
<ol style="text-align: left;">
<li>Lexical Analysis-Identifying Parts of Speech, Word Associations, Topic&nbsp;Mining</li>
<li>Syntactical Analysis-Connecting words and creating phrases and then connecting phrases</li>
<li>Semantical Analysis-Extracting knowledge about the sentence</li>
<li>Pragmatic&nbsp;Analysis-Getting the intent of the &nbsp;sentence</li>
</ol>
<div>

</div>
</div>
</div>
</div>
<h2 style="text-align: left;">
Lexical Analysis</h2>
<div>
By the definition lexical analysis means converting of a sequence of characters into the sequence of words with some defined meanings.</div>
<div>
Definitions of words can be</div>
<div>
<ul style="text-align: left;">
<li>POS Tags(Nouns,Verbs,Adverbs etc)</li>
<li>Word Associations(How two words are linked)</li>
<li>Topic(Context of the Paragraph)</li>
<li>Syntagmatic words&nbsp;</li>
</ul>
</div>
<div>

</div>
<div>
In this article, I will be writing about&nbsp;<b>Word Associations&nbsp;</b>which is the analysis of how different words are linked to each other. Look at the following sentences</div>
<div>
<ul style="text-align: left;">
<li>&nbsp;"<i>Jack drives a car",&nbsp;</i>"car" is associated to "drive"</li>
<li>"<i>I love cats"</i></li>
<li>"<i>I love dogs</i>", In these sentences, the word cats is related to dogs as they can be used interchangeably to make a valid sentence</li>
</ul>
<div>
In the first sentence &nbsp;"<i>Jack drives a car",</i>&nbsp;the type of relationship between "car " and "drive" is called
<b>
</b> <b>Syntagmatic Relation</b>.&nbsp;</div>
</div>
<div>
Two words are called syntagmatically related if the probability of both the words occurring in the same sentence is high. E.g</div>
<div>
<ul style="text-align: left;">
<li>Bob&nbsp;<i>eats</i>&nbsp;<i>food</i></li>
<li>John&nbsp;<i>drives&nbsp;</i>a<i>&nbsp;car</i></li>
<li>He&nbsp;<i>sits&nbsp;</i>on a&nbsp;<i>sofa</i></li>
</ul>
<div>
These types of relations are important to find the probability of a word occurring in a sentence based on another word which is present in the sentence.</div>
</div>
<div>

</div>
<div>
This problem can be mathematically reduced to&nbsp;<i>Predicting a random variable v, where v=1 if the word is&nbsp;present in the sentence or v-0 if the word is not present in the sentence.</i></div>
<div>
The more random this variable is,&nbsp;the more difficult it is to predict the variable. For e.g probability of occurring&nbsp;<i>the&nbsp;</i>in a sentence when some other word has occurred in the sentence can be easily predicted as "<i>the"&nbsp;</i>is a pretty common word, on the other hand, probability of occurring of word "eat" in a sentence is low and it's difficult to predict the probability of its occurrence.</div>
<div>

</div>
<div>
The randomness of a&nbsp;random variable can be measured by&nbsp;<b>Entropy.</b></div>
<div>
<b>
</b></div>
<div>
<b>H(Xw)=âˆ‘-P(Xw=V)logP(Xw=V)</b>
<b>(vÎµ{0,1})</b>
<b>
</b> X sub w is the probability that the word w is present in the sentence
H(Xw) is the entropy of the variable X sub w
P(Xw=V) is the probability that&nbsp;the variable exists(V=1) and vice-versa(V=0)
logP(Xw=V) is the natural log of the probability that a variable exists(V=1) and vice-versa (V=0)
<b>
</b> "Higher the entropy more difficult it is to predict the syntagmatic relation"

Now that we know the concept of entropy and how it can be used to predict the existence of a word in a sentence, let's introduce one more concept called&nbsp;<b>Conditional Entropy.</b>
It is defined as the entropy of a word W when it is known that V has occurred in the sentence.
This helps to reduce the entropy which in turn reduces the randomness of the random variable.
Conditional Entropy can be defined as

<b>H(Xmeat|Xeats =1)=-P(</b><b>Xmeat=0 | Xeats =1</b><b>)logP(</b><b>Xmeat=0 | Xeats =1</b><b>)&nbsp;</b>
<b>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; - P(</b><b>Xmeat=1 | Xeats =1</b><b>)logP(</b><b>Xmeat=1 | Xeats =1)</b>
<b>
</b> This defines the probability of meat occurring when eats has already occurred. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
<h3>
Paradigmatic Relations</h3>
</div>
<div>
The other type of relationship that can be found between the words is the paradigmatic relation.Two words are said to be paradigmatically related if they can be replaced with each other and still make a valid sentence.E.g</div>
<div>
<ul>
<li>I love cats</li>
<li>I love dogs</li>
</ul>
<div>
In the first&nbsp;sentence&nbsp;if&nbsp; "cats"&nbsp;is replaced with dogs it still makes a valid sentence, that means cats and dogs are paradigmatically related.</div>
</div>
<div>

</div>
<div>
In order to find these type of relationships in the sentences we first need to find the&nbsp;<b>Left Context,&nbsp;</b>which means the words that appear left to the words and then we need to find the&nbsp;<b>Right Context,&nbsp;</b>which means the words that appear to the right of the sentences.</div>
<div>
Once we have these context we can find the context similarities.Words with more context similarities are more paradigmatically related.This problem can be mathematically defined by representing each word in the context as a vector, where the value of vector is represented by the frequency of the occurrences&nbsp;of that word in the context</div>
<div>

</div>
<div>
Now the two contexts can be represented as&nbsp;</div>
<div>

</div>
<div>
d1=(x1,x2,x3,x4,........xn)</div>
<div>
d1=c(wi,d1) / |d1|</div>
<div>

</div>
<div>
c(wi,d1) is the count of word wi in d1 and,</div>
<div>
|d1| is the number of words in d1</div>
<div>

</div>
<div>

</div>
<div>
<div>
d2=(x1,x2,x3,x4,........xn)</div>
<div>
d2=c(wi,d2) / |d2|</div>
<div>

</div>
<div>
c(wi,d2) is the count of word&nbsp;wi&nbsp;in d2 and,</div>
<div>
|d2| is the number of words in d2</div>
</div>
<div>

</div>
<div>

</div>
<div>
And context similarity can be calculated as&nbsp;</div>
<div>
Sim(d1,d2)=d1.d2</div>
<div>
Sim(d1,d2)=x1y1+x2y2+x3y3+......................................+xnyn</div>
<div>
Sim(d1,d2)=ðšºxiyi where i=0 to n</div>
<div>

</div>
<div>

</div>
<div>
The similarity is the probability that a randomly picked word from d1 and d2 are identical.</div>
<div>

</div>
<div>

</div>
<div>
Soon will be adding some links for the programmatical model for these relation mining and in the next series will be writing about the Topic Mining.</div>
<div>
Stay Tuned......</div>
</div>