Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Task 2 b - More understanding of Semantic Matching ( 1 5 points ) . Which terms does LSI find similar? To understand why the
Task b More understanding of Semantic Matching points
Which terms does LSI find similar?
To understand why the LSIexpanded vectors get the results they do we're going to look at what the operator
U
does to text. In particular, the termterm matrix
U
U
T
tells us the term expansion behavior of this LSI model. Think of the termterm matrix like an operator that first maps a term to the latent space
L
k
using
U
then back again from
L
k
to term space using
U
transpose The
i
j
entry of
U
U
T
is a kind of association weight between term
i
and term
j
Write a function to get the most related terms according to LSI for the word "economy". To do this:
Compute the termterm matrix from the matrix U the reducedtermmatrix variable
Use the termterm matrix to get the association weights of all words related to the term "economy"
Sort by descending weight value.
Your function should return the top words and their weights as a list of string float tuples.
Do the related terms match your subjective similarity judgment?
TOC
In :
Grade cell: cellcbfScore: Top
# Please tell me more!
taskid b
In :
Student's answerTop
def answersemanticsimilarityb:
result None
# YOUR CODE HERE
term "economy"
termindex tfidfvectorizer.vocabularyterm
#calc term matrix
termtermmatrix reducedtermmatrix @reducedtermmatrix.T
#get the associated weights of the term
relatedtermsweights termtermmatrixtermindex
#get the top related terms
topindices relatedtermsweights.argsort:::
topterms tfidffeaturenamesi relatedtermsweightsi for i in topindices
return topterms
#raise NotImplementedError
return result
In :
# use this cell to explore your solution
# remember to comment the function call before submitting the notebook
# answersemanticsimilarityb
In :
Grade cell: cellddbcScore: Top
printfTask taskid AG tests"
stuans answersemanticsimilarityb
printfTask taskid your answer:
stuans
assert isinstancestuans, list fTask taskid: Your function should return a list.
assert lenstuans fTask taskid: Your list should contain five elements the term, score tuples
for i item in enumeratestuans:
assert isinstanceitem tuple fTask taskid: Your answer at index i should be a tuple.
assert isinstance
item str
fTask taskid: The first element of your tuple at index i should be a string.
assert isinstance
itemfloat npfloating
fTask taskid: The second element of your tuple at index i should be a float.
# Some hidden tests
del stuans
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started