modelcards
modelcards copied to clipboard
from_template silently drops non-matching kwargs
As a user, it is surprising to me that I can add any argument to ModelCard.from_template
only to have them silently being ignored if they don't match the template.
To reproduce, use the same code as in the README and add an arbitrary argument, e.g.
card = ModelCard.from_template(card_data=..., model_id=..., model_description=..., foo='123')
card.save(...)
The foo='123'
part is silently dropped.
ping @adrinjalali @merveenoyan
What would be the expected behaviour for you?
I'd expect an exception with a message containing the keys which are not present in the template.
Yes, it's easy too easy to miss currently. And even if you know that only supported keys should be used, you could still make a typo and there would be no indication of anything being wrong. At the very least, there should be a warning.
That being said, I looked through the jinja2 docs and code and there seems to be no support from jinja2 in validating the keys.
I believe there are ways to locate the existing keys in a template then we can compare those against the provided template kwargs. Definitely something to look into
I believe there are ways to locate the existing keys in a template then we can compare those against the provided template kwargs. Definitely something to look into
That would be fantastic, let me know if you need help. Ideally, the validation could be provided in a separate method, so that 3rd party libraries can make use of it.