NTMC-Community / MatchZoo

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

error about matchpyramid on wikiqa #69

Closed ckqsars closed 6 years ago

ckqsars commented 6 years ago

I have succeeded train with model drmm. However when I want to use matchpyramid to train the model, it reply the error

/DynamicMaxPooling.py:37: RuntimeWarning: divide by zero encountered in divide stride2 = 1.0 max_len2 / len2_one py:36: RuntimeWarning: divide by zero encountered in divide stride1 = 1.0 max_len1 / len1_one

I know the means of the error, but how should i do for it

Thank you

thiziri commented 6 years ago

What's the configuration that you use in the .config file for MatchPyramid, check the parameters: text1_maxlen and text2_maxlen.

ckqsars commented 6 years ago

The code I use is 'python matchzoo/main.py --phase train --model_file examples/wikiqa/config/matchpyramid_wikiqa.config' the configuration is your matchpyamid_wikiqa.config

and I record the 'max_len1 len1_one max2_len len2_one' and I found this record max_len1,len1_one,max2_len,len2_one, 10,6,40,0 the one of the text2 length is zeros. Is this data cause the error?

thiziri commented 6 years ago

text1_maxlen and text2_maxlen should give the maximum length of text1 and text2 respectively, so they must be different from 0

bwanglzu commented 6 years ago

Possibly a bug, need someone to look into this.

bwanglzu commented 6 years ago

@ckqsars @thiziri Maybe it's a good point to contribute some code to MatchZoo :) to handle ZeroDivisionError.

aneesh-joshi commented 6 years ago

Having the same problem @bwanglzu I would be happy to fix it. How should it be handled?

I am not sure how the script works fine otherwise. I got all my outputs but with this warning. If you could point me in the right direction, it would be great.

I paste my logs below (the error lines are in the end)

$ python matchzoo/main.py --phase predict --model_file examples/wikiqa/config/matchpyramid_wikiqa.config
Using TensorFlow backend.
2018-05-27 17:35:13.242733: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
{
  "net_name": "MatchPyramid",
  "global": {
    "model_type": "PY",
    "weights_file": "examples/wikiqa/weights/matchpyramid.wikiqa.weights",
    "save_weights_iters": 10,
    "num_iters": 400,
    "display_interval": 10,
    "test_weights_iters": 400,
    "optimizer": "adadelta",
    "learning_rate": 0.0001
  },
  "inputs": {
    "share": {
      "text1_corpus": "./data/WikiQA/corpus_preprocessed.txt",
      "text2_corpus": "./data/WikiQA/corpus_preprocessed.txt",
      "use_dpool": true,
      "embed_size": 300,
      "embed_path": "./data/WikiQA/embed_glove_d300_norm",
      "vocab_size": 18670,
      "train_embed": true,
      "target_mode": "ranking",
      "text1_maxlen": 10,
      "text2_maxlen": 40
    },
    "train": {
      "input_type": "PairGenerator",
      "phase": "TRAIN",
      "use_iter": false,
      "query_per_iter": 50,
      "batch_per_iter": 5,
      "batch_size": 100,
      "relation_file": "./data/WikiQA/relation_train.txt"
    },
    "valid": {
      "input_type": "ListGenerator",
      "phase": "EVAL",
      "batch_list": 10,
      "relation_file": "./data/WikiQA/relation_valid.txt"
    },
    "test": {
      "input_type": "ListGenerator",
      "phase": "EVAL",
      "batch_list": 10,
      "relation_file": "./data/WikiQA/relation_test.txt"
    },
    "predict": {
      "input_type": "ListGenerator",
      "phase": "PREDICT",
      "batch_list": 10,
      "relation_file": "./data/WikiQA/relation_test.txt"
    }
  },
  "outputs": {
    "predict": {
      "save_format": "TREC",
      "save_path": "predict.test.wikiqa.txt"
    }
  },
  "model": {
    "model_path": "./matchzoo/models/",
    "model_py": "matchpyramid.MatchPyramid",
    "setting": {
      "kernel_count": 64,
      "kernel_size": [
        3,
        3
      ],
      "dpool_size": [
        3,
        10
      ],
      "dropout_rate": 0.95
    }
  },
  "losses": [
    {
      "object_name": "rank_hinge_loss",
      "object_params": {
        "margin": 1.0
      }
    }
  ],
  "metrics": [
    "ndcg@3",
    "ndcg@5",
    "map"
  ]
}
[./data/WikiQA/embed_glove_d300_norm]
        Embedding size: 18670
Generate numpy embed: %s (18670, 300)
[Embedding] Embedding Load Done.
[Input] Process Input Tags. odict_keys(['predict']) in PREDICT.
[./data/WikiQA/corpus_preprocessed.txt]
        Data size: 24106
