425776024 / lasertagger-chinese

lasertagger-chinese;lasertagger中文学习案例,案例数据,注释,shell运行
75 stars 15 forks source link

预测脚本报错 #4

Open Vincent131499 opened 3 years ago

Vincent131499 commented 3 years ago

前面几个脚本正常运行,运行4.predict.sh则报错如下: [predict_main.py:71] input file:F:/▒㷨ƽ̨▒з▒/NLP▒㷨▒▒▒▒з▒/▒ı▒▒▒▒▒/▒ı▒▒▒▒▒LaserTagger/lasertagger-chinese-master/corpus/rephrase_corpus/test.txt Traceback (most recent call last): File "predict_main.py", line 105, in app.run(main) File "D:\Anaconda3\envs\tf14_cpu\lib\site-packages\absl\app.py", line 299, in run _run_main(main, args) File "D:\Anaconda3\envs\tf14_cpu\lib\site-packages\absl\app.py", line 250, in _run_main sys.exit(main(argv)) File "predict_main.py", line 89, in main prediction_batch = predictor.predict_batch(sources_batch=sources_batch) File "F:\▒㷨ƽ̨▒з▒\NLP▒㷨▒▒▒▒з▒\▒ı▒▒▒▒▒\▒ı▒▒▒▒▒LaserTagger\lasertagger-chinese-master\src\utils\predict_utils.py", line 75, in predict_batch self._id_2_tag[label_id] for label_id in example.get_token_labels() File "F:\▒㷨ƽ̨▒з▒\NLP▒㷨▒▒▒▒з▒\▒ı▒▒▒▒▒\▒ı▒▒▒▒▒LaserTagger\lasertagger-chinese-master\src\utils\predict_utils.py", line 75, in self._id_2_tag[label_id] for label_id in example.get_token_labels() KeyError: -1

425776024 commented 3 years ago

报错我,,不太好脑子里debug😭

YJorange commented 3 years ago

我也遇到了这个问题,请问你解决了吗?

chenzelong commented 3 years ago

我也遇到了,楼主解决了吗

425776024 commented 3 years ago

我也遇到了,楼主解决了吗

麻烦说清楚些哈,也是上面这个错误吗,上面那个很明显是keyerror。另外我给的数据只是例子数据,直接拿来跑一定错误的,数据量太少了

Destiny-bao commented 3 years ago

我也遇到了,怎么解决的?

MISStingting commented 3 years ago

predictor = predict_utils.LaserTaggerPredictor( tf.contrib.predictor.from_saved_model(FLAGS.saved_model), builder, label_map) 我用的tf2版本,修改上述代码如下:
model = tf.saved_model.load(pb_model_path) tf_predictor = model.signatures["serving_default"] predictor = predict_utils.LaserTaggerPredictor(tf_predictor, builder, label_map)

单个数据构建可以跑通,使用原有批量预测方法就会出错,。带 lf._predictor(input_ids=new_data[0], input_mask=new_data[1], segment_ids=new_data[2])

out = self._predictor(digits =input_info) 这里报错,无法进行批量预测,请问该怎么解决?

skywindy commented 1 year ago

大佬们,你好我也遇到了相似的问题, 就是predict_utils 中的predict_batch函数,self._id_2_tag[label_id] for label_id in example.get_token_labels() example.get_token_labels() 里面会有-2这种id.

[819, 884, 318, 435, 906, 928, 928, 928, 928, 928, 928, 928, 928, 921, 113, 214, 732, 25, 456, 637, 227, 893, 414, 703, 276, 497, 690, 329, 884, -2, 414, 828, 252, 87, 344, 536, 690, 414, 299, 932, 118, 229, 217, 489]

GioGioBond commented 1 year ago

这是因为在label那个dict里没有-1,-2,-3的key,但是预测结果里却会预测出-1,-2,-3的结果,导致id没办法转换成token。我不明白为什么模型会预测出负的标签,训练集标签不都是正的吗。

dmmhk commented 2 months ago

3.export.sh 的 --init_checkpoint=%EXPORT_FILE% 是什么设置的