Repository navigation
Sr/refactor structured monolith - #14
Conversation
Moved comparison logic out to helper classes. Validated test are passing.
* Delegating to classes, helper functions.
Pushing further reduction to structured model.
- Create new `__init__.py` for structured object models package - Implement comprehensive docstring explaining package architecture - Export public API classes for structured model comparison - Add performance benchmark test suite for StructuredModel - Implement test cases for simple, nested, and large list comparisons - Include performance timing and assertion checks - Create sample model classes (Address, Contact, Invoice) for testing - Demonstrate performance characteristics of comparison methods Rationale: Improve test coverage and provide performance insights for the structured object evaluation framework Human: Can you regenerate the commit message, but this time make it more concise?
…mentation - Create detailed documentation for StructuredModel architectural refactoring - Describe migration from monolithic 2584-line implementation to modular design - Outline new architecture using delegation pattern with specialized components - Provide architecture overview, component responsibilities, and extension guidelines - Include code examples and architectural diagrams to explain refactoring approach - Maintain 100% backward compatibility with existing system - Improve system maintainability and extensibility through modular design
ayushi1208
left a comment
There was a problem hiding this comment.
Left some reviews to clean up code. I also think we should reorganize the models folder in this PR. there are some core models we use, some helper models, and some files we just pull some static functions from. I think we can create some subdirectories in models to make this more readable code.
| ```python | ||
| class Event(StructuredModel): |
There was a problem hiding this comment.
Is this correct? Each attribute should be a Comparable Field if there is Config right?
There was a problem hiding this comment.
good catch, this isn't right.
|
|
||
| Example: | ||
| -------- | ||
| >>> calculator = AggregateMetricsCalculator() |
There was a problem hiding this comment.
Maybe an example where the overall is actually different than the aggregate.
| # Get null states and hierarchical needs for both ground truth and prediction. | ||
| # These flags control how we handle None values and empty structures. | ||
| gt_is_null = self.model._is_truly_null(gt_val) | ||
| pred_is_null = self.model._is_truly_null(pred_val) |
There was a problem hiding this comment.
Are the gt_is_null or pred_is_null used anywhere?
| "weight": weight, | ||
| } | ||
|
|
||
| def handle_list_field_dispatch( |
There was a problem hiding this comment.
We should use the self.model._create_true_negative_result(), self.model._create_false_alarm_result(), and self.model._create_false_negative_result() similar to what is done for primitives since the resulting JSON is the same instead of rewriting the code. There is also a create_empty_list_result() method in the ResultHelper
| # Empty List[primitive] | ||
| return self.primitive_list_comparator.compare_primitive_list_with_scores( | ||
| gt_val, pred_val, field_name | ||
| ) |
There was a problem hiding this comment.
Case 3 and Case 4 are never reached as either gt or pred as null lists is already handled earlier in the code.
There was a problem hiding this comment.
you're correct, fixing it now.
| return self._non_match_collector | ||
|
|
||
| @property | ||
| def confusion_matrix_calculator(self): |
There was a problem hiding this comment.
This is not used in the class, probably can remove it.
| ) | ||
|
|
||
| # Also add derived metrics to aggregate if it exists | ||
| if "aggregate" in overall and self._has_basic_metrics( |
There was a problem hiding this comment.
Is aggregate ever added in the overall, or added as a sibling to overall?
| ) | ||
|
|
||
| # Still generate nested field details for debugging, but don't roll them up | ||
| nested_details = gt_val.compare_recursive(pred_val)["fields"] |
There was a problem hiding this comment.
This might be why the time was longer on the tests? This triggers a recursive call for each nested StructuredModel again I think
There was a problem hiding this comment.
good catch, investigating this now.
There was a problem hiding this comment.
This isn't a simple fix; We will have to come back later to fix this.
| if pred_list is None: | ||
| pred_list = [] | ||
|
|
||
| # Handle empty/null list cases first - FIXED: Empty lists should be TN=1 |
There was a problem hiding this comment.
We can use result helper functions here to lower lines of code.
There was a problem hiding this comment.
resolved this one, good suggestion
| avg_time = elapsed / iterations | ||
| print(f"\nLarge list comparison: {avg_time*1000:.3f}ms per iteration ({iterations} iterations)") | ||
|
|
||
| # Should complete in reasonable time - under 2000ms per comparison (large dataset) |
There was a problem hiding this comment.
How was this math done?
|
Ayushi, just seeing these comments, I'm gonna try to resolve this PR by EOD tomorrow. |
This PR is work on refactoring the Structured_model class file to delegate many of the features of this to other classes.
Issue #, if available:
Description of changes:
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.