NLP Unit 4,5
NLP Unit 4,5
1. Basic De nitions
• Predicate: Determines the number and type of arguments it can take. For example,
the verb "give" typically requires three arguments: a subject, a direct object, and an
indirect object (e.g., "She gave him a book").
• Arguments: The elements that ll the roles required by the predicate. Each argument
typically corresponds to a speci c syntactic and semantic role:
◦ Subject: The doer of the action or the one in a state (e.g., "She" in "She reads
a book").
◦ Direct Object: The entity directly affected by the action (e.g., "a book" in
"She reads a book").
◦ Indirect Object: The entity that bene ts from or is affected by the action (e.g.,
"him" in "She gave him a book").
◦ Complement: An argument that provides additional information about the
subject or object (e.g., "a teacher" in "She is a teacher").
3. Syntactic Structure
• Valency: This refers to the number of arguments a predicate can have. For instance,
intransitive verbs like "sleep" have one argument (e.g., "He sleeps"), while transitive
verbs like "read" require two (e.g., "She reads a book").
1
fi
fi
fi
fi
◦ Intransitive Verbs: "John sleeps."
◦ Transitive Verbs: "John reads a book."
◦ Ditransitive Verbs: "John gives Mary a book."
4. Semantic Roles
Arguments often ful ll speci c semantic roles related to the predicate's action:
• Agent: The entity performing the action (e.g., "John" in "John kicks the ball").
• Theme: The entity undergoing the action or affected by it (e.g., "the ball" in "John
kicks the ball").
• Goal/Recipient: The entity that receives or bene ts from the action (e.g., "Mary" in
"John gives Mary a book").
• Experiencer: The entity experiencing a state or emotion (e.g., "John" in "John enjoys
the book").
5. In Computational Linguistics
In natural language processing (NLP), understanding PAS is crucial for tasks such as:
• Semantic Role Labeling: Identifying roles like agent, theme, etc., in sentences.
• Syntactic Parsing: Analyzing sentence structure to understand how arguments relate
to predicates.
• Information Extraction: Extracting structured information from unstructured text,
such as identifying who did what to whom.
6. Example Analysis
Consider the sentence: "The chef cooked a delicious meal for the guests."
• Predicate: "cooked"
• Arguments:
◦ Subject (Agent): "The chef"
◦ Direct Object (Theme): "a delicious meal"
◦ Indirect Object (Recipient): "for the guests"
The Predicate Argument Structure helps in understanding how the action of cooking is related
to the entities involved in the sentence.
Semantics : Semantics is the study of meaning in language at the level of words, phrases, and
sentences. It deals with how individual words and their combinations convey meaning.
Pragmatics : Pragmatics is the study of how context in uences the interpretation of meaning
in communication. It examines how speakers use language in different contexts to convey
meaning beyond the literal interpretation.
2
fi
fi
fi
fi
fl
Discourse Analysis : Discourse analysis studies how larger units of language, such as
conversations, written texts, or speeches, are structured and how they convey meaning across
different contexts.
• Understanding Context: Helps machines grasp the intent and context of a text.
• Facilitating Reasoning: Allows machines to make logical conclusions based on the
text.
• Supporting Complex Queries: Enables machines to handle sophisticated questions
and search queries.
• Improving Communication: Enhances how machines interact with humans by
understanding their language better.
2. Types of Meaning Representation
3
a. Semantic Networks
• De nition: Graphs where nodes are concepts (like "John" or "book") and edges are
relationships between them (like "gave").
• Example: For "John gave Mary a book," nodes would be "John," "Mary," and "book,"
connected by "gave."
b. Frame Semantics
• De nition: Uses structured scenarios (frames) to represent meaning. Each frame has
roles lled by entities.
• Example: For "John gave Mary a book," the frame includes roles like Giver (John),
Receiver (Mary), and Item (book).
c. First-Order Logic
• De nition: Uses formal logic to represent knowledge with quanti ers and predicates.
• Example: "All humans are mortal" is represented as ∀x (Human(x) → Mortal(x)).
d. Abstract Syntax Trees (ASTs)
a. Rule-Based Systems
• Description: Use advanced models like transformers (e.g., BERT, GPT) to understand
text.
• Pros: Captures complex language patterns and performs well on many NLP tasks.
• Cons: Computationally expensive and sometimes hard to interpret.
4. Applications
4
fi
fi
fi
fi
fi
fi
fl
fi
fi
fi
• Information Extraction: Pulling out important information from text.
• Question Answering: Answering user questions based on the meaning of text.
• Machine Translation: Translating text from one language to another by
understanding its meaning.
• Text Summarization: Creating brief summaries by understanding the main points.
5. Challenges
• Semantic Network: Nodes for "Alice," "Bob," and "book," connected by "gave" with
roles for each entity.
• Frame Semantics: Frame for "giving" with roles for Alice (Giver), Bob (Receiver),
and the book (Item).
• First-Order Logic: Representation could be Gave(Alice, Bob, book).
• Abstract Syntax Tree: Tree showing "Alice" as the subject, "gave" as the action, and
"Bob" and "book" as object and indirect object.
• Semantic Parsing: Might convert to a query to nd information about the book.
Meaning Representation Systems using First-Order Logic (FOL) help convert human
language into a structured format that computers can understand and work with.
5
fi
fi
fi
fi
fi
fi
2. FOL Represent Meaning
• Simple Sentences:
6
fi
fi
Q.Explain the significance of using propbank in NLP,
PropBank is a resource that provides detailed information about verbs in a text. It includes:
• Rolesets: Descriptions of the different roles (like the person doing something or
receiving something) that can be associated with a verb.
• Argument Structures: Information about how different parts of a sentence relate to
each other around a verb.
Signi cance of PropBank
1. Understanding Sentence Meaning (Semantic Role Labeling):
◦ What It Does: Helps computers gure out what different words in a sentence
are doing (e.g., who is doing what to whom).
◦ Example: In "She gave him a book," it helps identify "She" as the giver,
"him" as the receiver, and "a book" as the item given.
2. Improving Sentence Parsing:
◦ What It Does: Helps in pulling out speci c details from a text, like nding out
who did what.
◦ Example: Identifying that "John bought a car from Mary" involves John as the
buyer and Mary as the seller.
4. Translating Text:
◦ What It Does: Helps in determining how similar two pieces of text are by
comparing their meaning.
◦ Example: Comparing "She gave him a gift" with "She presented him with a
present."
7
fi
fi
fi
fi
fi
fi
Example
For the sentence: "The company sold the product to the customer":
• Verb: "sold"
• Roles:
◦ Seller: The company
◦ Buyer: The customer
◦ Product: The product
PropBank helps in understanding who is selling, who is buying, and what is being sold.
UNIT 5
1. Cohesion
Cohesion refers to the way in which different parts of a text or conversation are connected
together to create a uni ed whole. It involves various linguistic devices that help tie sentences
and phrases together, making the text coherent and easier to understand.
Key Aspects:
• Conjunctions: Words that link clauses or sentences (e.g., "and," "but," "because").
◦ Example: "The company will improve its services. The company aims to be
the best."
• Ellipsis: Omitting parts of a sentence that are understood from the context.
◦ Example: "She can speak Spanish, and I can [speak Spanish] too."
• Lexical Ties: Using synonyms or related words to link parts of the text.
◦ Example: "The car was fast. The vehicle could reach high speeds."
2. Reference Resolution
Reference Resolution is the process of identifying which entities in a text (such as names,
pronouns, or noun phrases) refer to the same real-world object or concept. It helps in
understanding what or whom the text is talking about when multiple references are made.
Key Aspects:
8
fi
• Anaphora: When a word (typically a pronoun) refers back to something mentioned
earlier.
◦ Example: "Lisa lost her keys. She found them in the car." ("She" and "them"
refer to Lisa and her keys, respectively.)
• Cataphora: When a word refers forward to something mentioned later in the text.
◦ Example: "He was the best player on the team. John always scored the most
points." ("He" refers to John.)
• Coreference: The relationship between different expressions that refer to the same
entity.
◦ Example: "The dog barked. It was very loud." ("It" refers to "the dog.")
3. Discourse Markers
Discourse Markers are words or phrases used to manage the ow of conversation or text.
They help structure the discourse, indicate relationships between ideas, and guide the listener
or reader through the text.
Key Aspects:
Reference resolution is a critical task in Natural Language Processing (NLP) that involves
identifying which entities in a text (such as names, pronouns, or noun phrases) refer to the
same real-world object or concept.
9
fi
fi
fl
Algorithm for Reference Resolution
Objective: Determine what each pronoun (like "he," "she," "it") refers to in a text.
1. Input:
• Look for names or entities in the text that the pronouns could be referring to.
◦ In the example: The only names mentioned are "Lisa" and "her friend."
5. Match Pronouns to Antecedents:
• Use the context to match each pronoun with the correct entity from step 4.
◦ For "her" in "Lisa called her friend": It refers to "Lisa" (Lisa called
someone, so "her" is Lisa).
◦ For "She" in "She said": It refers to "Lisa" (Lisa is the one talking).
◦ For "she" in "she would meet her": It refers to "Lisa" (Lisa is meeting
someone).
◦ For "her" in "meet her": It refers to "her friend" (Lisa is meeting the friend).
6. Replace Pronouns with Names:
• Substitute the pronouns with the names they refer to for clarity.
◦ Resolved Text: "Lisa called her (Lisa) friend. She (Lisa) said she (Lisa) would
meet her (friend) at the café."
7. Output:
10
Q.Explain the different types of Language Modeling .
Mention its application
Language modeling is a crucial task in Natural Language Processing (NLP) that involves
predicting the likelihood of a sequence of words. Various techniques are used to build and
improve language models.
Types:
• Unigram Model: Predicts the probability of a word based on its occurrence alone,
ignoring context.
• Bigram Model: Predicts a word based on the immediately preceding word.
• Trigram Model: Predicts a word based on the two preceding words.
Applications:
• Spell Checking and Correction: Suggests corrections for misspelled words using
common sequences.
• Text Generation: Completes sentences or generates text based on learned sequences
of words.
• Speech Recognition: Improves accuracy by predicting the next word in a spoken
sequence.
2. Neural Network-Based Models
Types:
• Feedforward Neural Networks: Use a xed-size context to predict the next word in
a sequence.
• Recurrent Neural Networks (RNNs): Use previous words in a sequence to predict
the next word, capturing sequential dependencies.
• Long Short-Term Memory (LSTM) Networks: A type of RNN designed to handle
long-term dependencies and avoid vanishing gradients.
Applications:
11
fi
fi
fi
fi
3. Transformer-Based Models
Types:
Types:
• Content Generation: Creates human-like text for articles, blogs, and marketing.
• Chatbots and Virtual Assistants: Powers conversational agents for interactive user
engagement.
• Information Retrieval: Enhances search engine results by better understanding user
queries.
• Summarization and Extraction: Extracts key information and summarizes large
texts or documents.
An N-Gram Model is a probabilistic language model that predicts the next word in a
sequence based on the preceding n−1 words. It is called "N-Gram" because it uses sequences
of n words to make predictions. The value of n determines the type of N-Gram model:
• Unigram (1-Gram) Model: Uses single words (i.e., individual words are considered
in isolation).
12
fi
fi
fi
fi
• Bigram (2-Gram) Model: Uses pairs of words (i.e., the probability of a word given
the previous word).
• Trigram (3-Gram) Model: Uses triples of words (i.e., the probability of a word
given the two preceding words).
• Higher-Order N-Grams: Use more preceding words to predict the next word.
2. Working
1. Collect N-grams:
◦ Break the text into sequences of N items.
◦ For example, from "The cat sat," the bigrams are "The cat" and "cat sat."
2. Count Frequencies:
1. Tokenization:
◦ Bigrams: ("The", "cat"), ("cat", "sat"), ("sat", "on"), ("on", "the"), ("the",
"mat")
3. Frequency Counting:
◦ Count("The", "cat") = 1
◦ Count("cat", "sat") = 1
◦ Count("sat", "on") = 1
◦ Count("on", "the") = 1
◦ Count("the", "mat") = 1
◦ Count("The") = 1
◦ Count("cat") = 1
◦ Count("sat") = 1
◦ Count("on") = 1
◦ Count("the") = 2
◦ Count("mat") = 1
13
4. Applications of N-gram Models
• Text Prediction: Predicting the next word in a sentence based on the previous words.
• Speech Recognition: Improving accuracy by predicting possible sequences of words
or phonemes.
• Text Generation: Creating coherent text by generating sequences of words that
follow learned patterns.
• Machine Translation: Translating text by predicting sequences of words in the target
language.
5. Limitations of N-gram Models
14
1. Maximum Likelihood Estimation (MLE)
• MLE is used to estimate how likely different words or sequences are based on how
often they appear in the training data.
Working:
◦ Example: If "the cat sat" appears 5 times and "the cat" appears 10 times,
P(sat ∣ th e, cat) = 5/10 = 0.5
Applications:
• Helps generate text or predict the next word based on learned frequencies.
2. Smoothing Techniques
What It Is:
◦ How It Works: Adds a small number to all counts to avoid zero probabilities.
◦ Example: If a bigram "new cat" hasn’t been seen, it still gets a small
probability.
• Good-Turing Smoothing:
15
• Ensures that the model handles unseen data more effectively and avoids zero
probabilities.
3. Bayesian Estimation
What It Is:
• Example: If you know that certain words are usually followed by speci c other
words, you adjust the probabilities accordingly.
Applications:
What It Is:
• This method uses constraints and features to estimate probabilities in a way that
maximizes uncertainty within those constraints.
How It Works:
• Useful for complex tasks like text classi cation and part-of-speech tagging.
Multilingual and crosslingual language modeling are approaches in NLP aimed at handling
multiple languages with a single model or system. These techniques are increasingly
important for applications that need to operate across different languages, such as translation,
information retrieval, and sentiment analysis.
Working:
16
fi
fi
fi
• Shared Representations: The model learns shared representations for different
languages. This means that the same underlying model parameters are used for
multiple languages, leveraging similarities between them.
• Training Data: Uses a combined dataset from all target languages. For example, a
multilingual model might be trained on English, Spanish, Chinese, and Arabic texts.
• Tokenization: Different languages might use different tokenization methods.
Multilingual models often use subword tokenization (e.g., Byte Pair Encoding, BPE)
to handle various languages ef ciently.
Examples:
Working:
17
fi
fi
fi
fi
fi
fi
• Cross-lingual Information Retrieval: Finding relevant information across different
languages.
• Zero-shot Learning: Applying a model trained in one language to tasks in other
languages without additional training.
• Multilingual Search Engines: Providing search results in multiple languages based
on user queries in different languages.
De nition:
Multilingual Language Modeling trains a single model to handle multiple languages by
learning shared representations from diverse linguistic data. This approach simpli es model
management and enhances performance across various languages.
• Problem: Different languages have unique structures, words, and grammar rules.
• Challenge: Adapting models to handle these differences, like different ways of
structuring sentences.
2. Limited Data
• Problem: Not all languages have lots of data available for training.
• Challenge: High-resource languages (like English) have plenty of data, but low-
resource languages (like some Indigenous languages) have very little.
3. Transfer Between Languages
• Problem: Models trained on one language might not work well for others.
• Challenge: Aligning features and adapting models to new languages without enough
data.
4. Cultural Context
• Problem: Measuring how well a model performs in different languages can be tricky.
• Challenge: Developing fair benchmarks and metrics for each language.
7. Bias and Fairness
18
fi
fi
• Challenge: Making sure the model treats all languages and cultures fairly and does
not reinforce existing biases.
8. Mixed-Language Inputs
Key Metrics:
1. Perplexity: Measures how well the model predicts a sample; lower perplexity
indicates better performance.
2. Accuracy: Evaluates how often the model's predictions match the correct answers,
especially in tasks like classi cation or sequence labeling.
3. BLEU Score: Used in translation tasks to compare generated text against reference
translations by measuring n-gram overlaps.
4. ROUGE Score: Measures the overlap between the generated text and reference text,
commonly used in summarization tasks.
5. F1 Score: Combines precision and recall to evaluate the model's performance on
tasks like named entity recognition.
Evaluation Methods:
• Held-Out Test Set: Evaluating the model on a separate dataset not seen during
training.
• Cross-Validation: Splitting data into training and test sets multiple times to ensure
robust performance assessment.
• Human Evaluation: Involves human judges to assess the quality of generated text or
model predictions.
Language Adaptation
Language Adaptation refers to the process of modifying a language model to perform well
in a speci c language, domain, or context, especially when the model is initially trained on
general or different data.
Techniques:
19
fi
fi
1.
Fine-Tuning: Adjusting a pre-trained model on a speci c dataset related to the target
language or domain to improve performance.
2. Transfer Learning: Leveraging knowledge from a pre-trained model on a related
task or language to enhance performance in a new language or domain.
3. Domain Adaptation: Training the model on domain-speci c texts (e.g., medical,
legal) to better handle jargon and specialized vocabulary.
4. Multilingual Training: Using a combined dataset from multiple languages to adapt
the model to work effectively across those languages.
Applications:
20
fi
fi
fi
fi