You somehow mixed up two code lines
-
Check if d>threshold to make predictions
Here you were only suppose to check if cosine similarity is greater than threshold but you ended up adding the accuracy part of the code to this code line. Also do not hard code the path by introducing res = d > threshold (I KNOW THE HINT FROM PREVIOUS CELLS TELLS YOU TO DO SO.
INSTEAD OF y_test == res, you only need to use tf.cast(d>threshold with the datatype). -
Next your accuracy code is incorrect
take the average of correct predictions to get the accuracy
accuracy = tf.math.reduce_mean(y_pred)
You need to use tf.reduce_mean to the tf.cast when your actual target is absolute equal to the prediction with the datatype.
Regards
DP