When creating a post, please add:
- Week # must be added in the tags option of the post.
- Link to the classroom item you are referring to:
- Description (include relevant info but please do not post solution code or your entire notebook)
Week -3
Exercise 4.2
Instructions
- Loop through the incoming data in batch_size chunks, you will again define a
tensorflow.data.Dataset
to do so. This time you don’t need the labels, so you can just replace them byNone
, - compute
v1
,v2
using the model output, - for each element of the batch - compute the cosine similarity of each pair of entries,
v1[j]
,v2[j]
- determine ifd > threshold
- increment accuracy if that result matches the expected results (y_test[j]
) Instead of running a for loop, you will vectorize all these operations to make things more efficient, - compute the final accuracy and confusion matrix and return. For the confusion matrix you can use the
tf.math.confusion_matrix
function.
Instructions seems like partially incorrect and confusing. All test cases fails. How to seek help?
Exercise 5
def predict(question1, question2, threshold, model, verbose=False):
“”"Function for predicting if two questions are duplicates.
Args:
question1 (str): First question.
question2 (str): Second question.
threshold (float): Desired threshold.
model (tensorflow.keras.Model): The Siamese model.
data_generator (function): Data generator function. Defaults to data_generator.
verbose (bool, optional): If the results should be printed out. Defaults to False.
There is no data generator argument
Comment says, call the predict method
Call the predict method of your model and save the output into v1v2
v1v2 = model((question1, question2))