Conversation
add BDD-OIA example
…nknown import "M, R"
….py, moving 2 dist calculating methods into class A3BLReasoner and make them private
… ablkit\bridge.py
…in ablkit\bridge\simple_bridge.py
Request to merge branch hangy/master to branch dev
…IST add example - Squash of hangy/master f0ec43c plus follow-up cleanup. - examples/mnist_add: unify entry point on main.py with --method, --dist-func, --labeled-ratio. Removes the parallel new_feature.py. - ablkit/utils: fix rejection_dist (complexity term, alpha parameter) and rewrite similarity_dist around a per-example embedding matrix. - ablkit/reasoning: clearer error when 'similarity' is requested without embeddings; docstring updates covering the new dist_func options. - ablkit/data: replace private-key heuristic in BaseDataElement.keys with a direct scan over _data_fields.
- Removes examples/bdd_oia/dataset/dataset.zip from the repository (kept on disk locally). - Extends .gitignore with common dataset/binary extensions so future data files (.npz, .npy, .zip, .tar*, .gz, .h5, .parquet, MNIST *-ubyte, .data, .arff, ...) are not tracked.
- Intro/Reasoning: extend the dist_func description with similarity and rejection (and clarify that similarity requires embeddings). - Examples/MNISTAdd: add a Command-line options section covering --method, --dist-func and --labeled-ratio with usage examples. - ablkit.utils: export similarity_dist and rejection_dist so they show up in the generated API documentation.
- bdd_oia/main.py: --segment_size type=int -> type=float (default 0.01)
- simple_bridge.py: replace bare except with (TypeError, ValueError)
- basic_nn.py: fix 'accuray' typo in log message and 'save_parma_dic' var
- docs/API/*.rst: fix title underlines (5 files); list members explicitly
for ablkit.reasoning and ablkit.utils so newly-added symbols surface
- docs/Intro/{Basics,Quick-Start,Reasoning}.rst: fix title underlines
- docs/Examples/HWF.rst: '14 classes' -> '13 classes' (1-9 + 4 ops);
fix 'illstrations' typo; fix 'alongwith' -> 'along with'
- docs/Examples/MNISTAdd.rst: fix 'alongwith' -> 'along with'
- ABLModel.predict now calls base_model.extract_features (when present)
and stores per-example embeddings on data_example.embeddings, so any
user model can opt into dist_func='similarity' without subclassing.
- examples/mnist_add/models/a3bl_model.py: drop the now-redundant
A3BLModel shell; keep only A3BLBasicNN, which actually implements
extract_features.
- examples/mnist_add/{main,bridge/a3bl_bridge}.py: switch to ABLModel.
- Improve A3BLReasoner.abduce docstring (named return fields).
- examples/bdd_oia/reasoning/bddkb.py: replace assert with ValueError;
asserts disappear under python -O.
- docs: update similarity dist_func description to reference
extract_features instead of A3BLModel.
- ablkit/learning/abl_model.py: predict() return Dict[str, Any].
- examples/hwf/main.py: dedup HwfKB / HwfGroundKB logic_forward into a
shared helper; replace eval() with a precedence-aware ast walker so
the example no longer demonstrates eval-on-strings.
- examples/hed/{bridge,reasoning/reasoning}.py: annotate public method
signatures (Reasoner/Bridge overrides).
- examples/{hed,hwf}/datasets/get_dataset.py: replace bare print() with
print_log so the messages flow through ABLLogger.
- ablkit/reasoning/kb.py: route the Prolog install hint through
print_log at WARNING level instead of print().
- examples/{mnist_add,hwf,hed,bdd_oia}/main.py and docs/Examples,
docs/Intro: rename 'cls' (a backbone network instance) to 'net'.
'cls' is conventionally the class object in classmethods - this
removes the confusion for new readers.
- examples/bdd_oia/main.py: rename get_args -> parse_args to match
the other examples.
- examples/zoo/kb.py: replace exec()-based variable injection and
eval()-based lookup with an explicit dict of Z3 Int variables.
Same semantics, no dynamic code execution in the example code.
Extract _resolve_segment_size, _train_one_segment, _maybe_eval and _maybe_save from the 114-line train() method so the main loop reads top-down. Behavior is unchanged; verified against the mnist_add smoke tests including the semi-supervised path.
- Move examples/mnist_add/bridge/a3bl_bridge.py up one level so the
layout matches hed and bdd_oia (single bridge file at the example
root), and drop the now-empty bridge/ package.
- Add missing __init__.py files to examples/{mnist_add,bdd_oia,hed,
hwf}/{models,reasoning} so type-checkers and IDEs recognize them as
packages instead of namespace dirs.
…icNN Verification Learning support (ported from https://github.com/VerificationLearning/VerificationLearning): - ablkit/reasoning/verification.py (new): enumerate_label_assignments (Lawler-style best-first walk over the per-symbol probability lattice), top_k_satisfying, and VerificationReasoner. - ablkit/bridge/verification_bridge.py (new): VerificationBridge runs model.train once per top-K consistent candidate per segment. - ablkit/bridge/base_bridge.py: loosen the reasoner type check from isinstance(Reasoner) to a duck-type so non-Reasoner reasoners plug in. - examples/mnist_add/main.py: --method verification and --top-k flags (with steps_per_epoch adjusted so OneCycleLR accounts for top-K). extract_features promotion: - ablkit/learning/basic_nn.py: BasicNN now owns extract_features / _extract_features, so any wrapped PyTorch model that implements extract_features(x) can populate data_example.embeddings (used by dist_func='similarity'). - examples/mnist_add/models/a3bl_model.py deleted: its only purpose was to expose extract_features, which BasicNN now does directly. A3BL on mnist_add runs on plain BasicNN.
Workflows: - build-and-test.yaml: actions/checkout v2->v4, actions/setup-python v2->v5, codecov-action v1->v4. Drop Python 3.7 from the matrix (EOL). Replace the syphar virtualenv cache with setup-python's built-in pip cache, keyed on pyproject.toml. Install via pip install -e ".[test]". Add fail-fast: false; upload coverage once (ubuntu + py3.10). - lint.yaml: checkout v3->v4, setup-python v4->v5, Python 3.8->3.10, scope flake8 to ablkit only. Test fixes: - ablkit/learning/abl_model.py: with BasicNN now exposing extract_features unconditionally, the hasattr(model, "extract_features") check is no longer a real capability test. Wrap the call in try/except AttributeError so wrappers around PyTorch models that lack extract_features(x) silently skip embeddings during predict. - tests/test_reasoning.py: update test_invalid_predefined_dist_func to match the new error message that lists all five dist_func options. Lint cleanup (flake8 was clean before recent additions): - ablkit/bridge/verification_bridge.py: drop unused os.path import. - ablkit/reasoning/reasoner.py: split long import line, drop trailing whitespace. - ablkit/utils/utils.py: fix blank-line spacing around similarity_dist and rejection_dist. pyproject.toml: align requires-python with the workflow matrix (>=3.8.0); add explicit pytest to the [test] extras.
All Reasoner classes now live in a single module, matching the A3BLReasoner layout. Sections are separated by double-line === banners so the file remains scannable. - Move enumerate_label_assignments, top_k_satisfying and VerificationReasoner from ablkit/reasoning/verification.py into ablkit/reasoning/reasoner.py; delete the standalone file. - Update ablkit/reasoning/__init__.py and ablkit/bridge/verification_bridge.py to import from .reasoner. - Update docs/API/ablkit.reasoning.rst autofunction paths.
…BDD-OIA + Advanced docs
Move generic framework code out of examples into ablkit:
- examples/mnist_add/a3bl_bridge.py -> ablkit/bridge/a3bl_bridge.py
(the bridge pairs with the already-core A3BLReasoner; pre-existing
lint issues cleaned up as part of the move).
- examples/bdd_oia/models/bdd_nn.py -> MultiLabelBasicNN, inlined into
ablkit/learning/basic_nn.py under a "Multi-label variants" banner.
- examples/bdd_oia/models/bdd_model.py -> MultiLabelABLModel, inlined
into ablkit/learning/abl_model.py under a "Multi-label variants" banner.
- MultiLabelClassificationDataset extracted to
ablkit/learning/torch_dataset/multi_label_classification_dataset.py
(matches the one-class-per-file convention there).
- ablkit/{bridge,learning,reasoning}/__init__.py: export the promoted
symbols.
Callsite + reference updates:
- examples/bdd_oia/{main.py,bdd_oia.ipynb}: switch to MultiLabelBasicNN
/ MultiLabelABLModel; drop the deleted models/bdd_*.py files.
- examples/mnist_add/main.py: import A3BLBridge from ablkit.bridge.
- ablkit/reasoning/reasoner.py: add the A3BL reference URL to the A3BL
section banner.
Documentation:
- docs/Examples/BDD-OIA.rst (new) and toctree entry: an end-to-end
walkthrough of the BDD-OIA example matching the HWF.rst style.
- docs/Intro/Advanced.rst (new) and toctree entry: a single page that
collects the four "alternative methods" (multi-label, semi-supervised
via use_supervised_data, A3BL, Verification Learning) with a one-
paragraph rationale and minimal wiring for each.
- docs/Examples/MNISTAdd.rst: drop the obsolete A3BLBridge path,
replace em-dash separators in the CLI option list.
- README.md: add Lin-Han Jia to contributors.
The package was importing and using an optional third-party logger that is not in our requirements, which broke the build job on CI. Remove the import and its usage so the package builds on a clean environment with only the declared dependencies.
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.
This PR brings four new ABL method variants into ablkit core, refreshes the examples + docs to demonstrate them, and modernizes CI.
New methods (all opt-in; standard ABL is unchanged)
ablkit.reasoning.A3BLReasoner+ablkit.bridge.A3BLBridge. Soft-label aggregation over top-K consistent candidates. Reference: https://github.com/Hao-Yuan-He/A3BLablkit.reasoning.VerificationReasoner+ablkit.bridge.VerificationBridge. Lawler-style best-first enumeration of the top-K consistent label assignments, trained one-per-segment. Reference: https://github.com/VerificationLearning/VerificationLearningablkit.learning.MultiLabelABLModel,MultiLabelBasicNN,MultiLabelClassificationDataset(sigmoid + threshold).SimpleBridge.train(..., use_supervised_data=True)with partial-labeltrain_data(None entries get abduced).dist_funcoptions —similarity(cosine-geometry of model embeddings; requires base modelextract_features) andrejection(confidence + candidate-complexity).Examples
examples/bdd_oia/end-to-end pipeline (usesMultiLabelBasicNN/MultiLabelABLModel).examples/mnist_add/main.py: new--method {standard,a3bl,verification},--dist-func {hamming,confidence,avg_confidence,similarity,rejection},--labeled-ratio FLOAT,--top-k INTflags. The oldnew_feature.pyis removed.examples/hwf/main.py:eval()replaced with a precedence-awareastwalker;_valid_candidatededuped.examples/zoo/kb.py:exec()/eval()replaced with an explicit Z3 variable dict.Refactoring & cleanup
extract_featurespromoted toBasicNNso any user model withextract_features(x)can opt intodist_func='similarity'without subclassing.A3BLBasicNNdeleted.SimpleBridge.train()split into_resolve_segment_size/_train_one_segment/_maybe_eval/_maybe_savehelpers.Reasoner,A3BLReasoner,VerificationReasoner) consolidated inablkit/reasoning/reasoner.pywith=====section banners.A3BLBridgemoved fromexamples/mnist_add/intoablkit/bridge/(it was generic, not example-specific).cls = LeNet5(...)→net = LeNet5(...)across examples and docs (clsconventionally means a class).get_args→parse_argsfor cross-example consistency. Missing__init__.pyadded to example sub-packages.print()→print_log()in dataset downloaders and the Prolog install hint.except:insimple_bridge.py;--segment_size type=int default=0.01inbdd_oia/main.py;accuray/save_parma_dictypos;assert→ValueErrorin BDD KB.CI
.github/workflows/build-and-test.yaml:actions/checkout v2 → v4,setup-python v2 → v5,codecov-action v1 → v4. Drop Python 3.7 (EOL). Switched the third-party virtualenv cache to setup-python's built-in pip cache. Install viapip install -e ".[test]".fail-fast: false; coverage uploaded once (ubuntu+3.10)..github/workflows/lint.yaml: action bumps, Python 3.10, scope flake8 toablkit/.pyproject.toml:requires-python>=3.8.0; explicitpytestin[test]extras..gitignore: stop tracking dataset binaries (*.zip,*.npz,*-ubyte, etc.).examples/bdd_oia/dataset/dataset.zipremoved from tracking.Docs
docs/Intro/Advanced.rstpage covers all four new methods in one place; added to toctree.docs/Examples/BDD-OIA.rstwalkthrough; added to toctree.docs/Examples/MNISTAdd.rst: documented new CLI flags.Intro/andAPI/pages; explicit:members:forablkit.reasoningandablkit.utilsso newly-added symbols surface.