NTMC-Community / MatchZoo

Facilitating the design, comparison and sharing of deep text matching models.
Apache License 2.0
3.82k stars 898 forks source link

CDSSM model doesnt work #800

Open tramya28 opened 4 years ago

tramya28 commented 4 years ago

Describe the Question

I was trying to implement the CDSSM model with the toy dataset provided and I get the following error. image Also the word hashing (preprocessing) is consuming a lot of memory. Is there a hack around to have less memory usage and have word hashing?

I followed the tutorials in the Matchzoo and used the code of CDSSM from wikiqa (https://github.com/NTMC-Community/MatchZoo/tree/master/tutorials/wikiqa)

P.S - I played around with other models like knrm, convknrm, dssm, arcII, duet and mvlstm and they all worked. I only have issue with the CDSSM model. I followed the tutorials for all the other models as well.

uduse commented 4 years ago

481 may help with your memory issue.

tramya28 commented 4 years ago

I figured out that i can use "with_word_hashing=False" for large datasets, but if i want to use word hashing then it is not possible with large datasets right? Please confirm. Also the CDSSM model doesnt work irrespective of word hashing set to false. Please let me know if there is a fix! Thanks

uduse commented 4 years ago

Word hashing takes a lot of space. Unless you have HUGE memory in your computer, it's not possible to do it as a part of the preprocessing process.

What do you mean by "CDSSM doesn't work"?

tramya28 commented 4 years ago

This is the error i get when i use the same code provided in the tutorials and using the dataset given the tutorial.

cdssmpng

matthew-z commented 4 years ago

did you run the wikiqa/cdssm ipynb?

I could not reproduce this error with matchzoo 2.2.

did you modify the notebook?

I think this error means that the labels are not in the correct form

matthew-z commented 4 years ago

ranking_task = mz.tasks.Classification(num_classes=2)

This is why you failed. You loaded the ranking dataset, but set the task to classification.

tramya28 commented 4 years ago

This is the code that i used for the CDSSM model.

import keras import pandas as pd import numpy as np import matchzoo as mz import json print('matchzoo version', mz.version) print()

print('data loading ...') train_pack_raw = mz.datasets.wiki_qa.load_data('train', task='ranking') dev_pack_raw = mz.datasets.wiki_qa.load_data('dev', task='ranking', filtered=True) test_pack_raw = mz.datasets.wiki_qa.load_data('test', task='ranking', filtered=True) print('data loaded as train_pack_raw dev_pack_raw test_pack_raw')

preprocessor = mz.preprocessors.CDSSMPreprocessor(fixed_length_left=10, fixed_length_right=10)

train_processed = preprocessor.fit_transform(train_pack_raw) valid_processed = preprocessor.transform(dev_pack_raw) test_processed = preprocessor.transform(test_pack_raw)

model = mz.models.CDSSM() model.params['input_shapes'] = preprocessor.context['input_shapes'] model.params['filters'] = 64 model.params['kernel_size'] = 3 model.params['strides'] = 1 model.params['padding'] = 'same' model.params['conv_activation_func'] = 'tanh' model.params['w_initializer'] = 'glorot_normal' model.params['b_initializer'] = 'zeros' model.params['mlp_num_layers'] = 1 model.params['mlp_num_units'] = 64 model.params['mlp_num_fan_out'] = 64 model.params['mlp_activation_func'] = 'tanh' model.params['dropout_rate'] = 0.8 model.params['optimizer'] = 'adadelta' model.guess_and_fill_missing_params() model.build() model.compile() model.backend.summary()

pred_x, pred_y = train_processed[:].unpack() evaluate = mz.callbacks.EvaluateAllMetrics(model, x=pred_x, y=pred_y, batch_size=len(pred_x)) train_generator = mz.DataGenerator(train_processed, batch_size=20, mode='pair', num_dup=2, num_neg=1, ) print('num batches:', len(train_generator))

history = model.fit_generator(train_generator, epochs=20, callbacks=[evaluate], workers=1, use_multiprocessing=False)

print("done")

and i get this error image

matthew-z commented 4 years ago

Your matchzoo is outdated. Please upgrade it.

Matchzoo 2.1 does not work with keras 2.3.1

tramya28 commented 4 years ago

Can i clone the latest version from github? when i do a pip install, its installing an older version of match zoo. Please let me know. Thanks

matthew-z commented 4 years ago

did you install matchzoo with this command? pip install -U matchzoo

could you show us the log?