Module 1
Module 1
Processing [NLP]
BAI601
Module-1: Syllabus
• Introduction: What is Natural Language Processing?
• Origins of NLP,
• Language and Knowledge,
• The Challenges of NLP,
• Language and Grammar,
• Processing Indian Languages,
• NLP Applications.
• Language Modeling: Statistical Language Model - N-gram
model (unigram, bigram),
• Paninion Framework,
• Karaka theory.
What is NLP ?
• NLP is concerned with development of computational models
of aspects of human language processing [Siddiqui, Tiwari].
Objectives:
• To develop automated tools for language processing.
• To gain a better understanding of human communication.
Inputs:
• Knowledge of how human acquire, store and process language.
• Knowledge of the world
• Knowledge of the language
Historic approaches to NLP
1. Rationalist – assumes existence of some language faculty
(cognitive capacity shared by all normal human beings) in human
brain.
Spoken Form
• Serves as our primary means of coordinating our day-to-day
behavior with others.
Written Form-Text
• Serves as a long-term record of knowledge from one
generation to the next.
2. Data-driven
• Assume existence of a large amount of data
• Usually employ some Machine Learning techniques to learn syntactic
patterns.
Advantages
• Less human effort
• Performance of such systems depend on quantity of data
• Such systems are adaptive to noisy data
NLP – usage of term – in practice
• Mistakenly termed as Natural Language Understanding
• Understanding only involves interpretation of language
• NLP includes both Understanding (interpretation) and Generation
(production)
• NLP also includes Speech processing
• NLU is considered AI-complete
Consider the following example:
Sentence A: “Get me something I can drink from”. Sentence B: “Get me a cup”.
The two sentences A and B are different but have the same meaning.
The AI system needs to have a more meaningful model of language in order for
it to conclude that: A = B
• For example, the sentence “Do you know what time it is?” should be
interpreted as a request to be told the time.
• One way is to record what was said as fact. (for some sentences
intended effect is declarative and sometimes it is not).
Challenges
• Related to the representation and interpretation like human.
1. Representation of meaning of a sentence, meaning of words
appearing in it.
• Meaning of word and its use in language.
• Example: ‘I like Ice cream’ instead if we use ‘like Ice cream I’
• Indian languages have a free word order, ie., words can be moved freely within a
sentence without changing the meaning of the sentence.
• Indian languages make extensive and productive use of complex predicates (CPs).
• Indian languages use verb complexes consisting of sequences of verbs, e.g., गा रहा
है (ga raha hai - singing) and खेल रही है (khel rahi hai - playing). The auxiliary
verbs in this sequence provide information about tense, aspect, modality, etc.
• Except for the direction in which its
script is written, Urdu is closely
related to Hindi. Both share similar
phonology, morphology, and syntax.
Both are free-word-order languages
and use post-positions.
• They also share a large amount of
their vocabulary. Urdu vocabulary
comes from Persian and Arabic, while
Hindi borrows much of its vocabulary
from Sanskrit.
• Paninian grammar provides a
framework for Indian language
models. These can be used for
computation of Indian languages. The
grammar focuses on extraction of
Karaka relations from a sentence.
NLP APPLICATIONS
• Machine translation - It involves the complete linguistic analysis
of a natural language sentence, and linguistic generation of an
output sentence.
• Speech Recognition
• Speech Synthesis - utterance of natural language sentences
• Natural Language Interfaces to Databases - querying a
structured database using natural language sentences.
• Information Retrieval – use of indexing (stop word elimination,
stemming, phrase extraction, etc.), word sense disambiguation,
query modification, and knowledge bases. Lexical resources are
WordNet, LDOCE (Longman Dictionary of Contemporary
English) and Roget's Thesaurus.
• Information Extraction
• Question Answering
• Text Summarization
LANGUAGE MODELLING
• The domain of language is quite vast.
• To handle such a large number of sentences, we have to create a
model of the domain, which can subsequently be simplified and
handled computationally.
• To create a general model of any language is a difficult task.
• Natural language is a complex entity and in order to process it
through a computer-based program, need to build a model of it.
This is known as language modelling.
• There are 2 approaches for language modelling.
• One is to define a grammar that can handle the language. The
other is to capture the patterns in a grammar language
statistically. [Grammar-based model and Statistical language
model]
• These include lexical functional grammar, government and
binding, Paninian grammar, and gram-based model.
• Study the grammar of various languages, compare them, and if
possible, arrive at reasonable models that facilitate our
understanding of the problem and designing of natural-
language tools.
• A grammar-based language model attempts to distinguish a
grammatical sentence from a non-grammatical one, whereas a
Probabilistic language model attempts to identify a sentence
based on a probability measure, usually a maximum likelihood
estimate.
• The Grammar-based language model, attempts to represent the
syntactic structure of language. Grammar consists of hand-
coded rules defining the structure and ordering of various
constituents (phrase, sentence, etc.).
• The statistical approach creates a language model by training it
from a corpus.
• SLM is one of the fundamental tasks, in many applications like
speech recognition, spelling correction, handwriting recognition,
machine translation, also for in information retrieval, text
summarization, and question answering.
STATISTICAL LANGUAGE MODEL
• A statistical language model is a probability distribution P(s) over all possible word
sequences (or any other linguistic unit like words, sentences, paragraphs,
documents, or spoken utterances).
• N-gram Model
P(s) = P(w1) P(w2/ w1) P(w3 / w1 w2) P(w4 / w1 w2 w3)......... P(wn / w1 w2 ……wn-1 )
P(s) ≈ ς𝑛𝑖=1 P(wi / wi−1) and P(s) ≈ ς𝑛𝑖=1 P(wi / wi−2 .wi−1)
• For example, the bi-gram approximation of P(east / The Arabian knights are
fairy tales of the) is P(east/the), whereas a tri-gram approximation is
P(east/of the).
• A special word (pseudo word) <s> is introduced to mark the beginning of the
sentence in bi-gram estimation. The probability of the first word in a
sentence is conditioned on <s>.
• How to estimate the probabilities. This is done by training the n-gram model
on the training corpus.
C(wi−n+1,……, wi−1,wi)
P(wi / wi-n+1,……, wi-1) = σ
𝑤 C(wi−n+1,……, wi−1,w)
• The sum of all n-grams that share first (n-1) words is equal to the
count of the common prefix [wi-n+1,……, wi-1].
C(wi−n+1,……, wi−1,wi)
P(wi / wi-n+1,……, wi-1) =
C(wi−n+1,……, wi−1)
• The model parameter we get using these estimates, maximizes
the probability of the training set T given the model M, ie., P(T/M).
• The frequency with which a word occurs in a text may not be the
same as in the training set; this model only provides the most
likely solution.
world
I am the king of the ……….
• 1-gram(Unigram)-----(i)(am)(the)(king) …..
• 2-gram(bigram)-----(I am)(am the)(the king)….
• 3-gram(trigram)------(I am the)(am the king)….
Corpus
The girl bought a chocolate
The boy ate the chocolate
Vocabulary
The girl bought a toy
{the, girl, bought, a,
chocolate, boy, ate, The girl played with the toy
toy, played, with}
Input: The girl …?….
Training set:
The Arabian Knights
These are the fairy tales of the east
The stories of the Arabian knights are translated in many languages
• Bi-gram model:
• P(the/<s>) = 0.67 P(Arabian/the)=0.4 P(knights/Arabian) = 1.0
P(the/are) = 0.5 P(fairy/the) = 0.2 P(tales/fairy) =1.0
P(of/tales) = 1.0 P(the/of) = 1.0 P(east/the) = 0.2
P(stories/the) =0.2 P(of/stories) =1.0 P(are/knights) =0.5
P(translated/are) = 0.5 P(in/translated) = 1.0 P(many/in) = 1.0
P(languages/many) = 1.0 P(are/these) = 1.0
• Test sentence(s): The Arabian knights are the fairy tales of the east.
• P(The/<s>) x P(Arabian/the) x P(Knights/Arabian) x P(are/knights) x P(the/are)
x P(fairy/the) x P(tales/fairy) x P(of/tales) x P(the/of) x P(east/the)
= 0.67 x 0.4 x 1.0 x 0.5 x 0.5 x 0.2 x 1.0 x 1.0 x 1.0 x 0.2 = 0.00267
• As each probability is less than 1, multiplying the probabilities
might cause a numerical underflow, particularly in long
sentences.
Layered Representation in PG
• The Government and Binding (GB) theory
represents 3 syntactic levels: deep
structure, surface structure, and logical
form (LF), where the LF is nearer to
semantics.
• This theory tries to resolve all language
issues at syntactic levels only.
• Paninian grammar framework is said to be
syntactico-semantic, that is, one can go
from surface layer to deep semantics by
passing through intermediate layers.
• Vibhakti refers to word (noun, verb, or other) groups
based either on case endings, or post-positions, or
compound verbs, or main and auxiliary verbs, etc.
• Word groups are formed based on various kinds of
markers. These markers are language-specific, but all
Indian languages can be represented at the Vibhakti
level.
• Karaka (pronounced Kaaraka) literally means Case.
Paninian Grammar has its own way of defining Karaka
relations.
• These relations are based on the way the word groups
participate in the activity denoted by the verb group.
• Complexities arise because of the absence of
inflections, multiple categories and meanings of the
words, and the presence of a large number of
exceptions.
• These exceptions are not only applicable on stated
rules but also on future rules. Such forward and
backward chaining makes actual implementation
difficult.
• The resolution of ambiguities is a contentious issue,
often left to the listener.
• Multiple-meaning texts are abundant in Indian
literature as seen in the hundreds of interpretations
of the epics.
Karaka Theory
• Karaka theory is the central theme of PG framework.
• Karaka relations are assigned based on the roles, which
are reflected in the case markers and post-position
markers (parsargs).
• These relations are similar to case relations in English,
but the types of relations are defined in a different
manner and the richness of the case endings found in
Indian languages has been used to its advantage.
• The various Karakas, such as Karta (subject), Karma
(object), Karana (instrument), Sampradana
(beneficiary), Apadan (separation), and Adhikaran
(locus).
मााँ बच्ची को आाँगन में हाथ से रोटी खखलाती है ।
Maan bachchi ko aangan mein haath se rotii khilaatii hei
Mother child-to courtyard-in hand-by bread feed (s).
The mother feeds bread to the child by hand in the courtyard.
• Karta is defined as the noun group which is most independent.
Karta has generally 'ne' or 'φ' case marker. It is an independent
entity in the activity denoted by the main verb.
• In above example, 'maan' (mother) is the Karta. The concept of
Karta is different from the 'agent' concept in the sense that Karta
can also take up the role of experience, e.g..
मझ
ु से रहा न गया। Mujhse rahaa na gayaa
Me hold not passive
I could not hold myself.
मााँ बच्ची को आाँगन में हाथ से रोटी खखलाती है ।
Maan bachchi ko aangan mein haath se rotii khilaatii
hei
• maan (mother) is the Karta
• rotii (bread) is the Karma
• haath (hand) is the Karan
• bachchi (child) is the Sampradan
• aangan (courtyard) is the Adhikaran
• ‘Karma' is similar to object and is the locus of the
result of the activity.
• rotii (bread) is the Karma.
• when the Karta is the experiencer, it (she) is also
the locus of the result.
• Thus, the locus of the result is only when it is
different from Karta termed Karma.
• Karma generally has 'φ' or 'KO' case marker.
• 'Karan' (instrument), which is a noun group
through which the goal is achieved.
• haath (hand) is the Karan. It has the marker
dwara (by) or se.
• 'Sampradan' is the beneficiary of the activity, e.g., bachchi
(child). It takes the marker ko (to) or ke liye (for).
• 'Apaadaan' denotes separation and the marker is attached to
the part that serves as a reference point (being stationary),
मााँ ने थाली से खाना उठाकर बच्चे को ददया । Maan ne thaali se
khana uthakar bachche ko diyaa.
Mother plate from food taking up child-to gave.
The mother gave food to the child taking it up from the plate.
• Here thaali is the Apaadan.
• 'Adhikaran' is the locus (support in space or time) of Karta or
Karma. aangan (courtyard) is the Adhikaran.
• As these six relations are not sufficient to capture all possible
relations, various others such as 'Sambandh' (relation) and
"Tadarthya' (purpose) have also been tried.
Issues in Paninian Grammar
The two problems challenging linguists are:
(i) Computational implementation of PG, and
(ii) Adaptation of PG to Indian, and other similar languages.
• In Bharati, et al. (1995) research work they spoke the PG is a multilayered
implementation. The approach is named 'Utsarga-Apvada' (default-
exception), where rules are arranged in multiple layers in such a way that
each layer consists of rules which are in exception to rules in the higher layer.
As we go down the layer, more particular information is derived. Rules may
be represented in the form of charts.
• Another difficulty arises when mapping between the Vibhakti and the
semantic relation is not one to one.
• Two different Vibhakti can represent the same relation, or the same Vibhakti
can represent different relations in different contexts. The strategy to
disambiguate the various senses of words, or word groupings, are still the
challenging issues.
• As the system of rules is different in different languages, the framework
requires adaptations to tackle various applications in various languages.
Questions?
1. What is NLP? How it has been originated and what are the challenges of NLP?
2. What is NLP? List and explain different levels of processing involved in it.
3. Explain semantic and syntactic levels of text analysis.
4. Explain the challenges of NLP.
5. Explain in detail about Transformational grammar.
6. List and explain in detail applications of NLP.
7. Describe how to process Indian Languages.
8. List the key differences between Processing Indian Languages against English language.
9. Differentiate between grammar based model and statistical based model.
10. Explain n-gram modelling of natural languages. Find the probability of the test sentence
S4 in the following training set
S1: The Arabian knights
S2: These are the fairy tales of the east
S3: The stories of the Arabian Knights are translated in many languages
S4: The Arabian Knights are the fairy tales of the east
11. Determine the probability for training set corpus, predict the test case sentences
probability and choose the highest probability sentence among two by the use of
bigram model.
Training Set:
<s> I am Chintu
<s> I like College
<s> Do Chintu like College
<s> Chintu I am
<s> Do I like Chintu
<s> Do I like College
<s> I do like Chintu
Testing Set:
I like College
Do I like Chintu
12. Determine the probability of words and sentence using add one smoothing.
Training Set:
I love India
India is my country
I feel proud
Testing Set:
I love India and feel proud
my country
13. What are the different approaches for language modeling? Explain.
14. What is statistical language model and explain features of n-gram model?
15. What is data sparseness problem in n-gram model? Explain.
16. Briefly explain the problems associated with n-gram model and the techniques to
resolve problems.
17. Using Bi-gram model, find the probability of the sentence “They play in a garden” for
the following training set data;
There is a big garden
Children play in the garden
They play inside beautiful garden
18. Consider the Training set below:
The girl cat
The boy and the cat
The cat and the girl
The girl and the cat
Girl and the boy
i. Estimate the probability of the sentence “The boy and the girl cat” using a model that limits
the history to the previous one word only.
ii. Estimate the probability of the sentence “The boy and the girl cat” using a model that limits
the history to the previous two words.