Skip to content

print_textcats_auc_per_cat returns TypeError if there are no examples of a class in test dataset #7019

Description

@bpben

How to reproduce the behaviour

This is probably an edge case, but when the evaluation dataset does not contain any instances of a particular class, the scorer returns None, which causes the string formatting portion of print_textcats_auc_per_cat to fail and return the following error:

TypeError: unsupported format string passed to NoneType.__format__

I'm actually adapting the textcat tutorial for my company's usecase, but you can replicate the error just by slicing off all but the following lines from the test.tsv dataset (or any subset where the category list is incomplete):

I’m really sorry about your situation :( Although I love the names Sapphira, Cirilla, and Scarlett!	25	eecwqtt
It's wonderful because it's awful. At not with.	0	ed5f85d
Kings fan here, good luck to you guys! Will be an interesting game to watch! 	13	een27c3

If I run all the steps, I run into that error. It seems like a simple fix, let me know if that's something it'd be useful for me to take on.

Full traceback:

Traceback (most recent call last):
  File "/opt/miniconda3/envs/spacy/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/opt/miniconda3/envs/spacy/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/opt/miniconda3/envs/spacy/lib/python3.6/site-packages/spacy/__main__.py", line 4, in <module>
    setup_cli()
  File "/opt/miniconda3/envs/spacy/lib/python3.6/site-packages/spacy/cli/_util.py", line 68, in setup_cli
    command(prog_name=COMMAND)
  File "/opt/miniconda3/envs/spacy/lib/python3.6/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/opt/miniconda3/envs/spacy/lib/python3.6/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/opt/miniconda3/envs/spacy/lib/python3.6/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/opt/miniconda3/envs/spacy/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/opt/miniconda3/envs/spacy/lib/python3.6/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/opt/miniconda3/envs/spacy/lib/python3.6/site-packages/typer/main.py", line 497, in wrapper
    return callback(**use_params)  # type: ignore
  File "/opt/miniconda3/envs/spacy/lib/python3.6/site-packages/spacy/cli/evaluate.py", line 50, in evaluate_cli
    silent=False,
  File "/opt/miniconda3/envs/spacy/lib/python3.6/site-packages/spacy/cli/evaluate.py", line 130, in evaluate
    print_textcats_auc_per_cat(msg, scores["cats_auc_per_type"])
  File "/opt/miniconda3/envs/spacy/lib/python3.6/site-packages/spacy/cli/evaluate.py", line 194, in print_textcats_auc_per_cat
    [(k, f"{v:.2f}") for k, v in scores.items()],
  File "/opt/miniconda3/envs/spacy/lib/python3.6/site-packages/spacy/cli/evaluate.py", line 194, in <listcomp>
    [(k, f"{v:.2f}") for k, v in scores.items()],
TypeError: unsupported format string passed to NoneType.__format__

Your Environment

Info about spaCy

  • Operating System: Darwin-19.6.0-x86_64-i386-64bit
  • Python Version Used: 3.6.12
  • spaCy Version Used: spaCy version: 3.0.1
  • Environment Information:

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugBugs and behaviour differing from documentationfeat / textcatFeature: Text Classifierfeat / uxFeature: User experience, error messages etc.

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions