-
Notifications
You must be signed in to change notification settings - Fork 109
added from_dict() method to LTRModelConfig #806
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
base: main
Are you sure you want to change the base?
Conversation
🎉 Snyk checks have passed. No issues have been found so far.✅ security/snyk check is complete. No issues have been found. (View Details) ✅ license/snyk check is complete. No issues have been found. (View Details) |
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.
Pull Request Overview
This PR adds a from_dict() class method to the LTRModelConfig class to enable instantiation from dictionary representations, supporting JSON import/export functionality for LTR model configurations.
- Added
from_dict()class method with comprehensive docstring and examples - Implemented parsing logic for query extractors from dictionary format
- Added error handling for invalid configurations and unknown extractor types
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| ... }, | ||
| ... { | ||
| ... "query_extractor": { | ||
| ... "feature_name": "description_bm25", |
Copilot
AI
Sep 24, 2025
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.
There's a spelling error in the example - 'description_bm25' should match the variable name 'descritption_bm25' used in the PR description, or the PR description should be corrected to use 'description_bm25'.
| feature_extractors = [] | ||
| for feature_extractor in d[TYPE_LEARNING_TO_RANK]["feature_extractors"]: | ||
| if "query_extractor" in feature_extractor: |
Copilot
AI
Sep 24, 2025
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.
Missing validation for the 'feature_extractors' key. If the dictionary doesn't contain this key, a KeyError will be raised. Add a check to ensure 'feature_extractors' exists in the nested dictionary.
| feature_extractors = [] | |
| for feature_extractor in d[TYPE_LEARNING_TO_RANK]["feature_extractors"]: | |
| if "query_extractor" in feature_extractor: | |
| if "feature_extractors" not in d[TYPE_LEARNING_TO_RANK]: | |
| raise ValueError( | |
| f"Invalid LTR model config, missing 'feature_extractors' key in '{TYPE_LEARNING_TO_RANK}'" | |
| ) | |
| feature_extractors = [] | |
| for feature_extractor in d[TYPE_LEARNING_TO_RANK]["feature_extractors"]: |
from_dict() method adds support for instantiating a LTRModelConfig object from a dictionary. Allows users to easily export/import LTRModelConfig objects as json objects.
Closes issues 807