nusnlp / mlconvgec2018

Code and model files for the paper: "A Multilayer Convolutional Encoder-Decoder Neural Network for Grammatical Error Correction" (AAAI-18).
GNU General Public License v3.0
185 stars 73 forks source link

TypeError: iter() returned non-iterator of type 'NBestList' #20

Closed young-zonglin closed 5 years ago

young-zonglin commented 5 years ago

Hi, I have encountered a type error when I run run_trained_model.sh with EO reranker, the error message is as follows: Traceback (most recent call last): File "/mnt/yangzonglin-gec/projects/mlconvgec2018/software/nbest-reranker/rerank.py", line 59, in <module> for group in input_aug_nbest: TypeError: iter() returned non-iterator of type 'NBestList' Screenshot from 2019-03-11 11-13-37

I also noticed that the train_reranker.sh script printed a lot of messages, saying: Levenshtein distance is greater than source size. Screenshot from 2019-03-11 11-16-02

shamilcm commented 5 years ago

The first error is something which I never encountered. I suspect it has got to do with the language you are dealing with. Are you using English outputs or any other language? I have only tested the nbest reranker on English. Can you send your nbest list (before and after augmentation)? It is weird that augmentation step on the nbest list seems to have no issues but reranker causes a problem. Did you try training the weights of the reranker successfully?

Regarding Levenshtein distance, the M2 implementation in Moses skips sentence pairs that are too different in terms of length due to efficiency reasons during training.

young-zonglin commented 5 years ago

Hi, thank you for your reply firstly. Actually I am using rescoring mechanism in Chinese GEC task. The nbest list before augmentation(${output_dir}/output.tok.nbest.reformat.txt) is as follows:

0 |||  冬阴功 是 泰国 最 著名 的 菜 之一 , 它 虽然 不是 很 豪华 , 但 它 的 味 确实 让 人 上瘾 , 做法 也 不难 、 不 复杂 。 ||| F0= -0.04735666885972023 ||| -0.04735666885972023
0 |||  冬阴功 是 泰国 最 著名 的 菜 之一 , 它 虽然 不是 很 豪华 , 但 它 的 味道 确实 让 人 上瘾 , 做法 也 不难 、 不 复杂 。 ||| F0= -0.06592220067977905 ||| -0.06592220067977905
0 |||  冬阴功 是 泰国 最 著名 的 菜 之一 , 它 虽然 不是 很 豪华 , 但 它 确实 让 人 上瘾 , 做法 也 不难 、 不 复杂 。 ||| F0= -0.1047820895910263 ||| -0.1047820895910263
0 |||  冬阴功 是 泰国 最 著名 的 菜 之一 , 它 虽然 不是 很 豪华 , 但 它 的 味 确实 让 人 上瘾 , 做法 也 不难 , 不 复杂 。 ||| F0= -0.1169404685497284 ||| -0.1169404685497284
0 |||  冬阴功 是 泰国 最 著名 的 菜 之一 , 它 虽然 不是 很 豪华 , 但 它 的 口味 确实 让 人 上瘾 , 做法 也 不难 、 不 复杂 。 ||| F0= -0.12856733798980713 ||| -0.12856733798980713
0 |||  冬阴功 是 泰国 最 著名 的 菜 之一 , 它 虽然 不是 很 豪华 , 但 它 的 味道 确实 让 人 上瘾 , 做法 也 不难 , 不 复杂 。 ||| F0= -0.13551054894924164 ||| -0.13551054894924164
0 ||| 冬阴功 是 泰国 最 著名 的 菜 之一 , 它 虽然 不是 很 豪华 , 但 它 的 味 确实 让 人 上瘾 , 做法 也 不难 、 不 复杂 。 ||| F0= -0.13648469746112823 ||| -0.13648469746112823
0 ||| “ 冬阴功 ” 是 泰国 最 著名 的 菜 之一 , 它 虽然 不是 很 豪华 , 但 它 的 味 确实 让 人 上瘾 , 做法 也 不难 、 不 复杂 。 ||| F0= -0.14135058224201202 ||| -0.14135058224201202
0 |||  冬阴功 是 泰国 最 著名 的 菜 之一 , 它 虽然 不是 很 豪华 , 但 它 的 味儿 确实 让 人 上瘾 , 做法 也 不难 、 不 复杂 。 ||| F0= -0.143321692943573 ||| -0.143321692943573
0 |||  冬阴功 是 泰国 最 著名 的 菜 之一 , 它 虽然 不是 很 豪华 , 但 它 的 香味 确实 让 人 上瘾 , 做法 也 不难 、 不 复杂 。 ||| F0= -0.143504798412323 ||| -0.143504798412323
0 |||  冬阴功 是 泰国 最 著名 的 菜 之一 , 虽然 它 不是 很 豪华 , 但 它 的 味 确实 让 人 上瘾 , 做法 也 不难 、 不 复杂 。 ||| F0= -0.14606299996376038 ||| -0.14606299996376038
0 |||  冬阴功 是 泰国 最 著名 的 菜 之一 , 它 虽然 不是 很 奢华 , 但 它 的 味 确实 让 人 上瘾 , 做法 也 不难 、 不 复杂 。 ||| F0= -0.14855249226093292 ||| -0.14855249226093292

The nbest list after augmentation(${output_dir}/output.tok.nbest.reformat.augmented.txt) is as follows:

