Semantic Analysis
What is Semantic Analysis ?
Semantic Analysis is a process to get meaning from text. It can be helpful to analyze paragraphs, sentences, and text documents. This helps to understand the grammatical structure and relationship between the individual words in the text and their context.
for example, He is in a terrible state
In the above sentence, there is an existence of Semantic Ambiguity here state refers to any mental state (mood of the person) or any geographical region.
This can be useful in the areas of marketing, and customer services, to understand customer sentiment and identify trends and improve communication. Every time semantic analysis is NOT always seen as 100% accurate because it depends on languages to languages and their complexities.
Semantic analysis is different from Lexical analysis because it focuses on a large corpus. Therefore we can divide the semantic analysis into two parts.
- Analysis of the relationship between the individuals’ words ::::: This is a lexical based analysis that focuses on the meaning and relationship between the individual words
For example: “ I am happy today.” I — the subject, am — verb, happy — adjective.
- Analysis of relationship between the combination of words:::: This is an example of semantic analysis which looks for the relations between the combinations of individual words.
For example He lost his bicycle.
Get Dayana Vincent’s stories in your inbox
Join Medium for free to get updates from this writer.
By analyzing the combination of words “lost his bicycle” a semantic analysis could recognize that this implies that the person had ownership of the bicycle and has now lost it, rather than just analyzing the individual words “lost,” “his,” and “bicycle” in isolation.
Thus this helps to understand the context better than lexical analysis (focuses on individual words).
Way to get meaning from the corpus !!!!!
Sometimes one words can have different meaning.
This can be handled using
- Word Sense Disambiguation
- Relationship Extraction
Word Sense Disambiguation using NLTK
import nltk
nltk.download('punkt')
nltk.download('wordnet')
from nltk.wsd import lesk
from nltk.tokenize import word_tokenize
a1= lesk(word_tokenize('I went to the bank to deposit my money.'),'bank')
print(a1,a1.definition())Relationship Extraction
import spacy
from spacy.matcher import Matcher
from spacy import displacy
import visualise_spacy_tree
from IPython.display import Image, display
nlp = spacy.load('en_core_web_sm',disable=['ner','textcat'])
doc = nlp('Atiq Ahmed, who was under police escort, was talking to reporters when a gun was pulled close to his head in Prayagraj, also known as Allahabad. ')
png = visualise_spacy_tree.create_png(doc)
display(Image(png))








