Unit V Natural Language Processing
Unit V Natural Language Processing
Data Collection: Gathering text data from various sources such as websites, books,
social media, or proprietary databases.
Data Storage: Storing the collected text data in a structured format, such as a database
[Date]
or a collection of documents.
1
AI UNIT V NOTES
2. Text Preprocessing
Preprocessing is crucial to clean and prepare the raw text data for analysis. Common
preprocessing steps include:
Tokenization: Splitting text into smaller units like words or sentences.
Lowercasing: Converting all text to lowercase to ensure uniformity.
Stop word Removal: Removing common words that do not contribute significant
meaning, such as “and,” “the,” “is.”
Punctuation Removal: Removing punctuation marks.
Stemming and Lemmatization: Reducing words to their base or root forms. Stemming
cuts off suffixes, while lemmatization considers the context and converts words to
their meaningful base form.
Text Normalization: Standardizing text format, including correcting spelling errors,
expanding contractions, and handling special characters.
3. Text Representation
Bag of Words (BoW): Representing text as a collection of words, ignoring grammar and
word order but keeping track of word frequency.
Term Frequency-Inverse Document Frequency (TF-IDF): A statistic that reflects the
importance of a word in a document relative to a collection of documents.
Word Embeddings: Using dense vector representations of words where semantically
similar words are closer together in the vector space (e.g., Word2Vec, GloVe).
4. Feature Extraction
Extracting meaningful features from the text data that can be used for various NLP tasks.
N-grams: Capturing sequences of N words to preserve some context and word order.
Syntactic Features: Using parts of speech tags, syntactic dependencies, and parse
trees.
2
AI UNIT V NOTES
Evaluating the performance of the NLP algorithm using metrics such as accuracy, precision,
recall, F1-score, and others.
Hyperparameter Tuning: Adjusting model parameters to improve performance.
Error Analysis: Analysing errors to understand model weaknesses and improve
robustness.
8. Iteration and Improvement
Continuously improving the algorithm by incorporating new data, refining preprocessing
techniques, experimenting with different models, and optimizing features.
NLP Techniques:
1. Rule-Based Approach
7. Transformers
[Date]
3
AI UNIT V NOTES
NLP Applications:
1. Virtual Assistants (e.g., Siri, Alexa)
2. Language Translation Apps (e.g., Google Translate)
3. Sentiment Analysis Tools
4. Text Summarization Tools
5. Chatbots
6. Speech Recognition Systems
7. Information Retrieval Systems
There are 2 main components of Natural language processing: Syntactic Analysis and Semantic
analysis.
Syntactic Analysis
Syntactic analysis involves analysing the grammatical syntax of a sentence to understand its
meaning.
For example, consider the following sentence: “The cow jumped over the moon“
Using Syntactic analysis, a computer would be able to understand the parts of speech of the
different words in the sentence. Based on the understanding, it can then try and estimate the
meaning of the sentence. In the case of the above example (however ridiculous it might be in
real life), there is no conflict about the interpretation. Thus, the syntactic analysis does the job
just fine.
However, human language is nuanced and not always, is a sentence as simple as the one
described above. Consider this: “Does this all sound like a joke to you?“
A human would easily understand the irateness locked in the sentence. However, a syntactic
analysis may just be too naive for it. That leads us to the need for something better and more
sophisticated, i.e., Semantic Analysis.
Semantic Analysis
In the case of semantic analysis, a computer understands the meaning of a text by analyzing
the text as a whole and not just looking at individual words. The context in which a word is
used is very important when it comes to semantic analysis. Let’s revisit the same example:
“Does it all sound like a joke to you?” While the word “joke” may be positive on its own,
something sounding like a joke may not be so. Thus, the context here is derived by analyzing
the whole sentence instead of isolated words.
[Date]
4
AI UNIT V NOTES
The semantic analysis does throw better results, but it also requires substantially more
training and computation. We will now understand why.
Modern-day SEO strategy requires a semantic approach. Content is today analyzed by search
engines, semantically and ranked accordingly. It is thus important to load the content with
sufficient context and expertise. On the whole, such a trend has improved the general
content quality of the internet.
[Date]
5
AI UNIT V NOTES
Syntactic analysis is much easier to implement than semantic analysis. The typical process
includes:
o Tokenization: Breaking a text into sentence tokens & then a sentence into word
tokens
o Lemmatization: Identifying the lemma of a word. Example: Cri will be the
lemma for all cry , crying, cried
o POS Tagging: Identifying the part of speech (POS) of a particular word in a
sentence.
Advantages of Syntactic Analysis
While semantic analysis is more modern and sophisticated, it is also expensive to implement.
Thus for simple text analysis, syntactic analysis is still used. One such need is described below.
Parsing
Parsing implies pulling out a certain set of words from a text, based on predefined rules. For
example, we want to find out the names of all locations mentioned in a newspaper. Semantic
analysis would be an overkill for such an application and syntactic analysis does the job just
fine.
Discourse Processing
Definition: Analysis of language beyond sentence level, focusing on context, structure, and
relationships.
Key Concepts:
1. Discourse Structure: Organization of text into coherent units.
2. Coherence Relations: Connections between sentences (e.g., cause-effect).
3. Discourse Markers: Words/phrases indicating relationships (e.g., "however").
4. Anaphora Resolution: Identifying pronoun references.
5. Coreference Resolution
[Date]
6
AI UNIT V NOTES
Pragmatic Processing
Definition: Analysis of language in context, considering speaker intention, implicature, and
inference.
Key Concepts:
1. Implicature: Inferring meaning beyond literal interpretation.
2. Inference: Drawing conclusions from context.
3. Presupposition: Assumptions underlying language.
3. Cantering Theory
4. Rhetorical Structure Theory (RST)
5. Pragmatic Inference Frameworks
Applications
1. Text Summarization
2. Question Answering
3. Sentiment Analysis
4. Dialogue Systems
5. Natural Language Generation
[Date]
7
AI UNIT V NOTES
Forms of Learning:
1. Supervised Learning: Learning from labelled data.
2. Unsupervised Learning: Learning from unlabelled data.
3. Reinforcement Learning: Learning from rewards/punishments.
Inductive Learning:
Definition: Inductive learning is a type of machine learning where the algorithm learns
patterns and relationships from specific instances (data) to make generalizations.
How it works:
1. Data Collection: Gather specific instances (data points) related to the problem.
2. Pattern Identification: Identify patterns, relationships, or rules within the data.
3. Hypothesis Formation: Formulate a hypothesis (model) based on the patterns.
4. Generalization: Apply the hypothesis to new, unseen data.
Example:
Problem: Predict whether a person will buy a car based on age and income.
Data:
-------------------------------------------------------------------------------
| 25 | 40000 | Yes |
| 30 | 50000 | Yes |
| 35 | 60000 | Yes |
| 20 | 30000 | No |
| 40 | 70000 | Yes |
[Date]
8
AI UNIT V NOTES
Pattern Identification:
- People with higher incomes tend to buy cars.
- People above 30 years old tend to buy cars.
Hypothesis Formation:
- If age > 30 and income > 50000, then likely to buy a car.
Generalization:
- New data: Age = 38, Income = 65000
- Prediction: Likely to buy a car (based on hypothesis)
9
AI UNIT V NOTES
Key Concepts:
1. Features: Attributes used to make decisions.
2. Class Labels: Target variable predictions.
3. Information Gain: Measure of feature importance.
4. Gini Impurity: Measure of node purity.
Key Concepts:
1. Domain Knowledge: Expert knowledge about the problem domain.
10
AI UNIT V NOTES
1. If a patient has high blood pressure, they are likely to have HTN.
2. If a patient has an increased heart rate, they are likely to have HTD.
3. If a patient has a family history of thyroid problems, they are likely to have HTD.
Training Data:
EBL Process:
1. Select a patient (e.g., Patient 1).
11
AI UNIT V NOTES
Example:
Problem: Product Recommendation
Goal: Recommend products to users based on their past purchase
Data:
| User ID | Product ID | Rating |
-------------------------------------------------------------------------------------------
[Date]
|1 |A |5|
12
AI UNIT V NOTES
|1 |B |4|
|2 |C |3|
|2 |D |2|
Relevance Information:
Definition: Neural networks are machine learning models inspired by the human brain's
structure and function.
[Date]
Key Concepts:
13
AI UNIT V NOTES
1. Artificial Neurons: Processing units that receive inputs and produce outputs.
2. Activation Functions: Introduce non-linearity to neural networks.
3. Backpropagation: Training algorithm for neural networks.
Example:
Real-World Applications
1. Image Classification
2. Natural Language Processing
3. Speech Recognition
Forward Propagation
Input Layer: Each feature in the input layer is represented by a node on the network,
which receives input data.
Weights and Connections: The weight of each neuronal connection indicates how
strong the connection is. Throughout training, these weights are changed.
[Date]
14
AI UNIT V NOTES
Hidden Layers: Each hidden layer neuron processes inputs by multiplying them by
weights, adding them up, and then passing them through an activation function. By
doing this, non-linearity is introduced, enabling the network to recognize intricate
patterns.
Output: The final result is produced by repeating the process until the output layer is
reached.
Backpropagation
Loss Calculation: The network’s output is evaluated against the real goal values, and a
loss function is used to compute the difference. For a regression problem, the Mean
Squared Error (MSE) is commonly used as the cost function.
Loss Function:
Gradient Descent: Gradient descent is then used by the network to reduce the loss. To
lower the inaccuracy, weights are changed based on the derivative of the loss with
respect to each weight.
Adjusting weights: The weights are adjusted at each connection by applying this
iterative process, or backpropagation, backward across the network.
Training: During training with different data samples, the entire process of forward
propagation
loss calculation, and backpropagation is done iteratively, enabling the network to
adapt and learn patterns from the data.
Activation Functions: Model non-linearity is introduced by activation functions like
the rectified linear unit (ReLU) or sigmoid. Their decision on whether to “fire” a
neuron is based on the whole weighted input.
Genetic Learning
Definition: Genetic algorithms inspire genetic learning, using principles of natural selection
and genetics.
Key Concepts:
[Date]
3. Resource Allocation
Comparison
| | Neural Network Learning | Genetic Learning |
| Inspiration | Human Brain | Natural Selection |
| Key Concepts | Neurons, Activation Functions | Chromosomes, Fitness Function |
Expert Systems:
Definition: Expert systems are computer programs that mimic human expertise in a specific
domain, using knowledge representation and reasoning techniques.
1. knowledge base ,
2. inference engine,
16
AI UNIT V NOTES
3. user interface,
4. explanation module
5. knowledge acquisition system.
The knowledge base contains facts and rules relevant to a specific domain,
while the inference engine interprets this knowledge to find solutions to user
problems.
The user interface allows non-experts to interact with the system,
while the explanation module provides explanations for the system’s conclusions.
The knowledge acquisition system ensures that the expert system can acquire and
integrate new knowledge.
Types of Expert Systems in AI
There are several types of Expert Systems used in AI:
1. Rule-Based Expert Systems: These systems use a collection of rules to make decisions.
Rules are created by human experts and guide the system’s reasoning process. An
example is Mycin, an expert system for diagnosing bacterial infections.
2. Frame-Based Expert Systems: Frame-based expert systems use frame representation
to organize knowledge. Frames capture structured information about entities and
their attributes, allowing the system to reason about specific instances. For example,
an expert system for car insurance might use frames to represent different types of
coverage and associated costs.
3. Fuzzy Expert Systems: Fuzzy expert systems handle imprecise or uncertain data using
fuzzy logic. This allows the system to reason with degrees of truth rather than binary
values. Fuzzy expert systems are useful in domains where precise measurements are
difficult or subjective, such as weather forecasting or risk assessment.
4. Neural Expert Systems: Neural expert systems utilize neural networks to learn from
data through training processes. Neural networks can recognize patterns and make
predictions based on input data. They are particularly effective in areas such as image
recognition and natural language processing.
5. Neuro-Fuzzy Expert Systems: Neuro-fuzzy expert systems combine elements of fuzzy
logic and neural networks to make decisions based on both numerical and linguistic
information. These systems excel in complex domains where uncertainty and
imprecision are prevalent, such as financial forecasting or traffic management.
Advantages and Benefits of Expert Systems
17
AI UNIT V NOTES
They are highly scalable as they can handle large amounts of information efficiently.
This makes them suitable for managing complex domains with vast amounts of data.
Moreover, expert systems in AI can be cost-effective by reducing the need for human
experts, resulting in significant cost savings.
2. Dendral: Dendral, one of the earliest expert systems, focused on organic chemistry
analysis. In troubleshooting scenarios, similar rule-based reasoning is applied where
expert systems analyse complex systems to identify and resolve issues.
Examples:
18
AI UNIT V NOTES
Example Application:
Medical Diagnosis Expert System
Knowledge Base:
(defrule fever
(symptom fever yes)
=>
(assert (disease pneumonia)))
(disease ?d)
=>
(printout t "Diagnosis: “? d crlf))
Explanation:
[Date]
19
AI UNIT V NOTES
1. Fever Rule: If the symptom "fever" is yes, then assert "pneumonia" as a possible disease.
2. Headache Rule: If the symptom "headache" is yes, then assert "meningitis" as a possible
disease.
3. Diagnosis Rule: If a disease is asserted, print out the diagnosis.
User Interaction
CLIPS> (reset)
Knowledge Acquisition:
Definition: Process of gathering, structuring, and representing domain expertise.
Methods:
1. Interviews: Domain expert interviews.
2. Surveys: Questionnaires and surveys.
20