Closed dmesquita closed 2 years ago
Hi!
Apologies for the late follow-up.
what does keyword-only mean? (docs table)
This means that an argument can only be specified with its keyword, e.g. visualize_ner(doc, labels=my_labels)
works, but visualize_ner(doc, my_labels)
doesn't. This is triggered by using the *
in the definition:
def visualize_ner(
doc: spacy.tokens.Doc,
*,
labels: Sequence[str] = tuple(),
attrs: List[str] = NER_ATTRS,
show_table: bool = True,
title: Optional[str] = "Named Entities",
colors: Dict[str, str] = {},
key: Optional[str] = None,
)
It's an approach we often take for optional arguments to ensure that code is robust to changing order of the parameters & future extensions/changes of the function definition.
You're right that the empty tuple default is confusing though. Perhaps we could raise a warning if labels
is empty? That will also catch cases where the user accidently passes on an empty list or such.
Closing this one in favour of the more general solution presented in https://github.com/explosion/spacy-streamlit/pull/26, but thanks again for the report!
Hi! The default
labels
parameter ofvisualize_ner()
is an empty tuple and I think we can make it more explicit because today I was debugging to figure out why my custom entities were not being displayed :P. Maybe I'm missing something, what doeskeyword-only
mean? (docs table)Back to the
labels
parameter, I'm not sure if it's best to:I modified the docs because it's more straightforward, let me know if you think it's not a good path. Thanks!