当数据量小于 batch_size 的时候,会出错
- Dominant language
- Python
- Stars
- 2k
- Forks
- 362
- PR merge metrics
- No merged PRs in 30d
Description
按照 README 中的脚本去进行 eval 的时候会出现
```
Traceback (most recent call last):
File "sentiment_classify.py", line 288, in
main(args)
File "sentiment_classify.py", line 273, in main
args.model_path)
File "sentiment_classify.py", line 210, in eval_net
class2_acc = class2_acc / (total_count - neu_count)
ZeroDivisionError: float division by zero
```
经过分析发现是自带数据集中测试数据集只有 200 条, 而默认 batch_size 是 256, 而且因为代码使用的 batch 是 paddle.v2.batch 而不是 paddle.batch, (这个两个函数的实现一样,但是默认参数在 paddle.v2.batch 里面 drop_last 默认是 True, paddle.batch 里默认是 False), 所以会导致 test_reader 不会 yield.
建议更新代码,把 `utils.py` 中的
`import paddle.v2 as paddle`
改成 `import paddle`
或者在
`utils.py`101 和105 行中把
```
101 train_reader = paddle.batch(data_reader(data_path, word_dict, True), batch_size)
105 test_reader = paddle.batch(data_reader(data_path, word_dict, False), batch_size)
```
中加上 drop_last=False.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with utils.py lines 101 and 105 and reproduce the README eval using the bundled dataset and its default batch size. Check that the test reader yields the 200-item dataset instead of dropping it, and confirm eval_net no longer reaches a zero-denominator accuracy calculation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100