ninglab / Modof

The implementation of Modof for Molecule Optimization
Other
27 stars 10 forks source link

generating the same smiles as original smiles #4

Open liang2508 opened 1 year ago

liang2508 commented 1 year ago

Hi,

Thank you for sharing this code, it is really nice job. I was trying to train a model according to datasets in /data/logp06. I performed 100 epochs training process but the loss values didn't decrease and still remain 31.95. I am not sure if this is right. Anyway, I tried to optimized some molecules based on the trained model. But the generated smiles are the same as the original smiles and I don't know the reason. Have u met this problem?

Your help would be really appreciated. Thank you

ziqi92 commented 1 year ago

Hi,

Thank you for your interest in our work!

Could you please provide the command you used to train and test the model? I just tried the following command to test our trained model and found it works well for logp06.

python ./model/optimize.py --test ./data/logp06/test.txt --vocab ./data/logp06/vocab.txt --model ./experiments/logp/model.iter-7 --save_dir ./experiments/ --hidden_size 128 --latent_size 16 --depthT 3 --depthG 4 --iternum 5 --num 10 -s 0.6

Best, Ziqi

liang2508 commented 1 year ago

Hi,

Thanks for your reply. the commands used for data preprocessing, training and optimizing are as followings:

  1. data processing: python ./data_preprocessing/preprocess.py --train ./data/logp06/train_pairs.txt --output new_tensors --batch_size 10000 --batch_id 0 python ./data_preprocessing/preprocess.py --train ./data/logp06/train_pairs.txt --output new_tensors --batch_size 10000 --batch_id 1 python ./data_preprocessing/preprocess.py --train ./data/logp06/train_pairs.txt --output new_tensors --batch_size 10000 --batch_id 2 ... python ./model/mol_tree.py --train ./data/logp06/ --out ./data/logp06/vocab.txt
  2. training: python ./model/train.py --depthT 3 --depthG 5 --hidden_size 64 --latent_size 8 --add_ds --beta 0.1 --warmup 2000 --beta_anneal_iter 500 --step_beta 0.05 --max_beta 0.5 --save_iter 3000 --print_iter 20 --epoch 100 --train ./data/logp06/ --vocab ./data/logp06/vocab.txt --save_dir ./result (during the training process, the loss values didn't decrease and still remain 31.95. I am not sure if this is right)
  3. optimizing: python ./model/optimize.py --test ./data/logp06/test.txt --vocab ./data/logp06/vocab.txt --model ./result/model.iter-21000 --save_dir test_result --hidden_size 64 --latent_size 8 --depthT 3 --depthG 5 --iternum 5 --num 20 -s 0.6 (the problem is that generated smiles are the same as original smiles)
ziqi92 commented 1 year ago

Hi,

I just tried all the commands you provided and could not find any problems. The loss values decreased with our provided processed datasets and also the datasets processed by your provided commands. Below is an example of the training log for Modof I just got,

Screen Shot 2023-01-12 at 1 56 33 PM

I have no idea why your training loss didn't decrease. I wonder whether you could try your training command with our provided processed dataset and vocabulary as below.

python ./model/train.py --depthT 3 --depthG 5 --hidden_size 64 --latent_size 8 --add_ds --beta 0.1 --warmup 2000 --beta_anneal_iter 500 --step_beta 0.05 --max_beta 0.5 --save_iter 3000 --print_iter 20 --epoch 100 --train ./data/logp06/ --vocab ./data/logp06/vocab.txt --save_dir ./result

Our processed datasets are zipped in data/logp06, please unzip them before the training. Also, please let me know if the loss still cannot decrease.

Best, Ziqi

liang2508 commented 1 year ago

Hi,

I have used your processed zipped datasets in data/logp06 and run _python ./model/train.py --depthT 3 --depthG 5 --hidden_size 64 --latent_size 8 --add_ds --beta 0.1 --warmup 2000 --beta_anneal_iter 500 --step_beta 0.05 --max_beta 0.5 --save_iter 3000 --print_iter 20 --epoch 100 --train ./data/logp06/ --vocab ./data/logp06/vocab.txt --savedir ./result
then I got, image (Now this model is trained at epoch 17 but the loss values is still around 29. This is interesting. Is it the reason that we train this model in different machine? I am not sure, I guess it's not possible due to the big difference)

ziqi92 commented 1 year ago

Hi,

I don't think different machines could be the reason. I checked your log and noticed that your KL loss values are very small (around 0.3) compared with my KL loss values. Could you please check the beta value here (https://github.com/ninglab/Modof/blob/23d212bc69a57ee70666c1c56e29cb32288726d8/model/molopt.py#L127)? I guess the problem could be the large weight for KL loss values.

Best, Ziqi

liang2508 commented 1 year ago

Hi,

Do you mean change the beta value? The loss value still remain around 29 since I tried to change beta value to reduce the weight for KL loss value

ziqi92 commented 1 year ago

Hi,

Yes. I think you can change the beta value for KL loss. I don't know why my initial beta value 0.1 doesn't work for you. Could you please provide the beta values you have tried? Did you always observe that the loss values didn't decrease and remained around 29, no matter what the beta values are (e.g., with smaller initial beta values such as 0.01 or 0.05)?

Best, Ziqi

liang2508 commented 1 year ago

Hi,

I did tried different beta values such 0.05, 0.04, 0.01, 0.005, 0.001, but the loss remained around 29. I don't know why, either

ziqi92 commented 1 year ago

Hi,

Typically, with a smaller beta value such as 0.001, we should observe the different overall loss values and very large KL loss values as below,

Screen Shot 2023-01-17 at 11 31 33 AM

But even with smaller beta values, I found that the overall loss should also decrease as shown in the figure above. Did you modify the code or change the dataset?

I just double-checked your log, and found that your GNorm is 0.00, which indicates that the gradients used to update your model are 0, and thus your model is not trained. The GNorms in our log are always non-zero values. I would suggest you double-check the code and make sure the code for optimizer and backward pass is not deleted and correct.

Best, Ziqi

liang2508 commented 1 year ago

Hi,

Sorry to reply to you so late. Thank you for your reminder. I indeed modified the code. When I run train.py at the first time, one error below occured: image I find the answer to this error on the Internet and I added _total_loss = totalloss.detach().requiresgrad(True)_ before _totalloss.backward() in the train.py, then the code can run successfully.

So is it the reason? I am confused.

Thanks for your reply. Best, Li

liang2508 commented 1 year ago

Hi,

I have changed the Pytorch version to 1.5.1, and the training code can run successfully without any change. ![Uploading image.png…]() I run the optimizer.py after training model and got optimized molecules based on provided test.txt. But it seems that this trained model only gives the best optimized molecule for each original molecule, and how can I get multiple optimized molecules for each original molecule?

ziqi92 commented 1 year ago

Hi,

Glad to hear it! Just for your information, the code also ran successfully on my local environment with pytorch version 1.9.1.

In terms of optimized molecules, you can find the other optimized molecules from the intermediate files in each iteration such as "*-iter[0-N].txt". Please note that the optimization results with "optimize.py" file could not be diverse enough, as only the single best molecule will be selected for further modification. To alleviate this issue, you can try "optimize1.py" file to send multiple best molecules with good properties to the next iterations for further modification.

Best, Ziqi