Natural Language Processing in AI: Core Concepts, a Worked Bigram Example, and How Exams Test It

Build NLP from tokens to transformers, then reproduce the TF-IDF and bigram calculations that exam and placement questions expect.

KnowledgeGate Team

Exam prep & CS education

Updated 7 Aug 20266 min read

Natural Language Processing appears in UGC NET preparation, GATE DA discussions, and AI or ML placement interviews, yet many students know it only as “something with chatbots”. Underneath, it is counting and conditional probability: on a three-sentence corpus, the sentence “students love gate” carries a bigram probability of exactly 4/9.

What NLP is and where it sits in AI

Natural Language Processing, or NLP, lets machines process and generate human language. Natural Language Understanding, or NLU, extracts meaning from input. Natural Language Generation, or NLG, produces language as output.

The sentence “Students love GATE” shows four classical levels of analysis:

Level

Question answered

Example

Lexical

What are the units?

Split the sentence into “Students”, “love”, and “GATE”

Syntactic

How are the units arranged?

Students is the subject, love is the verb, and GATE is the object

Semantic

What does it mean?

Students are the people who love GATE

Pragmatic

Why was it said here?

The speaker may be describing motivation or making a claim about a class

NLP sits alongside search, knowledge representation, reasoning, and machine learning, and it borrows from each of them: probability for language models, grammars for parsing, and classification for tasks such as sentiment. UGC NET Computer Science places it in the AI unit of Paper 2, while GATE spreads the same machinery across its DA and CS syllabi.

From raw text to useful features

A classical preprocessing pipeline follows this order:

  1. Tokenisation splits text into words or subwords.

  2. Normalisation makes forms consistent, often through lowercasing.

  3. Stop-word removal drops frequent function words when they add little value.

  4. Stemming or lemmatisation reduces related forms.

Stemming applies mechanical rules. A Porter-style stemmer may reduce “studies” to the non-word “studi”. Lemmatisation uses vocabulary and part-of-speech information to map it to “study”. Stemming suits quick retrieval or rough feature reduction. Lemmatisation is better when valid words matter.

Part-of-speech tagging labels “Students love GATE” as NOUN, VERB, PROPN. Named Entity Recognition may label “GATE” as an EXAM or ORG-type entity, depending on the tag set.

Models need numbers, so representations include one-hot vectors, bag-of-words counts, TF-IDF weights, and dense embeddings. Suppose “parser” occurs 4 times in a 100-word document and in 10 of 1,000 documents:

  • tf = 4/100 = 0.04

  • idf = log10(1000/10) = log10(100) = 2

  • tf-idf = 0.04 × 2 = 0.08

The term gets weight because it is relatively rare across the collection. TF-IDF does not capture word order or meaning.

NLP pipeline turning the sentence 'Students love GATE' into tokens, POS tags, and a TF-IDF feature vector for a model.

Worked bigram language model

Use this toy corpus with sentence markers:

  1. <s> students love gate </s>

  2. <s> students love ai </s>

  3. <s> teachers love gate </s>

The unigram counts are: students = 2, love = 3, gate = 2, ai = 1, teachers = 1, <s> = 3, and </s> = 3.

The bigram counts are: <s> students = 2, <s> teachers = 1, students love = 2, teachers love = 1, love gate = 2, love ai = 1, gate </s> = 2, and ai </s> = 1.

Maximum likelihood estimation divides a bigram count by the count of its first word:

  • P(love | students) = 2/2 = 1.0

  • P(gate | love) = 2/3 ≈ 0.67

  • P(ai | love) = 1/3 ≈ 0.33

  • P(students | <s>) = 2/3 ≈ 0.67

Now apply the bigram chain rule to the first sentence:

P(<s> students love gate </s>)

= P(students | <s>) × P(love | students) × P(gate | love) × P(</s> | gate)

= (2/3) × 1 × (2/3) × 1

= 4/9 ≈ 0.444

An unseen bigram makes the whole sentence probability zero. “Students love teachers” contains love teachers, whose count is zero. This motivates smoothing.

Bigram transition graph for the toy corpus, with the highlighted path giving the sentence probability 4/9.

Laplace smoothing and zero probability

Add-1, or Laplace, smoothing gives every possible next word one extra count:

P(w2 | w1) = (count(w1 w2) + 1) / (count(w1) + V)