[Dataset] 1 Dataset Load Done.
{'text1_corpus': './data/WikiQA/corpus_preprocessed.txt', 'text2_corpus': './data/WikiQA/corpus_preprocessed.txt', 'use_dpool': True, 'embed_size': 300, 'embed_path': './data/WikiQA/embed_glove_d300_norm', 'vocab_size': 18670, 'train_embed': True, 'target_mode': 'ranking', 'text1_maxlen': 10, 'text2_maxlen': 40, 'embed': array([[-0.015813, -0.030727,  0.071415, ..., -0.05767 , -0.006848,
         0.072159],
       [ 0.014287,  0.051543, -0.019644, ..., -0.000331,  0.031015,
        -0.145481],
       [ 0.061419,  0.016787, -0.00883 , ...,  0.158453, -0.049464,
        -0.071066],
       ...,
       [-0.0507  ,  0.116266,  0.09943 , ..., -0.089696, -0.071486,
        -0.029069],
       [-0.007663, -0.074661, -0.023721, ...,  0.032474,  0.015744,
         0.050838],
       [ 0.      ,  0.      ,  0.      , ...,  0.      ,  0.      ,
         0.      ]], dtype=float32), 'input_type': 'ListGenerator', 'phase': 'PREDICT', 'batch_list': 10, 'relation_file': './data/WikiQA/relation_test.txt'}
[./data/WikiQA/relation_test.txt]
        Instance size: 2341
List Instance Count: 237
[ListGenerator] init done
[MatchPyramid] init done
[layer]: Input  [shape]: [None, 10]
 [Memory] Total Memory Use: 397.9453 MB          Resident: 407496 Shared: 0 UnshareData: 0 UnshareStack: 0
[layer]: Input  [shape]: [None, 40]
 [Memory] Total Memory Use: 397.9453 MB          Resident: 407496 Shared: 0 UnshareData: 0 UnshareStack: 0
[layer]: Input  [shape]: [None, 10, 40, 3]
 [Memory] Total Memory Use: 397.9453 MB          Resident: 407496 Shared: 0 UnshareData: 0 UnshareStack: 0
[layer]: Embedding      [shape]: [None, 10, 300]
 [Memory] Total Memory Use: 439.8203 MB          Resident: 450376 Shared: 0 UnshareData: 0 UnshareStack: 0
[layer]: Embedding      [shape]: [None, 40, 300]
 [Memory] Total Memory Use: 439.8203 MB          Resident: 450376 Shared: 0 UnshareData: 0 UnshareStack: 0
[layer]: Dot    [shape]: [None, 10, 40]
 [Memory] Total Memory Use: 439.8203 MB          Resident: 450376 Shared: 0 UnshareData: 0 UnshareStack: 0
[layer]: Reshape        [shape]: [None, 10, 40, 1]
 [Memory] Total Memory Use: 439.8203 MB          Resident: 450376 Shared: 0 UnshareData: 0 UnshareStack: 0
[layer]: Conv2D [shape]: [None, 10, 40, 64]
 [Memory] Total Memory Use: 439.8203 MB          Resident: 450376 Shared: 0 UnshareData: 0 UnshareStack: 0
[layer]: DynamicMaxPooling      [shape]: [None, 3, 10, 64]
 [Memory] Total Memory Use: 439.8203 MB          Resident: 450376 Shared: 0 UnshareData: 0 UnshareStack: 0
[layer]: Flatten        [shape]: [None, None]
 [Memory] Total Memory Use: 439.8203 MB          Resident: 450376 Shared: 0 UnshareData: 0 UnshareStack: 0
[layer]: Dropout        [shape]: [None, None]
 [Memory] Total Memory Use: 439.8203 MB          Resident: 450376 Shared: 0 UnshareData: 0 UnshareStack: 0
[layer]: Dense  [shape]: [None, 1]
 [Memory] Total Memory Use: 439.8203 MB          Resident: 450376 Shared: 0 UnshareData: 0 UnshareStack: 0
/mnt/d/Projects/NewMactch/MatchZoo/matchzoo/layers/DynamicMaxPooling.py:37: RuntimeWarning: divide by zero encountered in true_divide
  stride2 = 1.0 * max_len2 / len2_one
/mnt/d/Projects/NewMactch/MatchZoo/matchzoo/layers/DynamicMaxPooling.py:36: RuntimeWarning: divide by zero encountered in true_divide
  stride1 = 1.0 * max_len1 / len1_one
[05-27-2018 17:35:16]   [Predict] @ predict [Predict] results:  map=0.642877    ndcg@1=0.476793 ndcg@3=0.640863 ndcg@5=0.685916 ndcg@10=0.725052        ndcg@20=0.732838
bwanglzu commented 6 years ago

@ckqsars This will be solved in #140, we'll merge it by tomorrow.

bwanglzu commented 6 years ago

@ckqsars #140 has been merged into master, can you update your code to the latest version and try again? Best :)

ckqsars commented 6 years ago

@bwanglzu OK thank you very much :)

bwanglzu commented 6 years ago

I'll close this issue for now, if you have further questions please feel free to re-open it or create a new issue. Best!