0 |||  冬阴功 是 泰国 最 著名 的 菜 之一 , 它 虽然 不是 很 豪华 , 但 它 的 味 确实 让 人 上瘾 , 做法 也 不难 、 不 复杂 。 ||| F0= -0.04735666885972023 EditOps0= 0 0 0   ||| -0.04735666885972023
0 |||  冬阴功 是 泰国 最 著名 的 菜 之一 , 它 虽然 不是 很 豪华 , 但 它 的 味道 确实 让 人 上瘾 , 做法 也 不难 、 不 复杂 。 ||| F0= -0.06592220067977905 EditOps0= 0 0 1   ||| -0.06592220067977905
0 |||  冬阴功 是 泰国 最 著名 的 菜 之一 , 它 虽然 不是 很 豪华 , 但 它 确实 让 人 上瘾 , 做法 也 不难 、 不 复杂 。 ||| F0= -0.1047820895910263 EditOps0= 2 0 0   ||| -0.1047820895910263
0 |||  冬阴功 是 泰国 最 著名 的 菜 之一 , 它 虽然 不是 很 豪华 , 但 它 的 味 确实 让 人 上瘾 , 做法 也 不难 , 不 复杂 。 ||| F0= -0.1169404685497284 EditOps0= 0 0 1   ||| -0.1169404685497284
0 |||  冬阴功 是 泰国 最 著名 的 菜 之一 , 它 虽然 不是 很 豪华 , 但 它 的 口味 确实 让 人 上瘾 , 做法 也 不难 、 不 复杂 。 ||| F0= -0.12856733798980713 EditOps0= 0 0 1   ||| -0.12856733798980713
0 |||  冬阴功 是 泰国 最 著名 的 菜 之一 , 它 虽然 不是 很 豪华 , 但 它 的 味道 确实 让 人 上瘾 , 做法 也 不难 , 不 复杂 。 ||| F0= -0.13551054894924164 EditOps0= 0 0 2   ||| -0.13551054894924164
0 ||| 冬阴功 是 泰国 最 著名 的 菜 之一 , 它 虽然 不是 很 豪华 , 但 它 的 味 确实 让 人 上瘾 , 做法 也 不难 、 不 复杂 。 ||| F0= -0.13648469746112823 EditOps0= 1 0 0   ||| -0.13648469746112823
0 ||| “ 冬阴功 ” 是 泰国 最 著名 的 菜 之一 , 它 虽然 不是 很 豪华 , 但 它 的 味 确实 让 人 上瘾 , 做法 也 不难 、 不 复杂 。 ||| F0= -0.14135058224201202 EditOps0= 0 1 1   ||| -0.14135058224201202
0 |||  冬阴功 是 泰国 最 著名 的 菜 之一 , 它 虽然 不是 很 豪华 , 但 它 的 味儿 确实 让 人 上瘾 , 做法 也 不难 、 不 复杂 。 ||| F0= -0.143321692943573 EditOps0= 0 0 1   ||| -0.143321692943573
0 |||  冬阴功 是 泰国 最 著名 的 菜 之一 , 它 虽然 不是 很 豪华 , 但 它 的 香味 确实 让 人 上瘾 , 做法 也 不难 、 不 复杂 。 ||| F0= -0.143504798412323 EditOps0= 0 0 1   ||| -0.143504798412323
0 |||  冬阴功 是 泰国 最 著名 的 菜 之一 , 虽然 它 不是 很 豪华 , 但 它 的 味 确实 让 人 上瘾 , 做法 也 不难 、 不 复杂 。 ||| F0= -0.14606299996376038 EditOps0= 1 1 0   ||| -0.14606299996376038
0 |||  冬阴功 是 泰国 最 著名 的 菜 之一 , 它 虽然 不是 很 奢华 , 但 它 的 味 确实 让 人 上瘾 , 做法 也 不难 、 不 复杂 。 ||| F0= -0.14855249226093292 EditOps0= 0 0 1   ||| -0.14855249226093292

And the weights of the reranker are trained successfully(${train_reranker_output_dir}/weights.eo.txt):

0.910415 0.0390036 0.0223347 0.0282471 

And I also tried modify train_reranker.sh and run_trained_model.sh to rerank nbest output only using the language model feature, but still the same error~

shamilcm commented 5 years ago

I could rerank the above n-best list (with 1 example) and your weights file with no issue. Can you send the full file? image

shamilcm commented 5 years ago

You could try to check the same?

python rerank.py -i test/nbest -w test/weights -o test/outnbest --clean-up

Put your nbest list with the single example that you gave above and your weights file. See if it works with a single example first.

young-zonglin commented 5 years ago

emm, even if there is only one sample, it still doesn't work: Screenshot from 2019-03-12 10-38-33 The file content and output dir: Screenshot from 2019-03-12 10-39-39

shamilcm commented 5 years ago

I see you have a conda/virtualenv enabled. I am suspecting you are switching to Python3 for running rerank.sh. Can you verify if python2.7 is being used?

young-zonglin commented 5 years ago

Yes, it is the problem!! I found that some python scripts in nusnlp/nbest-reranker project use python interpreter specified by #!/usr/bin/env python instead of #!/usr/bin/python. In my Ubuntu, #!/usr/bin/python means python 2.7, however #!/usr/bin/env python means python 3.6

young-zonglin commented 5 years ago

Very very thank you for your help!

wulouzhu commented 5 years ago

@young-zonglin When I used python3, I got the same error as you. But when I used python2, another error happended. Did you meet this problem.Thank you.

Traceback (most recent call last):
  File "software/nbest-reranker/rerank.py", line 81, in <module>
    output_1best.write(group[sorted_indices[0]].hyp + "\n")
IndexError: list index out of range