added from_dict() method to LTRModelConfig#806
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.
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", |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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