0% found this document useful (0 votes)
6 views34 pages

Unit Iv

Unit IV discusses Genetic Algorithms (GAs), which are optimization techniques inspired by natural evolution, highlighting their components such as population, chromosome, gene, fitness function, selection, crossover, mutation, and generation. It outlines the working of GAs through a step-by-step example of maximizing a function, along with various operations like selection methods, crossover techniques, mutation applications, and the concept of elitism. The document also addresses the limitations of GAs, including convergence speed, premature convergence, parameter tuning, computational cost, scalability issues, representation challenges, lack of guarantee for optimal solutions, sensitivity to initial population, complexity in implementation, and the risk of overfitting.

Uploaded by

Ayman Mir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views34 pages

Unit Iv

Unit IV discusses Genetic Algorithms (GAs), which are optimization techniques inspired by natural evolution, highlighting their components such as population, chromosome, gene, fitness function, selection, crossover, mutation, and generation. It outlines the working of GAs through a step-by-step example of maximizing a function, along with various operations like selection methods, crossover techniques, mutation applications, and the concept of elitism. The document also addresses the limitations of GAs, including convergence speed, premature convergence, parameter tuning, computational cost, scalability issues, representation challenges, lack of guarantee for optimal solutions, sensitivity to initial population, complexity in implementation, and the risk of overfitting.

Uploaded by

Ayman Mir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

Unit-IV: Artificial Intelligence 6th Semester

UNIT-IV
PART-I
 GENETIC ALGORITHMS (GAS): A DETAILED EXPLANATION
Genetic Algorithms (GAs) are optimization techniques inspired by the principles of natural
evolution, such as selection, crossover, and mutation. They are particularly useful in solving
problems where the solution space is vast, complex, or poorly understood.
1. Population
 Explanation: The population in GAs is a group of potential solutions to the problem,
each represented by a "chromosome."
 Example: Suppose we are trying to optimize a function, like finding the maximum
value of f(x)=x2−3x+2 within a certain range. A population could consist of several
candidate values for x, like [1, 2, 3, 4, 5]. Each value of x is a "chromosome" or
"individual" in the population.
2. Chromosome
 Explanation: A chromosome is a representation of a solution. It is often encoded as a
string of binary digits (0s and 1s) but can also be represented in other ways.
 Example: If x ranges from 0 to 31, each possible value of x can be represented as a 5-
bit binary number. For example, x=19 could be represented as "10011." This binary
string is the chromosome.
3. Gene
 Explanation: A gene is a segment of a chromosome representing a specific trait or
feature of the solution.
 Example: In the binary string "10011," each bit (1 or 0) is a gene. The first gene is "1,"
the second is "0," and so on.
4. Fitness Function
 Explanation: The fitness function evaluates how good a solution is. It provides a score
(fitness value) to each chromosome.
 Example: For the function f(x)=x2−3x+2, the fitness of x=19 (with the binary
chromosome "10011") would be calculated as:
f(19) = 192 − 3(19) + 2 = 361 − 57 +2 = 306
Here, the fitness score is 306.
5. Selection
 Explanation: Selection is the process of choosing individuals from the population to
reproduce based on their fitness scores. Higher fitness individuals have a higher chance
of being selected.

Compiled by: Er. Shaif Mehraj Makhdoomi. 1


Unit-IV: Artificial Intelligence 6th Semester

 Example: If we have individuals with fitness scores of 50, 60, 70, 80, and 90, the ones
with scores of 80 and 90 have a higher probability of being selected for reproduction
because they represent better solutions.
6. Crossover (Recombination)
 Explanation: Crossover is a genetic operator that combines two parent chromosomes
to produce offspring. It mimics the biological process of reproduction.
 Example: Suppose we have two parent chromosomes: Parent 1 ("10101") and Parent 2
("11010"). A crossover point is randomly selected, say between the third and fourth
bits:
 Parent 1: "101 | 01"
 Parent 2: "110 | 10"
The offspring could be:
 Offspring 1: "10110"
 Offspring 2: "11001"
7. Mutation
 Explanation: Mutation introduces random changes to a chromosome's genes. It helps
maintain diversity in the population and allows the algorithm to explore new solutions.
 Example: Consider the offspring "10110." If a mutation occurs at the second gene,
flipping it from "0" to "1," the chromosome becomes "11110."
8. Generation
 Explanation: A generation is one complete cycle of evaluation, selection, crossover,
and mutation, resulting in a new population.
 Example: Starting with an initial population [1, 2, 3, 4, 5], after applying selection,
crossover, and mutation, we might end up with a new population like [3, 4, 6, 7, 9].
This new set of solutions forms the next generation.

WORKING OF GENETIC ALGORITHMS: A STEP-BY-STEP EXAMPLE


Problem: Maximize the function f(x)=x2−3x+2 for x in the range [0, 31].
Step 1: Initialization
 Population: Randomly generate an initial population of potential solutions.
 Example: [3 (00011), 8 (01000), 15 (01111), 23 (10111), 31 (11111)]
Step 2: Evaluation
 Fitness Calculation: Compute the fitness for each individual.

Compiled by: Er. Shaif Mehraj Makhdoomi. 2


Unit-IV: Artificial Intelligence 6th Semester

 Example:
 f(3)=2
 f(8)=50
 f(15)=182
 f(23)=426
 f(31)=890
Step 3: Selection
 Selection: Choose individuals based on fitness scores.
 Example: Individuals with chromosomes 31 ("11111") and 23 ("10111") are
selected because they have the highest fitness.
Step 4: Crossover
 Crossover: Perform crossover to generate new offspring.
 Example:
 Parent 1: "11111"
 Parent 2: "10111"
 Crossover at position 3:
 Offspring 1: "11111"
 Offspring 2: "10111"
Step 5: Mutation
 Mutation: Introduce mutations to some offspring.
 Example: If "11111" mutates at position 2, the result could be "10111."
Step 6: Replacement
 New Population: Replace the old population with the new offspring.
 Example: New population might be [15 (01111), 23 (10111), 23 (10111), 23
(10111), 31 (11111)]
Iteration
 Repeat the process for several generations until a termination criterion is met.

Compiled by: Er. Shaif Mehraj Makhdoomi. 3


Unit-IV: Artificial Intelligence 6th Semester

GENETIC ALGORITHMS (GAS): OPERATIONS:


1. Selection
 Purpose: Selection is the process of choosing the fittest individuals from the population
to create offspring for the next generation. The idea is to give higher chances of
reproduction to individuals with better fitness, mimicking the "survival of the fittest"
principle in natural selection.
 Common Methods:
 Roulette Wheel Selection: Individuals are selected based on a probability
proportional to their fitness. Imagine a roulette wheel where each individual's
slice is sized according to their fitness score. The wheel is spun, and the
individual where the ball lands is selected.
 Tournament Selection: A set number of individuals are randomly chosen from
the population, and the one with the highest fitness among them is selected. This
process is repeated until the desired number of individuals is selected.
 Rank-Based Selection: Individuals are ranked based on their fitness, and
selection probabilities are assigned based on these ranks rather than raw fitness
scores. This helps in cases where fitness differences are extreme, preventing the
best individuals from dominating the selection process too quickly.
2. Crossover (Recombination)
 Purpose: Crossover combines the genetic material of two parent individuals to produce
