nfmcclure / tensorflow_cookbook

Code for Tensorflow Machine Learning Cookbook
https://www.packtpub.com/big-data-and-business-intelligence/tensorflow-machine-learning-cookbook-second-edition
MIT License
6.25k stars 2.41k forks source link

Siamese RNN - target values and model configuration #83

Closed MikolajSedek closed 7 years ago

MikolajSedek commented 7 years ago

Hi Nick, get_bach function in 06_siamese_similarity_driver.ipynb generates data with targets -1 or 1, however the loss function in siamese_similarity_model.py seems to be configured to work with targets 0 or 1:

If y-target is -1 to 1, then do the following

pos_mult = tf.add(tf.multiply(0.5, y_target), 0.5)

Else if y-target is 0 to 1, then do the following

pos_mult = tf.cast(y_target, tf.float32)

This part of code also remains commented:

Change targets from (0,1) --> (-1, 1)

via (2 * x - 1)

y_target_int = tf.sub(tf.mul(y_target_int, 2), 1)

I wonder if I should change the loss function if I want to run this model on my data with target -1/1. Best regards!

nfmcclure commented 7 years ago

Hi @MikolajSedek , Thanks for noticing this. I missed this because the model trains fairly well just by learning on the positive examples. The code has been updated. Please repull and check if you want. Sorry about the late reply, I only get a chance to work on this project about once a month. I'm going to close this issue and please reopen if it isn't fixed on your end.