For this model, V = 6 possible output types: students, love, gate, ai, teachers, and </s>. Therefore:

  • P(gate | love) = (2 + 1)/(3 + 6) = 3/9 ≈ 0.33, down from about 0.67.

  • P(teachers | love) = (0 + 1)/(3 + 6) = 1/9 ≈ 0.11, up from 0.

The unseen event is now possible, but add-1 can take too much mass from seen events in a large vocabulary. Add-k uses a smaller value, while backoff and interpolation combine n-gram orders.

Model families examiners expect

In HMM part-of-speech tagging, hidden states are tags and observations are words. Transition and emission probabilities feed the Viterbi algorithm, which finds the most likely tag sequence.

Naive Bayes uses bag-of-words features and conditional independence. In the classic spam versus ham setup, add-1 smoothing stops an unseen word from forcing a class probability to zero.

Natural-language parsing also connects directly to theory of computation. “I saw the man with the telescope” has two possible parse trees because the phrase “with the telescope” can attach in two places. The context-free grammars and pushdown automata guide builds the formal machinery behind that ambiguity.

Embeddings place related words near one another. RNNs read a sequence one position at a time, carrying a hidden state forward. Transformers drop that sequential pass: attention lets every position weigh every other position in a single step, which makes them parallelisable and good at long-range dependencies. Transformers power modern large language models, but a small classical baseline trains in seconds, explains itself, and is often the right first model on a small dataset.

NLP traps that cost marks

  • Treating stemming and lemmatisation as identical. Check whether the result must be a valid dictionary word.

  • Dropping sentence markers. The 4/9 result includes both P(students | <s>) and P(</s> | gate).

  • Using token count as V. This corpus has 9 ordinary word tokens, excluding markers, and 6 output vocabulary types. It has 12 marked bigram tokens because each three-word sentence contributes four bigrams. The denominator takes the 6 vocabulary types, never the 9 word tokens and never the 12 bigram tokens.

  • Claiming TF-IDF captures order. It is a bag-of-words weighting, so order is lost.

  • Equating NLP with deep learning. In interviews, explain the classical pipeline and justify when Naive Bayes is a sensible first model.

How GATE, UGC NET, and interviews test NLP

Recent official GATE brochures have placed probability, Naive Bayes, machine learning, and AI in DA, while classic CS covers neighbouring CFG and probability foundations. NLP-style practice may ask for an n-gram probability, TF-IDF weight, or Naive Bayes step, but NLP is not separately named in every edition. Confirm the scope on the conducting institute’s official GATE test papers and syllabus page.

UGC NET Computer Science Paper 2 explicitly lists Natural Language Processing inside its AI unit, and its questions tend to be definitional or a short n-gram or TF-IDF computation. Marks, question counts and the negative-marking rule are only what the current notification at ugcnet.nta.nic.in states, and the official Computer Science syllabus on that portal carries the exact topic wording. Slot NLP into a revision order with UGC NET Computer Science high-yield topics.

Three NLP questions recur in placement interviews. “Design a sentiment classifier for product reviews”: name the pipeline (tokenise, lowercase, drop stop words, TF-IDF, then Naive Bayes or logistic regression), and report precision and recall rather than accuracy, since review data skews positive. “Why do we smooth?”: give the zero, P(teachers | love) = 0 kills the whole sentence probability, then the fix, add-1 lifts it to 1/9. “Bag-of-words or embeddings?”: bag-of-words is sparse, interpretable word by word, and fine on a small labelled set, while embeddings capture that “good” and “great” are near neighbours, which pays off only once you have enough data to exploit it. Carry one small calculation into every answer.

The short version and next step

  • NLP moves from lexical and syntactic analysis to semantics and pragmatics.

  • Stemming can produce “studi”, while lemmatisation produces the valid lemma “study”.

  • The TF-IDF example gives 0.04 × 2 = 0.08.

  • The marked bigram sentence probability is 4/9 ≈ 0.444.

  • Laplace smoothing uses V as the number of vocabulary types, not tokens.

  • UGC NET names NLP directly, while GATE candidates should confirm the current DA and CS syllabus boundaries.

For AI and ML placement preparation, continue with AI for Placement. UGC NET aspirants can follow the broader Paper 2 sequence in NTA UGC NET Paper 2. To keep building the surrounding CS foundation, use the GATE CS subject weightage guide.