Skip to content

Fix nerval evaluation when an entity type is missing

I ran into a bug during nerval evaluation.

Traceback (most recent call last):
  File "/gpfsscratch/rech/rxm/ubz97wr/env_dan/bin/teklia-dan", line 8, in <module>
    sys.exit(main())
  File "/gpfsdswork/projects/rech/rxm/ubz97wr/dan_compile/dan/cli.py", line 28, in main
    status = args.pop("func")(**args)
  File "/gpfsdswork/projects/rech/rxm/ubz97wr/dan_compile/dan/ocr/evaluate.py", line 233, in run
    eval(0, config, nerval_threshold, mlflow_logging)
  File "/gpfsdswork/projects/rech/rxm/ubz97wr/dan_compile/dan/ocr/evaluate.py", line 205, in eval
    eval_nerval(
  File "/gpfsdswork/projects/rech/rxm/ubz97wr/dan_compile/dan/ocr/evaluate.py", line 144, in eval_nerval
    scores = {
  File "/gpfsdswork/projects/rech/rxm/ubz97wr/dan_compile/dan/ocr/evaluate.py", line 145, in <dictcomp>
    key: {
  File "/gpfsdswork/projects/rech/rxm/ubz97wr/dan_compile/dan/ocr/evaluate.py", line 146, in <dictcomp>
    k: round(value * 100, 2) if k in ["P", "R", "F1"] else value
TypeError: unsupported operand type(s) for *: 'NoneType' and 'int'

This happens when value is None, which happens when

  • no entity is predicted for a specific entity type
  • there is no entity in the labels for a specific entity type