Ai Assignment 2 Answer
Ai Assignment 2 Answer
1. Consider the following Neural Network with the following input values,
weights, Bias Values, Target values
Given W2=0.20 w6=0.45
W3=0.25 w7=0.50
Input values W4=0.30 w8=0.55
X1=0.05 Bias Valuesb1=0.35 b2=0.60
X2=0.10
Target Values
Initial weight T1=0.01
W1=0.15 w5=0.40 T2=0.99
Required
Calculate the values of H1 and H2 by a forward pass. back-propagate this error to update the
weights using a backward pass, and perform a backward pass for the neural network?
Solution
H1 = x1*w1 + x2*w2 + b1
H1 = 0.05*0.15 + 0.10*0.20 + 0.35
H1 = 0.3775
H2=x1*w3+x2*w4+b1
H2=0.05*0.25+0.10*0.30+0.35
H2=0.3925
Now, we calculate the values of y1 and y2 in the same way as we calculate the H1 and H2.
To find the value of y1, we first multiply the input value i.e., the outcome of H1 and H2 from
the weights as
y1=H1*w5+H2*w6+b2
y1=0.593269992*0.40+0.596884378*0.45+0.60
y1=1.10590597
y2 = H1*w7 + H2*w8 + b2
y2 = 0.593269992 * 0.50 + 0.596884378 * 0.55 + 0.60
y2 = 1.2249214
Our target values are 0.01 and 0.99. Our y1 and y2 value is not matched
with our target values T1 and T2.
Now, we will find the total error, which is simply the difference between
the outputs from the target outputs. The total error is calculated as
Now, we calculate each term one by one to differentiate Etotal with respect
to w5 as
Putting the value of e-y in equation (5)
So, we put the values of in equation no (3) to find
the final result.
Now, we will calculate the updated weight w5 new with the help of the
following formula
In the same way, we calculate w6new,w7new, and w8new and this will give
us
w5new = 0.35891648
w6new = 408666186
w7new = 0.511301270
w8new = 0.561370121
Backward pass at Hidden layer
Now, we will backpropagate to our hidden layer and update the weight w1,
w2, w3, and w4 as we have done with w5, w6, w7, and w8 weights.
We will calculate the error at w1 as
From equation (2), it is clear that we cannot partially differentiate it with respect to w1
because there is no any w1. We split equation (1) into multiple terms so that we can
easily differentiate it with respect to w1 as
Now, we calculate each term one by one to differentiate Etotal with respect to w1
as
Now, we find the value of by putting values in equation (18) and (19)
as
From equation (18)
We calculate the partial derivative of the total net input to H1 with respect to w1
the same as we did for the output neuron:
Now, we will calculate the updated weight w1new with the help of the following
formula
In the same way, we calculate w2new,w3new, and w4 and this will give us the
following values
w1new=0.149780716
w2new=0.19956143
w3new=0.24975114
w4new=0.29950229
By update all the weights let’s found the error 0.298371109 on the network when
we fed forward the 0.05 and 0.1 inputs. In the first round of Back propagation, the
total error is down to 0.291027924.
After repeating this process 10,000, the total error is down to 0.0000351085. At
this point, the outputs neurons generate 0.159121960 and 0.984065734 i.e.,
nearby our target value when we feed forward the 0.05 and 0.1.
1. Morphology
2. N-Grams
2, Morphology
import spacy
from spacy.lang.en.examples import sentences
from spacy import displacy
nlp = spacy.load("en_core_web_sm")
print(f"Processed Sentence:\n{doc.text}\n")
print(f"{'Token':<12}{'Lemma':<12}{'POS':<10}{'Dependency':<15}{'Entity':<15}")
print("-" * 60)
for token in doc:
entity = token.ent_type_ if token.ent_type_ else "None"
print(f"{token.text:<12}{token.lemma_:<12}{token.pos_:<10}{token.dep_:<15}
{entity:<15}")
if doc.ents:
print("\nNamed Entities:")
for ent in doc.ents:
print(f"{ent.text:<20} ({ent.label_})")
else:
print("\nNo named entities found.")
Displays lemma (base form of the word) and entity type alongside POS and dependency
tags for richer insights.
Extracts and prints named entities (e.g., persons, organizations, dates) for better context
understanding.
Added display.render for both dependency parsing and named entities to provide
comprehensive visual analysis.
Handles sentences with or without named entities gracefully, ensuring user-friendly
feedback.
Aligns tabular output using string formatting for better readability