Unit 5
Unit 5
NP → "The cat"
VP → "sat on the mat"
PP → "on the mat"
✅ Use-case: Grammar checking, sentence generation.
✅ Components:
Non-terminals (A, B, S, NP, VP, etc.)
Terminals (actual words like “the”, “boy”)
Production rules (A → B C)
Start symbol (usually S)
S → NP VP
NP → Det N
VP → V NP
Det → 'the'
N → 'boy' | 'dog'
V → 'saw'
🔹 Explanation:
S → NP VP: A sentence (S) consists of a noun phrase followed by a verb phrase.
NP → Det N: A noun phrase is made up of a determiner and a noun.
VP → V NP: A verb phrase consists of a verb followed by a noun phrase.
Det → 'the': 'the' is a determiner.
N → 'boy' | 'dog': Both 'boy' and 'dog' are nouns.
V → 'saw': 'saw' is a verb.
🧠 Applying the Rules Step-by-Step
Let’s parse: “The boy saw the dog”
Step 1: Start with S (sentence)
→ S → NP VP
Step 2: Expand NP
→ NP → Det N
→ Det = 'the'
→ N = 'boy'
✅ First NP = “the boy”
Step 3: Expand VP
→ VP → V NP
→ V = 'saw'
→ NP → Det N
→ Det = 'the', N = 'dog'
✅ Second NP = “the dog”
Final Structure:
S
/ \
NP VP
/ \ / \
Det N V NP
| | | / \
the boy saw Det N
| |
the dog
🔹 Key Concepts:
Term Meaning
Head The central word in a phrase (usually a verb or noun)
Dependent A word that adds meaning to the head (like subject, object, modifier)
Arc A directed connection from head to dependent
Root The main verb of the sentence (it has no parent)
Dependency parsing builds a tree structure, with one root and connections (arcs) to all
other words.
chased (ROOT)
├── cat (nsubj)
│ └── The (det)
└── mouse (dobj)
└── the (det)
# Input sentence
doc = nlp("The cat chased the mouse.")
✅ Output:
✅ Example:
For word “cats”:
🔷 5. Unification in NLP
Unification is the process of merging two feature structures. It’s successful only when their values
are compatible (i.e., no contradiction).
✅ Why Unification?
Ensures subject-verb agreement
Allows modular representation of grammar rules
Enables robust parsing and semantic analysis
✅ Example:
NP: [Number: singular]
VP: [Number: singular]
→ ✅ Unification succeeds
But:
NP: [Number: plural], VP: [Number: singular]
→ ❌ Unification fails (incompatible)
🔹 6.2 Coordination
Joining similar grammatical units using conjunctions.
"John and Mary", "Fast but safe"
🔹 6.3 Subcategorization
Specifies what kind of arguments a verb can take.
Helps distinguish between verbs like:
"give" (needs subject, object, indirect object)
"sleep" (only needs subject)
"She gave him a book."
Subcat Frame: [Verb → NP NP]
🔹 Expressiveness
The degree to which a language or grammar can represent meaning.
More expressive grammars can handle complex language and semantics.
✅ Example:
Sentence: "All humans are mortal."
FOPC: ∀x (Human(x) → Mortal(x))
🔷 9. Semantic Analysis: Syntax-Driven Integration
Semantic analysis is the process of converting a sentence into a structured meaning representation.
🔹 Integration
Combining syntax, semantics, and features into one analysis.
Essential for applications like dialogue systems and machine reasoning.
🔹 Robustness
The parser should handle errors, informal text, or missing grammar.
Important for real-world applications (e.g., chatbots, web search).
import stanza
stanza.download('en')
nlp = stanza.Pipeline(lang='en', processors='tokenize,pos,lemma,depparse')
doc = nlp("The dog chased the cat.")
for sent in doc.sentences:
sent.print_dependencies()
import spacy
nlp = spacy.load("en_core_web_sm")
doc = nlp("The boy saw a dog with a telescope.")
for token in doc:
print(f"{token.text} --> {token.dep_} --> {token.head.text}")
📘 Summary Table
Topic Description
Parsing Analyze sentence structure using grammar
Constituency Parsing Phrase-based structure (NP, VP)
Dependency Parsing Word-to-word grammar relationships
CFG Rule-based grammar system
Feature Structures Attribute-value pairs (e.g., tense, number)
Unification Matching feature structures
Canonical Form Standard sentence format
FOPC Logic representation of meaning
Semantic Analysis Extracting sentence meaning
Attachment & Robustness Error handling & ambiguity resolution