ryankiros / skip-thoughts

Sent2Vec encoder and training code from the paper "Skip-Thought Vectors"
2.05k stars 543 forks source link

Type Error while training #67

Open liu115 opened 6 years ago

liu115 commented 6 years ago

I was training skip-thought model with my own data following the README in training directory. But I encountered TypeError and I'm not familiar with Theano, so I don't know how to do about it.

Here is my code,

# data = a list of strings
import vocab
worddict, wordcount = vocab.build_dictionary(data)
vocab.save_dictionary(worddict, wordcount, dict_filename)

import train
train.trainer(data)

Here is the runtime message,

{'grad_clip': 5.0, 'dim': 800, 'optimizer': 'adam', 'dim_word': 240, 'dictionary': './dict.txt', 'reload_': False, 'n_words': 5000, 'batch_size': 64, 'encoder': 'gru', 'maxlen_w': 30, 'saveto': './dialog.npz', 'decoder': 'gru', 'max_epochs': 5, 'dispFreq': 1, 'decay_c': 0.0, 'saveFreq': 1000}
Loading dictionary...
Building model
/home/extra/liu115/.local/lib/python2.7/site-packages/theano/scan_module/scan.py:1017: Warning: In the strict mode, all neccessary shared variables must be passed as a part of non_sequences
  'must be passed as a part of non_sequences', Warning)
Building f_log_probs... Done
Building f_cost... Done
Done
Building f_grad... Building optimizers...
Traceback (most recent call last):
  File "dialog.py", line 27, in <module>
    train.trainer(data)
  File "/tmp3/liu115/dialog/skip-thoughts/training/train.py", line 136, in trainer
    f_grad_shared, f_update = eval(optimizer)(lr, tparams, grads, inps, cost)
  File "/tmp3/liu115/dialog/skip-thoughts/training/optim.py", line 40, in adam
    f_update = theano.function([lr], [], updates=updates, on_unused_input='ignore', profile=False)
  File "/home/extra/liu115/.local/lib/python2.7/site-packages/theano/compile/function.py", line 266, in function
    profile=profile)
  File "/home/extra/liu115/.local/lib/python2.7/site-packages/theano/compile/pfunc.py", line 489, in pfunc
    no_default_updates=no_default_updates)
  File "/home/extra/liu115/.local/lib/python2.7/site-packages/theano/compile/pfunc.py", line 217, in rebuild_collect_shared
    raise TypeError(err_msg, err_sug)
TypeError: ('An update must have the same type as the original shared variable (shared_var=<TensorType(float32, matrix)>, shared_var.type=TensorType(float32, matrix), update_val=Elemwise{add,no_inplace}.0, update_val.type=TensorType(float64, matrix)).', 'If the difference is related to the broadcast pattern, you can call the tensor.unbroadcast(var, axis_to_unbroadcast[, ...]) function to remove broadcastable dimensions.')

By the way, I was using utf-8 strings as vocabularies. Is there anything that I should be carefully about? Thanks for helping.

HappyCoderMan commented 6 years ago

That type error should be fixable if you add this to your THEANO_FLAGS or .theanorc file: floatX=float32