-
Notifications
You must be signed in to change notification settings - Fork 215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make predict methods in ZeroShot pipeline return Result instead of panicking on unwrap #301
Conversation
- Add checked prediction methods to ZeroShotClassificationModel. These methods return Option and convert any underlying errors into None, to allow callers to implement appropriate error handling logic.
Rename *_checked methods into try_* methods. This is more idiomatic vis-a-vis the Rust standard library.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much for the changes @anna-hope , this looks good.
I think it would be OK to change the signature of the current predict
and predict_multilabel
to return a Result
rather than having multiple methods (that just unwrap for the user). The next release will introduce some breaking changes already. I added one minor comment to move the Option
to Error
conversion to the method that would produce an invalid output (this also saves code duplication since it is called twice)
Change return type of ZeroShotClassificationModel.prepare_for_model from option into Result. This simplifies the code, and returns the error closer to its origin. This addresses comments from @guillaume-be.
@guillaume-be Thank you very much for your feedback! I addressed your comments. This did indeed result in cleaner code. |
…nicking on unwrap (guillaume-be#301) * Add checked prediction methods - Add checked prediction methods to ZeroShotClassificationModel. These methods return Option and convert any underlying errors into None, to allow callers to implement appropriate error handling logic. * Update ZeroShot example to use checked method. * Add tests for ZeroShot checked methods * Change checked prediction methods to return Result * refactor: rename *_checked into try_* Rename *_checked methods into try_* methods. This is more idiomatic vis-a-vis the Rust standard library. * refactor: remove try_ prefix from predict methods * refactor: change return from Option to Result Change return type of ZeroShotClassificationModel.prepare_for_model from option into Result. This simplifies the code, and returns the error closer to its origin. This addresses comments from @guillaume-be. * refactor: address clippy lints in tests Co-authored-by: guillaume-be <guillaume.becquin@gmail.com>
Add checked prediction methods to ZeroShotClassificationModel.
These methods return
Result
to allow callers to implement appropriate error handling logic.I named these methods
try_
by analogy withtry_
methods inHashMap
and elsewhere in the standard library.This closes #297 for ZeroShotClassificationModel.