one or more offspring. This operation is crucial for introducing new combinations of
genes into the population, which can lead to better solutions.
 Techniques:
 Single-Point Crossover: A single crossover point is selected on the parent
chromosomes, and the segments after this point are swapped between the two
parents. For example, if Parent 1 is "11001" and Parent 2 is "10110," and the
crossover point is between the third and fourth bits, the offspring could be
"11010" and "10101."
 Multi-Point Crossover: Multiple crossover points are selected, and the
segments between these points are swapped between the parents. This technique
can produce more varied offspring but can also disrupt advantageous gene
combinations.
 Uniform Crossover: Each gene in the offspring is randomly selected from one
of the corresponding genes in the parents. This method provides a high level of
diversity in the offspring.
3. Mutation
 Purpose: Mutation introduces random changes to an individual's genes. This operation
maintains genetic diversity within the population and helps prevent premature

Compiled by: Er. Shaif Mehraj Makhdoomi. 4


Unit-IV: Artificial Intelligence 6th Semester

convergence to a suboptimal solution. Mutation ensures that the algorithm can explore
new areas of the solution space.
 Application:
 Bit Mutation: In binary-encoded chromosomes, individual bits (0 or 1) are
flipped with a certain probability. For example, if the chromosome is "11001"
and the mutation point is the third bit, the result could be "11101."
 Gene Mutation: In other types of encodings, such as real numbers, mutation
might involve adding a small random value to a gene. For instance, if a gene
has the value 5.6, a mutation might change it to 5.8.
 Chromosome Mutation: Entire segments of a chromosome can be rearranged
or swapped. This type of mutation is less common but can be useful in specific
applications.
4. Elitism
 Purpose: Elitism ensures that the best individuals from the current generation are
carried over to the next generation without alteration. This helps preserve the quality of
the best solutions found so far and ensures that the genetic algorithm does not lose the
best solutions during the random processes of crossover and mutation.
 How It Works: A certain number of top-performing individuals (e.g., the top 5% of
the population) are directly copied to the next generation. The rest of the population is
then filled using the usual selection, crossover, and mutation processes. This ensures
that the overall fitness of the population does not degrade over generations.

APPLICATIONS OF GENETIC ALGORITHMS: REAL-WORLD EXAMPLES


1. Scheduling:
 Example: Scheduling classes in a university to minimize conflicts and optimize
resource usage. Each chromosome represents a possible schedule. The fitness
function could evaluate how well the schedule meets the requirements.

2. Optimization in Engineering:
 Example: Designing an aircraft wing for minimal drag. Each chromosome
could represent a different wing shape, and the fitness function would calculate
drag based on computational fluid dynamics simulations.
3. Feature Selection in Machine Learning:
 Example: Selecting the most relevant features for a predictive model. Each
chromosome represents a subset of features, and the fitness function evaluates
the model's accuracy.

Compiled by: Er. Shaif Mehraj Makhdoomi. 5


Unit-IV: Artificial Intelligence 6th Semester

4. Game Playing:
 Example: Evolving strategies for playing chess. Each chromosome could
represent a different strategy, and the fitness function would be based on the
performance of the strategy in games.

Genetic Algorithms (GAs): Limitations


1. Convergence Speed:
 Explanation: Genetic Algorithms may converge slowly, especially when
dealing with complex or high-dimensional problems. The evolutionary process,
involving selection, crossover, and mutation, often requires many generations
to approach an optimal solution. This can lead to longer computation times,
particularly in scenarios where quick results are needed.
 Example: In a complex scheduling problem, where the goal is to optimize the
allocation of resources and time slots, GAs might take numerous generations to
find a satisfactory solution, slowing down the overall decision-making process.
2. Premature Convergence:
 Explanation: There is a risk that the algorithm will converge to a local optimum
rather than the global optimum. This happens when the population loses
diversity too quickly, and the search becomes confined to a suboptimal area of
the solution space.
 Example: In optimizing the design of an aerodynamic shape, the GA might
quickly settle on a suboptimal design that provides decent performance but is
far from the best possible solution because the population lacks sufficient
diversity to explore better options.
3. Parameter Tuning:
 Explanation: GAs require careful tuning of parameters like mutation rate,
crossover rate, and population size. The effectiveness of the algorithm heavily
depends on these parameters, and poor choices can lead to inefficient or
unsuccessful searches.
 Example: A high mutation rate might introduce too much randomness,
preventing convergence, while a low mutation rate might cause the algorithm
to get stuck in local optima. Balancing these parameters is crucial for the success
of the GA.
4. Computational Cost:
 Explanation: GAs can be computationally expensive because they often
require evaluating a large number of individuals across many generations. Each
evaluation can be resource-intensive, especially if the fitness function is
complex.

Compiled by: Er. Shaif Mehraj Makhdoomi. 6


Unit-IV: Artificial Intelligence 6th Semester

 Example: In real-time applications like real-time traffic management or


dynamic resource allocation, the computational cost of running a GA might be
prohibitive, as the algorithm needs to make decisions quickly, and evaluating
many potential solutions in each generation can be too time-consuming.
5. Scalability Issues:
 Explanation: GAs may struggle to scale effectively as the size of the problem
or the complexity of the solution space increases. As the number of variables
grows, the search space expands exponentially, making it increasingly difficult
for GAs to find optimal solutions within a reasonable time.
 Example: In optimizing a neural network's architecture (e.g., number of layers,
neurons, and activation functions), the search space becomes enormous as more
parameters are introduced. This can make it challenging for a GA to efficiently
explore and identify the best architecture.
6. Representation Challenges:
 Explanation: The performance of GAs is highly dependent on how the solution
is encoded (represented) in the chromosome. Poor or inappropriate
representations can lead to ineffective searches and difficulty in achieving good
results.
 Example: In designing an optimal circuit layout, the chromosome
representation of the circuit configuration might be too rigid or complex,
making crossover and mutation operations less effective and leading to
suboptimal solutions.
7. Lack of Guarantee for Optimal Solutions:
 Explanation: GAs are heuristic methods, meaning they do not guarantee
finding the global optimum. They are often used to find good solutions, but
there's no certainty that the solution obtained is the absolute best.
 Example: In optimizing a portfolio of investments, a GA might find a highly
profitable portfolio, but it might not be the most profitable one possible, as the
search could miss the global optimum.
8. Sensitivity to Initial Population:
 Explanation: The initial population can significantly influence the outcome of
the GA. A poorly chosen initial population may lead to slow convergence or
poor-quality solutions, as the algorithm's ability to explore the solution space
might be limited from the start.
 Example: If the initial population in a GA for optimizing a marketing campaign
consists of strategies that are too similar, the algorithm may fail to explore more
innovative and potentially more effective strategies.

Compiled by: Er. Shaif Mehraj Makhdoomi. 7


Unit-IV: Artificial Intelligence 6th Semester

9. Complexity in Implementation:
 Explanation: Implementing GAs can be complex, especially when designing
problem-specific operators (like crossover and mutation) that work well with
the problem at hand. This can require significant expertise and effort.
 Example: Developing a GA for evolving complex shapes in 3D modeling
requires custom crossover and mutation operators that handle the intricacies of
3D geometry, making the implementation process challenging and time-
consuming.
10. Overfitting Risk:
 Explanation: In some cases, GAs might overfit to the particular set of training
data or problem constraints used during the optimization process, leading to
solutions that perform well in the specific context but poorly in general or real-
world applications.
 Example: A GA trained to optimize a trading algorithm might perform
exceptionally well on historical data but fail when applied to new, unseen
market conditions due to overfitting.

 FUZZY LOGIC OVERVIEW:


Fuzzy Logic is an advanced form of multi-valued logic derived from fuzzy set theory, which
was introduced by Lotfi Zadeh in 1965. It provides a mathematical framework for dealing with
uncertainty and imprecision, allowing for reasoning that is approximate rather than strictly
binary or exact. Fuzzy Logic is particularly useful in situations where traditional Boolean logic
fails to capture the complexities of real-world scenarios that involve gradations or degrees of
truth.
1. Fuzzy Sets
 Definition: A fuzzy set is an extension of the classical set concept, where each element
in the set is associated with a degree of membership, typically ranging between 0 and
1. This degree represents the extent to which the element belongs to the set.

A fuzzy set is a class of objects with a continuum of grades of membership. A fuzzy set
is characterized by a membership function, which assigns to each object a grade of
membership ranging between 0 and 1.

 Example: Consider the fuzzy set "tall people." Instead of classifying people as simply
tall or not tall, fuzzy logic allows for degrees of tallness. A person who is 6 feet tall
might have a membership grade of 0.8 in the "tall" fuzzy set, while someone who is 5
feet 5 inches tall might have a membership grade of 0.4.

2. Membership Function (MF): The membership function is a key feature of fuzzy sets,
defining how each point in the input space (the universe of discourse) is mapped to a
membership value (degree of membership). This function can take various shapes
(triangular, trapezoidal, Gaussian, etc.), depending on how you want to model the concept.

Compiled by: Er. Shaif Mehraj Makhdoomi. 8


Unit-IV: Artificial Intelligence 6th Semester

 Example: Consider the fuzzy set "Tall people." Instead of a sharp cutoff where
people shorter than 180 cm are not considered tall, and those taller are, a fuzzy
set allows for a gradual transition. For instance, someone who is 170 cm tall
might have a membership value of 0.4 in the "Tall people" set, while someone
who is 190 cm tall might have a membership value of 0.9.
 Types of Membership Functions:
 Triangular MF: Simple and defined by a triangular shape, with three
parameters: a lower bound, an upper bound, and a peak where membership is 1.
 Trapezoidal MF: Similar to the triangular MF but with a plateau, representing
a range of values with full membership.
 Gaussian MF: Smooth and symmetric, defined by a bell curve, useful for
representing natural variations.
 Sigmoidal MF: S-shaped curve, useful for modeling situations with a gradual
transition from non-membership to full membership.
 Example: For the fuzzy set "warm temperature," a triangular membership function
might assign a temperature of 20°C a membership value of 0, 25°C a membership value
of 0.5, and 30°C a membership value of 1.

3. Linguistic Variables
 Definition: A linguistic variable is a variable whose values are words or sentences in
natural language rather than numerical values. These variables are central to fuzzy
logic, as they allow for more intuitive reasoning based on human language.
 Linguistic Terms: These are the specific values that a linguistic variable can take. Each
linguistic term is associated with a fuzzy set and a corresponding membership function.
 Example: If "Temperature" is a linguistic variable, its linguistic terms could be
"Cold," "Warm," and "Hot." Each term would be associated with a fuzzy set
that describes the degree to which a given temperature value belongs to that
category.
 Fuzzy Partitions: Linguistic variables often partition the universe of discourse into
overlapping fuzzy sets. For example, the temperature range might be divided into
overlapping regions for "Cold," "Warm," and "Hot," where a specific temperature
might partially belong to more than one category.
3. Degree of Truth
 Definition: In classical logic, a statement is either true or false (binary logic). In fuzzy
logic, the truth of a statement can take any value between 0 and 1, reflecting its degree
of truth or the extent to which it is true.
 Truth Values: These are numerical values between 0 and 1 assigned to propositions or
conditions, indicating how true the statement is within the context of fuzzy logic.

Compiled by: Er. Shaif Mehraj Makhdoomi. 9


Unit-IV: Artificial Intelligence 6th Semester

 Example: Consider the statement "The room is warm." In fuzzy logic, this
statement might have a truth value of 0.7, meaning that the room is somewhat
warm, but not entirely so.
FUZZY RULES
Fuzzy rules are fundamental components of fuzzy logic systems, used to model and manage
uncertainty by employing fuzzy sets. They follow an IF-THEN structure and enable decision-
making in complex systems where traditional binary logic may be insufficient.
Structure of Fuzzy Rules
1. Antecedent (IF part):
 This part describes the conditions or input variables that are evaluated.
 Example: IF temperature IS high
2. Consequent (THEN part):
 This part describes the output or action based on the conditions described in the
antecedent.
 Example: THEN fan speed IS fast
Fuzzy Variables
1. Linguistic Variables:
 These variables are expressed in natural language and describe the range of
possible values for a given input.
 Example: Temperature can be categorized as low, medium, or high.
2. Membership Functions:
 These functions define the degree to which a particular input belongs to a fuzzy
set, with values ranging from 0 (no membership) to 1 (full membership).
 Types of Membership Functions:
 Triangular: Defined by a triangle with three points. For instance, a
temperature membership function with low, medium, and high can be
represented by triangular functions.
 Trapezoidal: Defined by a trapezoid with four points, allowing for a
range of values where the membership value is high before tapering off.
 Gaussian: Defined by a bell-shaped curve, useful for representing
smooth transitions between fuzzy sets.
Types of Fuzzy Rules
1. Single Input Single Output (SISO):
 Definition: Deals with one input variable leading to one output variable.

Compiled by: Er. Shaif Mehraj Makhdoomi. 10


Unit-IV: Artificial Intelligence 6th Semester

 Example: Temperature Control System


 Rule: IF temperature IS high THEN heater power IS low
 Explanation: If the temperature is high, the heater power is set to low
to maintain an appropriate room temperature.
2. Multiple Input Single Output (MISO):
 Definition: Involves multiple input variables leading to one output variable.
 Example: Fan Speed Control Based on Temperature and Humidity
 Rules:
 IF temperature IS high AND humidity IS low THEN fan speed
IS fast
 IF temperature IS medium AND humidity IS medium THEN fan
speed IS medium
 IF temperature IS low AND humidity IS high THEN fan speed
IS slow
 Explanation: The fan speed is adjusted based on both temperature and
humidity to optimize comfort.
3. Multiple Input Multiple Output (MIMO):
 Definition: Multiple input variables lead to multiple output variables.
 Example: Climate Control System
 Rules:
 IF temperature IS high AND humidity IS high THEN air
conditioning IS high AND dehumidifier IS high
 IF temperature IS medium AND humidity IS low THEN air
conditioning IS medium AND dehumidifier IS off
 IF temperature IS low AND humidity IS medium THEN air
conditioning IS off AND dehumidifier IS low
 Explanation: The system adjusts both the air conditioning and
dehumidifier settings based on temperature and humidity to maintain an
optimal indoor environment.

Compiled by: Er. Shaif Mehraj Makhdoomi. 11


Unit-IV: Artificial Intelligence 6th Semester

 OPERATIONS ON FUZZY SETS


Operations on fuzzy sets are essential for manipulating and combining fuzzy information
within a fuzzy logic system. These operations allow for the evaluation of fuzzy rules and the
aggregation of fuzzy outputs. The key operations on fuzzy sets include fuzzy union (OR), fuzzy
intersection (AND), fuzzy complement (NOT), and fuzzy implications. Below is a detailed
explanation of each operation with examples.
1. Fuzzy Union (OR Operation)
Definition: The fuzzy union operation combines two fuzzy sets to create a new fuzzy set where
the membership value of an element is the maximum of its membership values in the original
sets.
Formula: For two fuzzy sets A and B with membership functions μA(x) and μB(x),
respectively, the membership function of the fuzzy union A∪B is given by:

Example: Consider two fuzzy sets:


 Fuzzy set A for "Warm": Membership function μA(x) = Triangular(x;20,25,30)

 Fuzzy set B for "Hot": Membership function μB(x) = Triangular (x;25,30,35)


For a temperature of 27°C:

2. Fuzzy Intersection (AND Operation)


Definition: The fuzzy intersection operation combines two fuzzy sets to create a new fuzzy set
where the membership value of an element is the minimum of its membership values in the
original sets.
Formula: For two fuzzy sets A and B with membership functions μA(x) and μB(x),
respectively, the membership function of the fuzzy intersection A∩B is given by:

Example: Using the same fuzzy sets A and B as above, for a temperature of 27°C:

Compiled by: Er. Shaif Mehraj Makhdoomi. 12


Unit-IV: Artificial Intelligence 6th Semester

3. Fuzzy Complement (NOT Operation)


Definition: The fuzzy complement operation creates a new fuzzy set where the membership
value of an element is the complement of its membership value in the original set. This
operation represents the degree to which an element does not belong to the original fuzzy set.
Formula: For a fuzzy set A with membership function μA(x), the membership function of the
fuzzy complement ¬A is given by

Example: Consider a fuzzy set A for "Cold" with the membership function
μA(x)=Triangular(x;0,10,20).
For a temperature of 15°C:

4. Fuzzy Implication
Definition: Fuzzy implication defines the degree to which a consequence follows from a given
premise based on fuzzy rules. There are several methods for defining fuzzy implications,
including Mamdani’s implication and the Lukasiewicz implication.
 Mamdani’s Implication: In Mamdani’s approach, fuzzy implication is often represented
as:

 Lukasiewicz Implication: In Lukasiewicz logic, the implication is defined as:

Example: Using fuzzy sets for "Temperature High" (A) and "Fan Speed High" (B), with:
 μA(x) for "High Temperature" defined as Triangular(x;30,35,40)
 μB(x) for "High Fan Speed" defined as Triangular(x;50,60,70)

Compiled by: Er. Shaif Mehraj Makhdoomi. 13


Unit-IV: Artificial Intelligence 6th Semester

For a temperature of 37°C:


 μA(37)=0.7
Assuming μB is not provided, if we consider a typical case where μB is fully activated (e.g.,
μB=1, the implication value for "High Temperature" leading to "High Fan Speed" is:

5. Fuzzy Aggregation
Definition: Fuzzy aggregation combines multiple fuzzy sets or rules into a single fuzzy set.
This can involve operations like fuzzy OR (union) and fuzzy AND (intersection), and can also
include more complex aggregation methods like weighted averages.
Example: Suppose we have multiple fuzzy sets for different temperature ranges and their
associated rules:

If we have rules for different conditions:


1. "IF temperature is Cold THEN set heater to high."
2. "IF temperature is Warm THEN set heater to medium."
3. "IF temperature is Hot THEN set heater to low."
The aggregated fuzzy output for heater settings would combine these rules based on their
respective membership values.

 HEDGES
In fuzzy logic, hedges are linguistic modifiers used to adjust or refine the meaning of fuzzy
terms. They enhance the flexibility and expressiveness of fuzzy rules by altering the
membership functions of fuzzy sets. Hedges help in representing uncertainty and vagueness
more accurately in natural language, allowing for more nuanced decision-making.
Types of Hedges
1. Intensifiers:
 Purpose: Increase the degree of membership of a fuzzy set.

Compiled by: Er. Shaif Mehraj Makhdoomi. 14


Unit-IV: Artificial Intelligence 6th Semester

 Common Intensifiers:
 Very: Enhances the membership value. For example, "very high" might
increase the membership value compared to just "high."
 Extremely: Similar to "very," but with a more substantial effect. For
example, "extremely high" would imply a membership value closer to
1.
2. Deintensifiers:
 Purpose: Decrease the degree of membership of a fuzzy set.
 Common Deintensifiers:
 Slightly: Reduces the membership value. For example, "slightly high"
would imply a lower membership compared to "high."
 Moderately: Less than "high" but more than "low." For instance,
"moderately high" indicates a membership value between high and
medium.
3. Negations:
 Purpose: Reverse the meaning of a fuzzy term.
 Common Negations:
 Not: Changes the membership from positive to negative. For example,
"not high" would imply a membership in the "low" or "medium" set.
 Less: Represents a reduction in the membership degree. For example,
"less high" indicates a membership value lower than "high."
4. Quantifiers:
 Purpose: Specify the quantity or extent to which a fuzzy term applies.
 Common Quantifiers:
 Some: Indicates that the fuzzy set applies to a certain extent. For
example, "somewhat high" suggests that the degree of membership is
moderate.
 Many: Implies a significant degree of membership. For example, "many
high" implies that the membership degree is high.
How Hedges Affect Membership Functions
Hedges modify the membership functions of fuzzy sets to reflect the intensity or degree of a
fuzzy term. The impact of a hedge on a membership function can be defined as follows:
1. Intensifiers:

Compiled by: Er. Shaif Mehraj Makhdoomi. 15


Unit-IV: Artificial Intelligence 6th Semester

 Very: The membership function might be scaled to increase the values. For
example, a membership function for "high" might be stretched to cover a
broader range.
 Extremely: Often, the membership function is shifted to approach the
maximum value more quickly. For instance, "extremely high" would have a
steeper slope and reach a membership value closer to 1 faster.
2. Deintensifiers:
 Slightly: The membership function might be contracted. For instance, "slightly
high" would have a lower peak and be more spread out.
 Moderately: The membership function is adjusted to show a moderate level of
membership. For example, "moderately high" would cover a range between
high and medium.
3. Negations:
 Not: This often involves complementing the membership function. For
example, "not high" would be the complement of the membership function for
"high."
 Less: The membership function is adjusted to be lower than the original term.
For instance, "less high" would have a peak lower than "high."
4. Quantifiers:
 Some: The membership function is adjusted to show that the term applies to a
certain extent, typically meaning a membership value in the middle range.
 Many: The membership function is adjusted to reflect a high degree of
membership. For example, "many high" would indicate that the membership
values are high for a significant range.
Examples of Hedges in Use
1. Temperature Control:
 Rule without Hedges: IF temperature IS high THEN fan speed IS fast
 Rule with Hedges:
 IF temperature IS very high THEN fan speed IS very fast
 IF temperature IS moderately high THEN fan speed IS medium
2. Climate Control:
 Rule without Hedges: IF humidity IS low THEN air conditioning IS off
 Rule with Hedges:
 IF humidity IS slightly low THEN air conditioning IS on low
 IF humidity IS extremely low THEN air conditioning IS off

Compiled by: Er. Shaif Mehraj Makhdoomi. 16


Unit-IV: Artificial Intelligence 6th Semester

3. Customer Satisfaction:
 Rule without Hedges: IF customer feedback IS positive THEN service quality
IS high
 Rule with Hedges:
 IF customer feedback IS very positive THEN service quality IS
excellent
 IF customer feedback IS moderately positive THEN service quality IS
good
FUZZY INFERENCE
Fuzzy inference is a critical component of fuzzy logic systems. It involves mapping inputs to
outputs based on fuzzy rules and processing the results through several stages. Here's a detailed
look at the fuzzy inference process:
1. Fuzzification
Fuzzification is the process of converting crisp (precise) input values into fuzzy values using
membership functions. This step allows the system to work with imprecise or vague data.
 Input Crisp Values: Raw data from sensors or measurements. For example, a
temperature reading of 30°C.
 Membership Functions: These functions define how input values map to degrees of
membership in fuzzy sets. Membership functions can be triangular, trapezoidal, or
Gaussian.
 Example: For a temperature of 30°C:
 Membership in "low" might be 0.2
 Membership in "medium" might be 0.8
 Membership in "high" might be 0.0
 Process: Use the membership functions to determine the degree to which the input
belongs to various fuzzy sets.
2. Rule Evaluation
Rule Evaluation involves applying fuzzy rules to the fuzzified inputs to determine how well
each rule applies.
 Rules: Expressed in the form of IF-THEN statements.
 Example Rule: IF temperature IS high THEN fan speed IS fast
 Degree of Applicability: Calculate how strongly the input fits the antecedent of each
rule. This involves combining the membership values from fuzzification with the fuzzy
operators in the rules.

Compiled by: Er. Shaif Mehraj Makhdoomi. 17


Unit-IV: Artificial Intelligence 6th Semester

 Example Calculation: If temperature is 30°C with a 0.8 membership in "high,"


the rule’s applicability might be 0.8.
 Process: Evaluate the degree to which each rule is satisfied based on the fuzzified
inputs.
3. Aggregation
Aggregation combines the results of all the rules to form a single fuzzy set for each output
variable. This step is necessary to consolidate the effects of multiple rules.
 Operators: Use fuzzy operators (AND, OR) to combine the results.
 AND Operator: Typically uses the minimum function to determine the degree
of membership. For example, if two rules apply with memberships of 0.6 and
0.8, the combined degree using AND might be 0.6.
 OR Operator: Typically uses the maximum function. For example, if two rules
apply with memberships of 0.6 and 0.8, the combined degree using OR might
be 0.8.
 Process: Aggregate the individual fuzzy outputs to form a composite fuzzy set for each
output variable.
4. Defuzzification
Defuzzification converts the aggregated fuzzy output into a crisp value that can be used for
practical purposes. This step is crucial for implementing the fuzzy logic system's decision.
 Centroid Method: Also known as the Center of Gravity or Center of Area method.
Calculates the center of gravity of the aggregated fuzzy set.
 Process: The output value is computed as the weighted average of all possible
values, where weights are the membership degrees.
 Formula: Centroid=∑(xi⋅μ(xi))
∑μ(xi),
where xi is a possible output value and μ(xi) is its membership degree.
 Maximum Membership Principle: Chooses the output value with the highest
membership degree.
 Process: Find the output value corresponding to the peak of the aggregated
fuzzy set.
 Weighted Average: Computes the average of all possible output values, weighted by
their membership degrees.
 Process: Similar to the centroid method but involves averaging output values
directly based on their weights.
 Process: Apply the chosen defuzzification method to convert the fuzzy set into a single
crisp value.

Compiled by: Er. Shaif Mehraj Makhdoomi. 18


Unit-IV: Artificial Intelligence 6th Semester

 EXAMPLE OF FUZZY INFERENCE SYSTEM


Let's consider a temperature control system using fuzzy inference:
1. Fuzzification:
 Temperature = 30°C
 Membership values:
 Low = 0.2
 Medium = 0.8
 High = 0.0
2. Rule Evaluation:
 Rules:
 IF temperature IS high THEN fan speed IS fast
 IF temperature IS medium THEN fan speed IS medium
 Evaluate:
 Rule 1: Applicability = 0.0 (no impact)
 Rule 2: Applicability = 0.8 (strong impact)
3. Aggregation:
 Combine results:
 Fuzzy set for fan speed might be aggregated to reflect the high
membership in "medium."
4. Defuzzification:
 Using the Centroid Method:
 Compute the crisp value for fan speed based on the aggregated fuzzy
set.

MAMDANI INFERENCE
Mamdani Inference is a type of fuzzy inference system (FIS) that is used to make decisions
or control systems based on fuzzy logic. It was introduced by Ebrahim Mamdani in 1975 and
is one of the most commonly used methods in fuzzy logic applications. Mamdani Inference is
designed to handle the mapping of fuzzy inputs to fuzzy outputs, and it emphasizes a more
interpretable approach to decision-making.

Compiled by: Er. Shaif Mehraj Makhdoomi. 19


Unit-IV: Artificial Intelligence 6th Semester

Key Components of Mamdani Inference


1. Fuzzification:
 Converts crisp input values into fuzzy values using membership functions.
 Example: For a temperature of 30°C, determine its membership in fuzzy sets
like "cool," "warm," and "hot."
2. Rule Base:
 A set of fuzzy rules in the IF-THEN format that defines how inputs are related
to outputs.
 Example: IF temperature IS hot THEN fan speed IS high
3. Inference Engine:
 Applies fuzzy rules to the fuzzified inputs to determine the degree of
applicability for each rule.
 Example: Calculate how strongly the temperature being "hot" implies a "high"
fan speed.
4. Aggregation:
 Combines the results of all the rules to form a single fuzzy set for each output
variable.
 Example: If multiple rules suggest different fan speeds, aggregate these results
to get a composite fuzzy set for fan speed.
5. Defuzzification:
 Converts the aggregated fuzzy set into a crisp output value for practical
implementation.
 Common methods include the centroid method, maximum membership
principle, and weighted average.
 Example: Calculate a specific fan speed value based on the aggregated fuzzy
set.
Mamdani Inference Process
1. Fuzzification:
 Input values are mapped to degrees of membership in various fuzzy sets using
membership functions.
 Example: Input temperature of 30°C might have membership values of 0.6 in
"warm" and 0.4 in "hot."
2. Rule Evaluation:

Compiled by: Er. Shaif Mehraj Makhdoomi. 20


Unit-IV: Artificial Intelligence 6th Semester

 Each rule in the rule base is evaluated using the fuzzified inputs. The degree of
fulfillment of each rule is calculated using fuzzy operators (AND, OR, etc.).
 Example: If a rule is IF temperature IS hot THEN fan speed IS high, and the
temperature's membership in "hot" is 0.4, then the rule's strength is 0.4.
3. Aggregation:
 Combine the outputs from all applicable rules to form a single fuzzy set for each
output. This is done using fuzzy operators.
 Example: Combine the outputs for different fan speeds from multiple rules into
a single fuzzy set.
4. Defuzzification:
 Convert the aggregated fuzzy set into a single crisp value. The most common
method is the centroid method, which calculates the center of gravity of the
aggregated fuzzy set.
 Example: Compute a specific fan speed value based on the aggregated fuzzy
set.
Example of Mamdani Inference
Scenario: Climate Control System
1. Fuzzification:
 Input Temperature: 28°C
 Membership Values:
 "Cool" = 0.3
 "Comfortable" = 0.7
 "Warm" = 0.0
2. Rule Base:
 IF temperature IS cool THEN heater power IS low
 IF temperature IS comfortable THEN heater power IS off
 IF temperature IS warm THEN heater power IS high
3. Rule Evaluation:
 Evaluate each rule based on the fuzzified input:
 Rule 1: Applicability = 0.3
 Rule 2: Applicability = 0.7
 Rule 3: Applicability = 0.0
4. Aggregation:

Compiled by: Er. Shaif Mehraj Makhdoomi. 21


Unit-IV: Artificial Intelligence 6th Semester

 Combine the results to form a fuzzy set for "heater power":


 Low power (0.3)
 Off (0.7)
 High power (0.0)
5. Defuzzification:
 Use the centroid method to find the crisp value for "heater power":
 Calculate the center of gravity of the aggregated fuzzy set to get a
specific heater power value.

PART –II
NLP
What is NLP?
Natural Language Processing (NLP) is a subfield of artificial intelligence (AI) that focuses on
enabling computers to understand, interpret, and generate human language. NLP combines
insights from computer science, linguistics, and machine learning to process large amounts of
natural language data and make sense of it in a way that is meaningful and useful. The ultimate
goal is to create systems that can interact with humans using natural language as intuitively as
possible.
Key Components of NLP
1. Tokenization
Tokenization is the process of splitting text into smaller units called tokens. Tokens can be
words, phrases, symbols, or other meaningful elements. Tokenization is often the first step in
NLP tasks and helps in simplifying the text for further analysis.
 Example: The sentence "Natural Language Processing is fascinating." can be tokenized
into ["Natural", "Language", "Processing", "is", "fascinating", "."].
2. Part-of-Speech Tagging (POS)
Part-of-Speech Tagging involves assigning grammatical categories to each token in a sentence.
These categories include nouns, verbs, adjectives, etc. POS tagging helps in understanding the
grammatical structure and function of each word within a sentence.
 Example: In the sentence "The cat sat on the mat," POS tagging might result in:
 "The" (Determiner)
 "cat" (Noun)
 "sat" (Verb)
 "on" (Preposition)

Compiled by: Er. Shaif Mehraj Makhdoomi. 22


Unit-IV: Artificial Intelligence 6th Semester

 "the" (Determiner)
 "mat" (Noun)

3. Named Entity Recognition (NER)


NER is the process of identifying and classifying entities in a text into predefined categories
such as people, organizations, locations, dates, etc. This helps in extracting structured
information from unstructured text.
 Example: In the sentence "Barack Obama was born in Honolulu," NER would identify:
 "Barack Obama" as a Person
 "Honolulu" as a Location
4. Parsing
Parsing involves analyzing the grammatical structure of a sentence to understand its syntactic
and semantic meaning. Parsing can be done using different methods such as dependency
parsing or constituency parsing.
 Example: The sentence "She gave him a book" can be parsed to reveal the relationships
between words (e.g., "gave" is the main verb, "She" is the subject, "him" is the indirect
object, and "a book" is the direct object).
5. Sentiment Analysis
Sentiment Analysis involves determining the emotional tone or sentiment behind a piece of
text. This can be positive, negative, or neutral. It is commonly used to gauge public opinion,
customer feedback, or social media sentiment.
 Example: Analyzing the review "The movie was fantastic!" would classify it as
positive sentiment.
6. Machine Translation
Machine Translation involves automatically translating text from one language to another. This
can be done using various techniques, including rule-based methods, statistical methods, and
neural networks.
 Example: Translating "Hello, how are you?" from English to French would result in
"Bonjour, comment ça va ?".
7. Text Summarization
Text Summarization aims to create a concise summary of a larger text while retaining the key
points and essential information. This can be done using extractive methods (selecting key
sentences) or abstractive methods (generating new sentences).
 Example: Summarizing a news article about a recent event to highlight the main points
and key details.

Compiled by: Er. Shaif Mehraj Makhdoomi. 23


Unit-IV: Artificial Intelligence 6th Semester

8. Speech Recognition and Synthesis


 Speech Recognition: Converting spoken language into text. This involves processing
audio signals and recognizing words and phrases.
 Example: Converting the spoken sentence "I would like a coffee" into the text
"I would like a coffee."
 Speech Synthesis: Generating spoken language from text. This involves converting
written text into natural-sounding speech.
 Example: Converting the text "Welcome to the conference" into spoken audio.

PHASES OF NATURAL LANGUAGE PROCESSING


The phases of Natural Language Processing (NLP) typically involve several stages, each
focusing on different aspects of processing and analyzing text.
1. Text Preprocessing
Text preprocessing is essential for transforming raw text into a format suitable for analysis.
This phase involves several key steps:
 Tokenization: Splitting text into smaller units, called tokens. For instance, the sentence
"NLP is amazing" is tokenized into ["NLP", "is", "amazing"]. Tokenization helps in
simplifying the text for further processing.
 Normalization: Converting text to a standard format to reduce complexity. This
includes:
 Lowercasing: Converting all characters to lowercase to maintain consistency.
 Removing Punctuation: Eliminating punctuation marks that may not
contribute to the analysis.
 Handling Special Characters: Removing or normalizing special characters or
symbols.
 Stopword Removal: Filtering out common words (stopwords) like "and", "the", "is"
that may not add significant meaning to the analysis.
 Stemming: Reducing words to their root form by removing prefixes or suffixes. For
example, "running" becomes "run".
 Lemmatization: Reducing words to their base or dictionary form, considering context
and meaning. For example, "better" becomes "good".
2. Part-of-Speech Tagging (POS)
Part-of-Speech (POS) tagging assigns grammatical categories to each token in a text. This helps
in understanding the syntactic structure and the role of each word.
 Types of Tags:

Compiled by: Er. Shaif Mehraj Makhdoomi. 24


Unit-IV: Artificial Intelligence 6th Semester

 Nouns: Represent people, places, things, or ideas (e.g., "cat", "city").


 Verbs: Represent actions or states (e.g., "run", "is").
 Adjectives: Describe or modify nouns (e.g., "beautiful", "quick").
 Adverbs: Modify verbs, adjectives, or other adverbs (e.g., "quickly", "very").
 Prepositions: Indicate relationships between words (e.g., "on", "in").
 Conjunctions: Connect words or phrases (e.g., "and", "but").
 Example: In the sentence "The cat sat on the mat":
 "The" (Determiner)
 "cat" (Noun)
 "sat" (Verb)
 "on" (Preposition)
 "the" (Determiner)
 "mat" (Noun)
3. Named Entity Recognition (NER)
NER identifies and classifies entities in text into predefined categories such as people,
organizations, locations, dates, and more. This phase is crucial for extracting structured
information from unstructured text.
 Types of Entities:
 Person: Names of people (e.g., "Barack Obama").
 Organization: Names of companies or institutions (e.g., "Microsoft").
 Location: Names of places (e.g., "New York").
 Date/Time: Dates and times (e.g., "January 1, 2023").
 Example: In the sentence "Apple Inc. is headquartered in Cupertino, California," NER
would identify:
 "Apple Inc." as an Organization
 "Cupertino" as a Location
 "California" as a Location
4. Parsing
Parsing analyzes the grammatical structure of a sentence to understand its syntactic and
semantic meaning. There are two main types:

Compiled by: Er. Shaif Mehraj Makhdoomi. 25


Unit-IV: Artificial Intelligence 6th Semester

 Dependency Parsing: Focuses on the relationships between words, identifying the


head of each word and its dependencies. It creates a tree structure showing how words
are related.
 Constituency Parsing: Breaks down a sentence into sub-phrases (constituents) and
shows their hierarchical relationships. It provides a tree structure that represents phrases
like noun phrases (NP) and verb phrases (VP).
 Example: For the sentence "She gave him a book," dependency parsing might reveal:
 "gave" is the main verb
 "She" is the subject
 "him" is the indirect object
 "a book" is the direct object
5. Semantic Analysis
Semantic analysis focuses on understanding the meaning and context of the text. It involves:
 Named Entity Disambiguation: Determining which specific entities are referred to in
the text based on context. For example, "Apple" could refer to the company or the fruit
depending on context.
 Word Sense Disambiguation: Identifying the correct meaning of a word with multiple
meanings based on its context. For example, "bank" can mean a financial institution or
the side of a river.
6. Sentiment Analysis
Sentiment analysis determines the emotional tone behind a piece of text, classifying it into
categories such as positive, negative, or neutral.
 Methods:
 Lexicon-Based: Uses predefined lists of words with associated sentiment
scores to determine the overall sentiment.
 Machine Learning-Based: Uses trained models to classify sentiment based on
features extracted from the text.
 Example: Analyzing the review "The movie was fantastic!" would classify it as
positive sentiment.
7. Text Classification
Text classification involves categorizing text into predefined classes or categories based on its
content.
 Types:
 Binary Classification: Categorizes text into two classes (e.g., spam vs. non-
spam).

Compiled by: Er. Shaif Mehraj Makhdoomi. 26


Unit-IV: Artificial Intelligence 6th Semester

 Multi-Class Classification: Categorizes text into multiple classes (e.g., news


topics like sports, politics, entertainment).
 Example: Classifying an email as either "spam" or "not spam" based on its
content.

8. Machine Translation
Machine translation automatically translates text from one language to another. It involves
several techniques:
 Rule-Based Translation: Uses linguistic rules and dictionaries.
 Statistical Machine Translation: Uses statistical models trained on bilingual corpora.
 Neural Machine Translation: Uses deep learning models, such as sequence-to-
sequence models, to generate translations.
 Example: Translating "Hello, how are you?" from English to French results in
"Bonjour, comment ça va ?".
9. Text Summarization
Text summarization aims to create a concise summary of a larger text while retaining its key
points.
 Extractive Summarization: Selects important sentences or phrases from the original
text to form a summary.
 Abstractive Summarization: Generates new sentences to convey the main ideas of the
original text, often using advanced neural network models.
 Example: Summarizing a news article about a new technology to highlight its key
features and impacts.
10. Speech Recognition and Synthesis
 Speech Recognition: Converts spoken language into text by processing audio signals.
It involves techniques such as acoustic modeling, language modeling, and decoding.
 Example: Converting the spoken sentence "I need a reservation" into text.
 Speech Synthesis: Generates spoken language from text, creating natural-sounding
speech using text-to-speech (TTS) systems. It involves techniques like concatenative
synthesis and neural TTS.
 Example: Converting the text "Welcome to our service" into spoken audio.
11. Information Retrieval and Extraction
Information retrieval involves retrieving relevant information from large datasets or documents
based on queries. Information extraction involves identifying and extracting specific pieces of
information.

Compiled by: Er. Shaif Mehraj Makhdoomi. 27


Unit-IV: Artificial Intelligence 6th Semester

 Information Retrieval: Includes search engines and systems that retrieve documents
or data based on user queries.
 Information Extraction: Identifies specific details such as dates, locations, or named
entities from text.
 Example: Extracting all mentions of "company names" from a set of business news
articles.
12. Dialogue Systems and Chatbots
Dialogue systems and chatbots are designed to interact with users through natural language,
providing responses or performing tasks based on user input.
 Types:
 Rule-Based Systems: Use predefined rules and patterns to generate responses.
 Retrieval-Based Systems: Select responses from a predefined set based on user
input.
 Generative Systems: Generate responses using advanced language models.
 Example: A customer support chatbot that can handle queries about account issues,
provide information, and assist with common problems.

CONSTRUCTING A PARSE TREE


Constructing a parse tree, also known as a syntax tree, involves creating a hierarchical
representation of a sentence's grammatical structure. The parse tree illustrates the syntactic
relationships between words and phrases in a sentence, showing how they combine to form a
coherent structure.
Here’s a detailed guide on constructing a parse tree:
1. Understand the Sentence Structure
Before constructing a parse tree, you need to understand the basic components of a sentence:
 Sentence (S): The entire structure that includes all words and phrases.
 Phrase Types:
 Noun Phrase (NP): Consists of a noun and its modifiers (e.g., "the cat").
 Verb Phrase (VP): Includes a verb and its complements (e.g., "sat on the mat").
 Prepositional Phrase (PP): Consists of a preposition and its object (e.g., "on
the mat").

2. Identify Parts of Speech

Compiled by: Er. Shaif Mehraj Makhdoomi. 28


Unit-IV: Artificial Intelligence 6th Semester

Assign parts of speech to each word in the sentence. This helps in understanding the
grammatical roles of each word.
Example Sentence: "The cat sat on the mat."

Parts of Speech:
 "The" (Determiner)
 "cat" (Noun)
 "sat" (Verb)
 "on" (Preposition)
 "the" (Determiner)
 "mat" (Noun)

3. Break Down the Sentence into Phrases


Identify and group words into phrases based on their grammatical roles:
 Noun Phrase (NP): "The cat" and "the mat"
 Verb Phrase (VP): "sat on the mat"
 Prepositional Phrase (PP): "on the mat"

4. Construct the Parse Tree


Construct the parse tree by creating nodes for each phrase and connecting them according to
their grammatical relationships.
Steps to Construct the Parse Tree:
1. Create the Root Node: Start with the root node labeled as Sentence (S).
2. Add Phrase Nodes: Add nodes for each major phrase type:
 Noun Phrase (NP): Add a node for "The cat."
 Verb Phrase (VP): Add a node for "sat on the mat."
 Prepositional Phrase (PP): Add a node for "on the mat."

3. Add Further Sub-Nodes: For each phrase node, add sub-nodes representing its
constituents:

Compiled by: Er. Shaif Mehraj Makhdoomi. 29


Unit-IV: Artificial Intelligence 6th Semester

 NP: "The" (Determiner) and "cat" (Noun)


 VP: "sat" (Verb) and a sub-node for PP
 PP: "on" (Preposition) and a sub-node for NP ("the mat")
 NP: "The" (Determiner) and "mat" (Noun)
4. Connect the Nodes: Draw lines (edges) to connect nodes according to their
grammatical relationships.
Example Parse Tree Construction:
1. Sentence (S)
 Noun Phrase (NP)
 "The" (Determiner)
 "cat" (Noun)
 Verb Phrase (VP)
 "sat" (Verb)
 Prepositional Phrase (PP)
 "on" (Preposition)
 Noun Phrase (NP)
 "The" (Determiner)
 "mat" (Noun)

NP VP

Det N V PP

The cat sat P NP

on Det N

The mat

Compiled by: Er. Shaif Mehraj Makhdoomi. 30


Unit-IV: Artificial Intelligence 6th Semester

Explanation of the Tree:


 Sentence (S): The root node representing the entire sentence.
 Noun Phrase (NP): "The cat" serves as the subject of the sentence.
 Det (Determiner): "The"
 N (Noun): "cat"
 Verb Phrase (VP): "sat on the mat" represents the action and its complement.
 V (Verb): "sat"
 Prepositional Phrase (PP): Provides additional information about the location.
 P (Preposition): "on"
 Noun Phrase (NP): "the mat" serves as the object of the preposition.
 Det (Determiner): "The"
 N (Noun): "mat"
TOKENIZING TEXT DATA
Detailed Explanation:
 Purpose: Tokenization transforms text into tokens, which are the basic units of analysis
in NLP. This step is crucial because most NLP algorithms and models operate on tokens
rather than raw text.
 Types:
 Word Tokenization: Splits text into words. Common libraries include NLTK’s
word_tokenize and SpaCy’s tokenizer.
 Sentence Tokenization: Splits text into sentences. Useful for tasks like text
summarization or sentiment analysis on a sentence level. Libraries such as
NLTK’s sent_tokenize or SpaCy can be used.
 Subword Tokenization: Divides words into smaller units, often used to handle
rare words or morphologically rich languages. Examples include Byte-Pair
Encoding (BPE) and SentencePiece.
 Challenges:
 Punctuation Handling: Deciding whether punctuation should be included in
tokens or treated separately.
 Multi-word Expressions: Handling phrases that are meaningful as a whole,
like "New York".
 Contractions and Special Characters: Dealing with contractions like "don’t"
and special characters, including emojis or hashtags in social media text.
WORD STEMMING

Compiled by: Er. Shaif Mehraj Makhdoomi. 31


Unit-IV: Artificial Intelligence 6th Semester

Detailed Explanation:
 Purpose: Stemming reduces words to their root form to standardize different word
forms to a common base. This simplification helps in reducing dimensionality and
improving the performance of NLP models.
 Algorithms:
 Porter Stemmer: Applies a set of rules to remove common English suffixes.
It’s simple but might sometimes produce non-standard word forms.
 Lancaster Stemmer: More aggressive than the Porter Stemmer, resulting in
more radical reductions.
 Snowball Stemmer: A more advanced stemmer that improves on the Porter
Stemmer by handling more suffixes.
 Example:
 Porter Stemmer: "running" -> "run", "better" -> "better" (doesn’t stem
comparative adjectives).
 Lancaster Stemmer: "running" -> "run", "better" -> "better" (similar to Porter).
 Limitations:
 Over-stemming: Where different words are reduced to the same stem even
though they have different meanings (e.g., "organ" and "organization" both stem
to "organ").
 Under-stemming: Where words that should be reduced to the same stem are
not (e.g., "run" and "running").

WORD LEMMATIZATION
Detailed Explanation:
 Purpose: Lemmatization provides the base form of words by considering their meaning
and context, which helps in preserving the semantic meaning of words.
 Process:
 Part-of-Speech Tagging: Identifies the grammatical role of a word (e.g., noun,
verb) to accurately determine its lemma.
 Lexicon Lookup: Uses a pre-defined dictionary (e.g., WordNet) to map words
to their lemmas.
 Example:
 Lemmatization: "am", "is", "are" all map to "be"; "running" maps to "run"
considering its context.
 Advantages:

Compiled by: Er. Shaif Mehraj Makhdoomi. 32


Unit-IV: Artificial Intelligence 6th Semester

 Context-Aware: Provides more accurate base forms by considering the context


and part of speech.
 Semantic Consistency: Ensures that different forms of a word (e.g., singular
and plural) are reduced to the same base form.
DIVIDING TEXT DATA INTO CHUNKS
Detailed Explanation:
 Purpose: Chunking extracts phrases or chunks from a sentence, facilitating the
identification of meaningful units for further processing, such as named entity
recognition or sentiment analysis.
 Types of Chunks:
 Noun Phrases (NP): Groups of words that function as a noun. For example,
"the big red balloon".
 Verb Phrases (VP): Consist of the main verb and its dependents. For example,
"has been running quickly".
 Prepositional Phrases (PP): Include a preposition and its object. For example,
"under the bed".
 Tools and Techniques:
 Rule-Based Methods: Use regular expressions and grammar rules to identify
chunks.
 Statistical Models: Use trained models to identify chunks based on
probabilities.
 Library Functions: Libraries like NLTK and SpaCy provide built-in functions
for chunking.

BAG OF WORDS (BOW)


Detailed Explanation:
 Purpose: BoW is a method for converting text into a numerical format by counting
word occurrences. This representation simplifies text data into a feature vector.
 Process:
 Tokenization: Break the text into individual words.
 Vocabulary Creation: Create a list of unique words (vocabulary) from the
entire dataset.
 Vector Construction: Represent each document as a vector where each
dimension corresponds to a word in the vocabulary, and the value represents the
word's frequency or presence.

Compiled by: Er. Shaif Mehraj Makhdoomi. 33


Unit-IV: Artificial Intelligence 6th Semester

 Example:
 For "I love programming" and "Programming is fun":
 Vocabulary: ["I", "love", "programming", "is", "fun"]
 BoW representation:
 "I love programming" -> [1, 1, 1, 0, 0]
 "Programming is fun" -> [0, 0, 1, 1, 1]
 Limitations:
 Loss of Context: Ignores the order of words and their context.
 High Dimensionality: Can result in very large feature vectors for large
vocabularies.
WORD2VEC
Detailed Explanation:
 Purpose: Word2Vec represents words in a continuous vector space where semantically
similar words are mapped to nearby points. This allows capturing semantic
relationships between words.
 Models:
 Continuous Bag of Words (CBOW): Predicts a target word from its context
words. For example, given the context "The cat on the", the model predicts
"mat".
 Skip-gram: Predicts context words given a target word. For example, given the
word "mat", the model predicts context words like "The", "cat", "on", "the".
 Process:
 Training: Uses a large corpus to learn vector representations. The model adjusts
word vectors based on their co-occurrence in the context.
 Vector Representation: Words are represented as dense vectors where similar
words have similar vector representations.
 Example:
 In a trained Word2Vec model, the vector for "king" minus "man" plus "woman"
is close to the vector for "queen".
 Advantages:
 Semantic Relationships: Captures the meaning and relationships between
words.
 Dimensionality Reduction: Provides dense vectors that are more compact
compared to BoW representations.

Compiled by: Er. Shaif Mehraj Makhdoomi. 34

You might also like