Question: Create a tensorflow.data.Dataset from your two questions. Again, labels are not important, so you simply write None ( this is completed for you ) ,
Create a tensorflow.data.Dataset from your two questions. Again, labels are not important, so you simply write None this is completed for you
use the trained model output to extract v vsimilar to Exercise
compute the cosine similarity dot product of v vsimilarly to Exercise
compute res the decision if questions are duplicate or not by comparing d to the threshold.
Replace all "None" instances with correct vaiables!
def predictquestion question threshold, model, verboseFalse:
Function for predicting if two questions are duplicates.
Args:
questionstr: First question.
questionstr: Second question.
threshold float: Desired threshold.
model tensorflowkeras.Model: The Siamese model.
datagenerator function: Data generator function. Defaults to datagenerator.
verbose bool optional: If the results should be printed out. Defaults to False.
Returns:
bool: True if the questions are duplicates, False otherwise.
generator tfdata.Dataset.fromtensorslicesquestionquestionNonebatchbatchsize
### START CODE HERE ###
# Call the predict method of your model and save the output into vv
vv None
# Extract v and v from the model output
v None
v None
# Take the dot product to compute cos similarity of each pair of entries, v v
# Since v and v are both vectors, use the function tfmath.reducesum instead of tflinalg.matmul
d None
# Is d greater than the threshold?
res None
### END CODE HERE ###
ifverbose:
printQ question
Q question
printd dnumpy
printres res.numpy
return res.numpy
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
