Skip to content

Add A3BL / Verification Learning / multi-label / semi-supervised support, refresh docs & CI#15

Merged
troyyyyy merged 42 commits into
mainfrom
dev
May 17, 2026
Merged

Add A3BL / Verification Learning / multi-label / semi-supervised support, refresh docs & CI#15
troyyyyy merged 42 commits into
mainfrom
dev

Conversation

@troyyyyy

Copy link
Copy Markdown
Collaborator

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)

  • A3BLablkit.reasoning.A3BLReasoner + ablkit.bridge.A3BLBridge. Soft-label aggregation over top-K consistent candidates. Reference: https://github.com/Hao-Yuan-He/A3BL
  • Verification Learningablkit.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/VerificationLearning
  • Multi-labelablkit.learning.MultiLabelABLModel, MultiLabelBasicNN, MultiLabelClassificationDataset (sigmoid + threshold).
  • Semi-supervisedSimpleBridge.train(..., use_supervised_data=True) with partial-label train_data (None entries get abduced).
  • New predefined dist_func optionssimilarity (cosine-geometry of model embeddings; requires base model extract_features) and rejection (confidence + candidate-complexity).

Examples

  • New examples/bdd_oia/ end-to-end pipeline (uses MultiLabelBasicNN / MultiLabelABLModel).
  • examples/mnist_add/main.py: new --method {standard,a3bl,verification}, --dist-func {hamming,confidence,avg_confidence,similarity,rejection}, --labeled-ratio FLOAT, --top-k INT flags. The old new_feature.py is removed.
  • examples/hwf/main.py: eval() replaced with a precedence-aware ast walker; _valid_candidate deduped.
  • examples/zoo/kb.py: exec() / eval() replaced with an explicit Z3 variable dict.

Refactoring & cleanup

  • extract_features promoted to BasicNN so any user model with extract_features(x) can opt into dist_func='similarity' without subclassing. A3BLBasicNN deleted.
  • SimpleBridge.train() split into _resolve_segment_size / _train_one_segment / _maybe_eval / _maybe_save helpers.
  • All reasoners (Reasoner, A3BLReasoner, VerificationReasoner) consolidated in ablkit/reasoning/reasoner.py with ===== section banners.
  • A3BLBridge moved from examples/mnist_add/ into ablkit/bridge/ (it was generic, not example-specific).
  • Naming pedagogy: cls = LeNet5(...)net = LeNet5(...) across examples and docs (cls conventionally means a class). get_argsparse_args for cross-example consistency. Missing __init__.py added to example sub-packages.
  • Logging: print()print_log() in dataset downloaders and the Prolog install hint.
  • Bug fixes: bare except: in simple_bridge.py; --segment_size type=int default=0.01 in bdd_oia/main.py; accuray / save_parma_dic typos; assertValueError in 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 via pip install -e ".[test]". fail-fast: false; coverage uploaded once (ubuntu+3.10).
  • .github/workflows/lint.yaml: action bumps, Python 3.10, scope flake8 to ablkit/.
  • pyproject.toml: requires-python>=3.8.0; explicit pytest in [test] extras.
  • .gitignore: stop tracking dataset binaries (*.zip, *.npz, *-ubyte, etc.). examples/bdd_oia/dataset/dataset.zip removed from tracking.

Docs

  • New docs/Intro/Advanced.rst page covers all four new methods in one place; added to toctree.
  • New docs/Examples/BDD-OIA.rst walkthrough; added to toctree.
  • docs/Examples/MNISTAdd.rst: documented new CLI flags.
  • Sphinx title-underline fixes across Intro/ and API/ pages; explicit :members: for ablkit.reasoning and ablkit.utils so newly-added symbols surface.

wnqn1597 and others added 30 commits June 13, 2025 15:59
….py, moving 2 dist calculating methods into class A3BLReasoner and make them private
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.
troyyyyy added 12 commits May 17, 2026 11:36
- 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.
@troyyyyy troyyyyy merged commit ed1838e into main May 17, 2026
9 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants