Repository navigation
Deduplicate TDL_refinement.fit() against TDL via shared template-method hooks - #616
Merged
Merged
Conversation
…od hooks TDL_refinement.fit() (tree_learner_refinement_inherit.py) copy-pasted most of TDL.fit() (tree_learner.py) — grid search, classifier training, classification reporting, plotting, and final OWL-expression construction — with only the SHAP-based refinement loop spliced in; create_training_data() was likewise a byte-for-byte duplicate. Extracted the shared steps into _maybe_plot_embeddings/_fit_decision_tree/_report_and_plot/_finalize_predictions hooks on the base TDL class, and TDL_refinement now inherits create_training_data instead of redefining it. As a side effect, this fixes TDL_refinement.classification_report always raising AttributeError: fit() set self.__classification_report from within TDL_refinement's own class body, which Python name-mangles to a different attribute than the classification_report property (defined on TDL) reads. Both classes now go through the same _report_and_plot method, so they agree on the mangled name. Re-enabled the test that had been commented out because of this bug. Prunes the corresponding Improvements.md item and adds a CHANGELOG.md entry. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01H4NxQxE3vqNs2DQBWVaFeM
1 task done
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
TDL_refinement.fit()(tree_learner_refinement_inherit.py) copy-pasted most ofTDL.fit()(tree_learner.py) — grid search, classifier training, classification reporting, plotting, and final OWL-expression construction — with only the SHAP-based refinement loop spliced in;create_training_data()was likewise a byte-for-byte duplicate._maybe_plot_embeddings/_fit_decision_tree/_report_and_plot/_finalize_predictionshooks on the baseTDLclass;TDL_refinementnow inheritscreate_training_datainstead of redefining it, and its refinement loop is factored into its own_refine_features_with_shapmethod.TDL_refinement.classification_reportalways raisingAttributeError—fit()previously setself.__classification_reportfrom withinTDL_refinement's own class body, which Python name-mangles to a different attribute than theclassification_reportproperty (defined onTDL) reads. Both classes now go through the same_report_and_plot, so they agree on the mangled name. Re-enabledtests/test_tdl_refinement.py::TestTDLTraining::test_classification_report, which had been commented out because of this bug.Improvements.md(§2 Code duplication) and adds aCHANGELOG.mdentry.Test plan
pytest tests/test_tdl.py tests/test_tdl_refinement.py— 77 passedruff check ontolearn/learners --exclude ontolearn/learners/spell_kit --line-length=200— cleanpython -c "import ontolearn.executor"— sanity import check🤖 Generated with Claude Code
https://claude.ai/code/session_01H4NxQxE3vqNs2DQBWVaFeM