From dab233c16a5161b7f56202164234da2c2d083287 Mon Sep 17 00:00:00 2001 From: troyyyyy Date: Sun, 7 Jan 2024 15:35:12 +0800 Subject: [PATCH] [ENH] change code from abl to ablkit --- README.md | 12 ++++++------ {abl => ablkit}/__init__.py | 0 {abl => ablkit}/bridge/__init__.py | 0 {abl => ablkit}/bridge/base_bridge.py | 0 {abl => ablkit}/bridge/simple_bridge.py | 0 {abl => ablkit}/data/__init__.py | 0 {abl => ablkit}/data/data_converter.py | 2 +- {abl => ablkit}/data/evaluation/__init__.py | 0 {abl => ablkit}/data/evaluation/base_metric.py | 0 .../data/evaluation/reasoning_metric.py | 0 {abl => ablkit}/data/evaluation/symbol_accuracy.py | 0 {abl => ablkit}/data/structures/__init__.py | 0 .../data/structures/base_data_element.py | 0 {abl => ablkit}/data/structures/list_data.py | 2 +- {abl => ablkit}/learning/__init__.py | 0 {abl => ablkit}/learning/abl_model.py | 0 {abl => ablkit}/learning/basic_nn.py | 0 {abl => ablkit}/learning/model_converter.py | 0 {abl => ablkit}/learning/torch_dataset/__init__.py | 0 .../torch_dataset/classification_dataset.py | 0 .../learning/torch_dataset/prediction_dataset.py | 0 .../learning/torch_dataset/regression_dataset.py | 0 {abl => ablkit}/reasoning/__init__.py | 0 {abl => ablkit}/reasoning/kb.py | 0 {abl => ablkit}/reasoning/reasoner.py | 0 {abl => ablkit}/utils/__init__.py | 0 {abl => ablkit}/utils/cache.py | 0 {abl => ablkit}/utils/logger.py | 0 {abl => ablkit}/utils/manager.py | 0 {abl => ablkit}/utils/utils.py | 0 docs/API/abl.bridge.rst | 4 ++-- docs/API/abl.data.rst | 6 +++--- docs/API/abl.learning.rst | 8 ++++---- docs/API/abl.reasoning.rst | 4 ++-- docs/API/abl.utils.rst | 4 ++-- docs/Examples/HED.rst | 4 ++-- docs/Examples/HWF.rst | 12 ++++++------ docs/Examples/MNISTAdd.rst | 12 ++++++------ docs/Examples/Zoo.rst | 10 +++++----- docs/Intro/Bridge.rst | 4 ++-- docs/Intro/Datasets.rst | 6 +++--- docs/Intro/Evaluation.rst | 2 +- docs/Intro/Learning.rst | 2 +- docs/Intro/Quick-Start.rst | 12 ++++++------ docs/Intro/Reasoning.rst | 2 +- docs/index.rst | 10 +++++----- examples/hed/bridge.py | 14 +++++++------- examples/hed/consistency_metric.py | 6 +++--- examples/hed/hed.ipynb | 4 ++-- examples/hed/main.py | 4 ++-- examples/hed/reasoning/reasoning.py | 4 ++-- examples/hwf/hwf.ipynb | 12 ++++++------ examples/hwf/main.py | 10 +++++----- examples/mnist_add/main.py | 10 +++++----- examples/mnist_add/mnist_add.ipynb | 12 ++++++------ examples/zoo/kb.py | 2 +- examples/zoo/main.py | 10 +++++----- examples/zoo/zoo.ipynb | 10 +++++----- tests/conftest.py | 6 +++--- tests/test_abl_model.py | 2 +- tests/test_reasoning.py | 2 +- 61 files changed, 113 insertions(+), 113 deletions(-) rename {abl => ablkit}/__init__.py (100%) rename {abl => ablkit}/bridge/__init__.py (100%) rename {abl => ablkit}/bridge/base_bridge.py (100%) rename {abl => ablkit}/bridge/simple_bridge.py (100%) rename {abl => ablkit}/data/__init__.py (100%) rename {abl => ablkit}/data/data_converter.py (99%) rename {abl => ablkit}/data/evaluation/__init__.py (100%) rename {abl => ablkit}/data/evaluation/base_metric.py (100%) rename {abl => ablkit}/data/evaluation/reasoning_metric.py (100%) rename {abl => ablkit}/data/evaluation/symbol_accuracy.py (100%) rename {abl => ablkit}/data/structures/__init__.py (100%) rename {abl => ablkit}/data/structures/base_data_element.py (100%) rename {abl => ablkit}/data/structures/list_data.py (99%) rename {abl => ablkit}/learning/__init__.py (100%) rename {abl => ablkit}/learning/abl_model.py (100%) rename {abl => ablkit}/learning/basic_nn.py (100%) rename {abl => ablkit}/learning/model_converter.py (100%) rename {abl => ablkit}/learning/torch_dataset/__init__.py (100%) rename {abl => ablkit}/learning/torch_dataset/classification_dataset.py (100%) rename {abl => ablkit}/learning/torch_dataset/prediction_dataset.py (100%) rename {abl => ablkit}/learning/torch_dataset/regression_dataset.py (100%) rename {abl => ablkit}/reasoning/__init__.py (100%) rename {abl => ablkit}/reasoning/kb.py (100%) rename {abl => ablkit}/reasoning/reasoner.py (100%) rename {abl => ablkit}/utils/__init__.py (100%) rename {abl => ablkit}/utils/cache.py (100%) rename {abl => ablkit}/utils/logger.py (100%) rename {abl => ablkit}/utils/manager.py (100%) rename {abl => ablkit}/utils/utils.py (100%) diff --git a/README.md b/README.md index 1d44939..1c94298 100644 --- a/README.md +++ b/README.md @@ -113,7 +113,7 @@ To facilitate uniform processing, ABL Kit provides the `BasicNN` class to conver ```python ​import torch -​from abl.learning import BasicNN +​from ablkit.learning import BasicNN ​ ​loss_fn = torch.nn.CrossEntropyLoss() ​optimizer = torch.optim.RMSprop(cls.parameters(), lr=0.001, alpha=0.9) @@ -124,7 +124,7 @@ To facilitate uniform processing, ABL Kit provides the `BasicNN` class to conver The base model built above is trained to make predictions on instance-level data (e.g., a single image), while ABL deals with example-level data. To bridge this gap, we wrap the base_model into an instance of `ABLModel`. This class serves as a unified wrapper for base models, facilitating the learning part to train, test, and predict on example-level data, (e.g., images that comprise an equation). ```python -from abl.learning import ABLModel +from ablkit.learning import ABLModel ​ ​model = ABLModel(base_model) ``` @@ -138,7 +138,7 @@ from abl.learning import ABLModel To build the reasoning part, we first define a knowledge base by creating a subclass of `KBBase`. In the subclass, we initialize the `pseudo_label_list` parameter and override the `logic_forward` method, which specifies how to perform (deductive) reasoning that processes pseudo-labels of an example to the corresponding reasoning result. Specifically, for the MNIST Addition task, this `logic_forward` method is tailored to execute the sum operation. ```python -from abl.reasoning import KBBase +from ablkit.reasoning import KBBase ​ class AddKB(KBBase): def __init__(self, pseudo_label_list=list(range(10))): @@ -153,7 +153,7 @@ kb = AddKB() Next, we create a reasoner by instantiating the class `Reasoner`, passing the knowledge base as a parameter. Due to the indeterminism of abductive reasoning, there could be multiple candidate pseudo-labels compatible to the knowledge base. In such scenarios, the reasoner can minimize inconsistency and return the pseudo-label with the highest consistency. ```python -from abl.reasoning import Reasoner +from ablkit.reasoning import Reasoner ​ reasoner = Reasoner(kb) ``` @@ -167,7 +167,7 @@ reasoner = Reasoner(kb) ABL Kit provides two basic metrics, namely `SymbolAccuracy` and `ReasoningMetric`, which are used to evaluate the accuracy of the machine learning model's predictions and the accuracy of the `logic_forward` results, respectively. ```python -from abl.data.evaluation import ReasoningMetric, SymbolAccuracy +from ablkit.data.evaluation import ReasoningMetric, SymbolAccuracy ​ metric_list = [SymbolAccuracy(), ReasoningMetric(kb=kb)] ``` @@ -182,7 +182,7 @@ Now, we use `SimpleBridge` to combine learning and reasoning in a unified ABL framework. ```python -from abl.bridge import SimpleBridge +from ablkit.bridge import SimpleBridge ​ bridge = SimpleBridge(model, reasoner, metric_list) ``` diff --git a/abl/__init__.py b/ablkit/__init__.py similarity index 100% rename from abl/__init__.py rename to ablkit/__init__.py diff --git a/abl/bridge/__init__.py b/ablkit/bridge/__init__.py similarity index 100% rename from abl/bridge/__init__.py rename to ablkit/bridge/__init__.py diff --git a/abl/bridge/base_bridge.py b/ablkit/bridge/base_bridge.py similarity index 100% rename from abl/bridge/base_bridge.py rename to ablkit/bridge/base_bridge.py diff --git a/abl/bridge/simple_bridge.py b/ablkit/bridge/simple_bridge.py similarity index 100% rename from abl/bridge/simple_bridge.py rename to ablkit/bridge/simple_bridge.py diff --git a/abl/data/__init__.py b/ablkit/data/__init__.py similarity index 100% rename from abl/data/__init__.py rename to ablkit/data/__init__.py diff --git a/abl/data/data_converter.py b/ablkit/data/data_converter.py similarity index 99% rename from abl/data/data_converter.py rename to ablkit/data/data_converter.py index b87a3b9..9191a67 100644 --- a/abl/data/data_converter.py +++ b/ablkit/data/data_converter.py @@ -1,6 +1,6 @@ from typing import Any, Tuple -from abl.utils import tab_data_to_tuple +from ablkit.utils import tab_data_to_tuple from .structures.list_data import ListData from lambdaLearn.Base.TabularMixin import TabularMixin diff --git a/abl/data/evaluation/__init__.py b/ablkit/data/evaluation/__init__.py similarity index 100% rename from abl/data/evaluation/__init__.py rename to ablkit/data/evaluation/__init__.py diff --git a/abl/data/evaluation/base_metric.py b/ablkit/data/evaluation/base_metric.py similarity index 100% rename from abl/data/evaluation/base_metric.py rename to ablkit/data/evaluation/base_metric.py diff --git a/abl/data/evaluation/reasoning_metric.py b/ablkit/data/evaluation/reasoning_metric.py similarity index 100% rename from abl/data/evaluation/reasoning_metric.py rename to ablkit/data/evaluation/reasoning_metric.py diff --git a/abl/data/evaluation/symbol_accuracy.py b/ablkit/data/evaluation/symbol_accuracy.py similarity index 100% rename from abl/data/evaluation/symbol_accuracy.py rename to ablkit/data/evaluation/symbol_accuracy.py diff --git a/abl/data/structures/__init__.py b/ablkit/data/structures/__init__.py similarity index 100% rename from abl/data/structures/__init__.py rename to ablkit/data/structures/__init__.py diff --git a/abl/data/structures/base_data_element.py b/ablkit/data/structures/base_data_element.py similarity index 100% rename from abl/data/structures/base_data_element.py rename to ablkit/data/structures/base_data_element.py diff --git a/abl/data/structures/list_data.py b/ablkit/data/structures/list_data.py similarity index 99% rename from abl/data/structures/list_data.py rename to ablkit/data/structures/list_data.py index 6e0f5d6..b937e18 100644 --- a/abl/data/structures/list_data.py +++ b/ablkit/data/structures/list_data.py @@ -57,7 +57,7 @@ class ListData(BaseDataElement): class implemented in `MMEngine `_. # noqa: E501 Examples: - >>> from abl.data.structures import ListData + >>> from ablkit.data.structures import ListData >>> import numpy as np >>> import torch >>> data_examples = ListData() diff --git a/abl/learning/__init__.py b/ablkit/learning/__init__.py similarity index 100% rename from abl/learning/__init__.py rename to ablkit/learning/__init__.py diff --git a/abl/learning/abl_model.py b/ablkit/learning/abl_model.py similarity index 100% rename from abl/learning/abl_model.py rename to ablkit/learning/abl_model.py diff --git a/abl/learning/basic_nn.py b/ablkit/learning/basic_nn.py similarity index 100% rename from abl/learning/basic_nn.py rename to ablkit/learning/basic_nn.py diff --git a/abl/learning/model_converter.py b/ablkit/learning/model_converter.py similarity index 100% rename from abl/learning/model_converter.py rename to ablkit/learning/model_converter.py diff --git a/abl/learning/torch_dataset/__init__.py b/ablkit/learning/torch_dataset/__init__.py similarity index 100% rename from abl/learning/torch_dataset/__init__.py rename to ablkit/learning/torch_dataset/__init__.py diff --git a/abl/learning/torch_dataset/classification_dataset.py b/ablkit/learning/torch_dataset/classification_dataset.py similarity index 100% rename from abl/learning/torch_dataset/classification_dataset.py rename to ablkit/learning/torch_dataset/classification_dataset.py diff --git a/abl/learning/torch_dataset/prediction_dataset.py b/ablkit/learning/torch_dataset/prediction_dataset.py similarity index 100% rename from abl/learning/torch_dataset/prediction_dataset.py rename to ablkit/learning/torch_dataset/prediction_dataset.py diff --git a/abl/learning/torch_dataset/regression_dataset.py b/ablkit/learning/torch_dataset/regression_dataset.py similarity index 100% rename from abl/learning/torch_dataset/regression_dataset.py rename to ablkit/learning/torch_dataset/regression_dataset.py diff --git a/abl/reasoning/__init__.py b/ablkit/reasoning/__init__.py similarity index 100% rename from abl/reasoning/__init__.py rename to ablkit/reasoning/__init__.py diff --git a/abl/reasoning/kb.py b/ablkit/reasoning/kb.py similarity index 100% rename from abl/reasoning/kb.py rename to ablkit/reasoning/kb.py diff --git a/abl/reasoning/reasoner.py b/ablkit/reasoning/reasoner.py similarity index 100% rename from abl/reasoning/reasoner.py rename to ablkit/reasoning/reasoner.py diff --git a/abl/utils/__init__.py b/ablkit/utils/__init__.py similarity index 100% rename from abl/utils/__init__.py rename to ablkit/utils/__init__.py diff --git a/abl/utils/cache.py b/ablkit/utils/cache.py similarity index 100% rename from abl/utils/cache.py rename to ablkit/utils/cache.py diff --git a/abl/utils/logger.py b/ablkit/utils/logger.py similarity index 100% rename from abl/utils/logger.py rename to ablkit/utils/logger.py diff --git a/abl/utils/manager.py b/ablkit/utils/manager.py similarity index 100% rename from abl/utils/manager.py rename to ablkit/utils/manager.py diff --git a/abl/utils/utils.py b/ablkit/utils/utils.py similarity index 100% rename from abl/utils/utils.py rename to ablkit/utils/utils.py diff --git a/docs/API/abl.bridge.rst b/docs/API/abl.bridge.rst index c967941..3cfc127 100644 --- a/docs/API/abl.bridge.rst +++ b/docs/API/abl.bridge.rst @@ -1,7 +1,7 @@ -abl.bridge +ablkit.bridge ================== -.. automodule:: abl.bridge +.. automodule:: ablkit.bridge :members: :undoc-members: :show-inheritance: \ No newline at end of file diff --git a/docs/API/abl.data.rst b/docs/API/abl.data.rst index fabff2c..32bc5d2 100644 --- a/docs/API/abl.data.rst +++ b/docs/API/abl.data.rst @@ -1,10 +1,10 @@ -abl.data +ablkit.data =================== ``structures`` -------------- -.. autoclass:: abl.data.structures.ListData +.. autoclass:: ablkit.data.structures.ListData :members: :undoc-members: :show-inheritance: @@ -12,7 +12,7 @@ abl.data ``evaluation`` -------------- -.. automodule:: abl.data.evaluation +.. automodule:: ablkit.data.evaluation :members: :undoc-members: :show-inheritance: diff --git a/docs/API/abl.learning.rst b/docs/API/abl.learning.rst index 7bdea1c..f26a866 100644 --- a/docs/API/abl.learning.rst +++ b/docs/API/abl.learning.rst @@ -1,12 +1,12 @@ -abl.learning +ablkit.learning ================== -.. autoclass:: abl.learning.ABLModel +.. autoclass:: ablkit.learning.ABLModel :members: :undoc-members: :show-inheritance: -.. autoclass:: abl.learning.BasicNN +.. autoclass:: ablkit.learning.BasicNN :members: :undoc-members: :show-inheritance: @@ -14,7 +14,7 @@ abl.learning ``torch_dataset`` ----------------- -.. automodule:: abl.learning.torch_dataset +.. automodule:: ablkit.learning.torch_dataset :members: :undoc-members: :show-inheritance: \ No newline at end of file diff --git a/docs/API/abl.reasoning.rst b/docs/API/abl.reasoning.rst index fefa64a..8707fc3 100644 --- a/docs/API/abl.reasoning.rst +++ b/docs/API/abl.reasoning.rst @@ -1,7 +1,7 @@ -abl.reasoning +ablkit.reasoning ================== -.. automodule:: abl.reasoning +.. automodule:: ablkit.reasoning :members: :undoc-members: :show-inheritance: \ No newline at end of file diff --git a/docs/API/abl.utils.rst b/docs/API/abl.utils.rst index 0975dae..b963a89 100644 --- a/docs/API/abl.utils.rst +++ b/docs/API/abl.utils.rst @@ -1,7 +1,7 @@ -abl.utils +ablkit.utils ================== -.. automodule:: abl.utils +.. automodule:: ablkit.utils :members: :undoc-members: :show-inheritance: \ No newline at end of file diff --git a/docs/Examples/HED.rst b/docs/Examples/HED.rst index 2b91be5..8a303eb 100644 --- a/docs/Examples/HED.rst +++ b/docs/Examples/HED.rst @@ -34,8 +34,8 @@ model. import torch import torch.nn as nn - from abl.learning import ABLModel, BasicNN - from abl.utils import ABLLogger, print_log + from ablkit.learning import ABLModel, BasicNN + from ablkit.utils import ABLLogger, print_log from bridge import HedBridge from consistency_metric import ConsistencyMetric diff --git a/docs/Examples/HWF.rst b/docs/Examples/HWF.rst index e940dce..d1f019e 100644 --- a/docs/Examples/HWF.rst +++ b/docs/Examples/HWF.rst @@ -32,11 +32,11 @@ machine learning model. import torch import torch.nn as nn - from abl.bridge import SimpleBridge - from abl.data.evaluation import ReasoningMetric, SymbolAccuracy - from abl.learning import ABLModel, BasicNN - from abl.reasoning import KBBase, Reasoner - from abl.utils import ABLLogger, print_log + from ablkit.bridge import SimpleBridge + from ablkit.data.evaluation import ReasoningMetric, SymbolAccuracy + from ablkit.learning import ABLModel, BasicNN + from ablkit.reasoning import KBBase, Reasoner + from ablkit.utils import ABLLogger, print_log from datasets import get_dataset from models.nn import SymbolNet @@ -232,7 +232,7 @@ examples. .. code:: ipython3 - from abl.data.structures import ListData + from ablkit.data.structures import ListData # ListData is a data structure provided by ABL Kit that can be used to organize data examples data_examples = ListData() # We use the first 1001st and 3001st data examples in the training set as an illustration diff --git a/docs/Examples/MNISTAdd.rst b/docs/Examples/MNISTAdd.rst index aef522b..a0e0663 100644 --- a/docs/Examples/MNISTAdd.rst +++ b/docs/Examples/MNISTAdd.rst @@ -31,11 +31,11 @@ machine learning model. import torch.nn as nn from torch.optim import RMSprop, lr_scheduler - from abl.bridge import SimpleBridge - from abl.data.evaluation import ReasoningMetric, SymbolAccuracy - from abl.learning import ABLModel, BasicNN - from abl.reasoning import KBBase, Reasoner - from abl.utils import ABLLogger, print_log + from ablkit.bridge import SimpleBridge + from ablkit.data.evaluation import ReasoningMetric, SymbolAccuracy + from ablkit.learning import ABLModel, BasicNN + from ablkit.reasoning import KBBase, Reasoner + from ablkit.utils import ABLLogger, print_log from datasets import get_dataset from models.nn import LeNet5 @@ -202,7 +202,7 @@ examples. .. code:: ipython3 - from abl.data.structures import ListData + from ablkit.data.structures import ListData # ListData is a data structure provided by ABL Kit that can be used to organize data examples data_examples = ListData() # We use the first 100 data examples in the training set as an illustration diff --git a/docs/Examples/Zoo.rst b/docs/Examples/Zoo.rst index c17c726..221c09c 100644 --- a/docs/Examples/Zoo.rst +++ b/docs/Examples/Zoo.rst @@ -28,11 +28,11 @@ further update the learning model. import numpy as np from sklearn.ensemble import RandomForestClassifier - from abl.bridge import SimpleBridge - from abl.data.evaluation import ReasoningMetric, SymbolAccuracy - from abl.learning import ABLModel - from abl.reasoning import Reasoner - from abl.utils import ABLLogger, confidence_dist, print_log, tab_data_to_tuple + from ablkit.bridge import SimpleBridge + from ablkit.data.evaluation import ReasoningMetric, SymbolAccuracy + from ablkit.learning import ABLModel + from ablkit.reasoning import Reasoner + from ablkit.utils import ABLLogger, confidence_dist, print_log, tab_data_to_tuple from get_dataset import load_and_preprocess_dataset, split_dataset from kb import ZooKB diff --git a/docs/Intro/Bridge.rst b/docs/Intro/Bridge.rst index 8d6b82e..35ee5ee 100644 --- a/docs/Intro/Bridge.rst +++ b/docs/Intro/Bridge.rst @@ -14,7 +14,7 @@ In this section, we will look at how to bridge learning and reasoning parts to t .. code:: python - from abl.bridge import BaseBridge, SimpleBridge + from ablkit.bridge import BaseBridge, SimpleBridge ``BaseBridge`` is an abstract class with the following initialization parameters: @@ -42,7 +42,7 @@ In this section, we will look at how to bridge learning and reasoning parts to t | ``test(test_data)`` | Test the model. | +---------------------------------------+----------------------------------------------------+ -where ``train_data`` and ``test_data`` are both in the form of a tuple or a `ListData <../API/abl.data.html#structures.ListData>`_. Regardless of the form, they all need to include three components: ``X``, ``gt_pseudo_label`` and ``Y``. Since ``ListData`` is the underlying data structure used throughout the ABL Kit, tuple-formed data will be firstly transformed into ``ListData`` in the ``train`` and ``test`` methods, and such ``ListData`` instances are referred to as ``data_examples``. More details can be found in `preparing datasets `_. +where ``train_data`` and ``test_data`` are both in the form of a tuple or a `ListData <../API/ablkit.data.html#structures.ListData>`_. Regardless of the form, they all need to include three components: ``X``, ``gt_pseudo_label`` and ``Y``. Since ``ListData`` is the underlying data structure used throughout the ABL Kit, tuple-formed data will be firstly transformed into ``ListData`` in the ``train`` and ``test`` methods, and such ``ListData`` instances are referred to as ``data_examples``. More details can be found in `preparing datasets `_. ``SimpleBridge`` inherits from ``BaseBridge`` and provides a basic implementation. Besides the ``model`` and ``reasoner``, ``SimpleBridge`` has an extra initialization argument, ``metric_list``, which will be used to evaluate model performance. Its training process involves several Abductive Learning loops and each loop consists of the following five steps: diff --git a/docs/Intro/Datasets.rst b/docs/Intro/Datasets.rst index 321986c..4b1788e 100644 --- a/docs/Intro/Datasets.rst +++ b/docs/Intro/Datasets.rst @@ -15,7 +15,7 @@ In this section, we will look at the dataset and data structure in ABL Kit. .. code:: python import torch - from abl.data.structures import ListData + from ablkit.data.structures import ListData Dataset ------- @@ -62,11 +62,11 @@ where each sublist in ``X``, e.g., |data_example|, is a data example and each im Data Structure -------------- -Besides the user-provided dataset, various forms of data are utilized and dynamicly generated throughout the training and testing process of ABL framework. Examples include raw data, predicted pseudo-label, abduced pseudo-label, pseudo-label indices, etc. To manage this diversity and ensure a stable, versatile interface, ABL Kit employs `abstract data interfaces <../API/abl.data.html#structure>`_ to encapsulate different forms of data that will be used in the total learning process. +Besides the user-provided dataset, various forms of data are utilized and dynamicly generated throughout the training and testing process of ABL framework. Examples include raw data, predicted pseudo-label, abduced pseudo-label, pseudo-label indices, etc. To manage this diversity and ensure a stable, versatile interface, ABL Kit employs `abstract data interfaces <../API/ablkit.data.html#structure>`_ to encapsulate different forms of data that will be used in the total learning process. ``ListData`` is the underlying abstract data interface utilized in ABL Kit. As the fundamental data structure, ``ListData`` implements commonly used data manipulation methods and is responsible for transferring data between various components of ABL, ensuring that stages such as prediction, abductive reasoning, and training can utilize ``ListData`` as a unified input format. Before proceeding to other stages, user-provided datasets will be firstly converted into ``ListData``. -Besides providing a tuple of ``(X, gt_pseudo_label, Y)``, ABL Kit also allows users to directly supply data in ``ListData`` format, which similarly requires the inclusion of these three attributes. The following code shows the basic usage of ``ListData``. More information can be found in the `API documentation <../API/abl.data.html#structure>`_. +Besides providing a tuple of ``(X, gt_pseudo_label, Y)``, ABL Kit also allows users to directly supply data in ``ListData`` format, which similarly requires the inclusion of these three attributes. The following code shows the basic usage of ``ListData``. More information can be found in the `API documentation <../API/ablkit.data.html#structure>`_. .. code-block:: python diff --git a/docs/Intro/Evaluation.rst b/docs/Intro/Evaluation.rst index bc328ac..e07cd51 100644 --- a/docs/Intro/Evaluation.rst +++ b/docs/Intro/Evaluation.rst @@ -14,7 +14,7 @@ In this section, we will look at how to build evaluation metrics. .. code:: python - from abl.data.evaluation import BaseMetric, SymbolAccuracy, ReasoningMetric + from ablkit.data.evaluation import BaseMetric, SymbolAccuracy, ReasoningMetric ABL Kit seperates the evaluation process from model training and testing as an independent class, ``BaseMetric``. The training and testing processes are implemented in the ``BaseBridge`` class, so metrics are used by this class and its sub-classes. After building a ``bridge`` with a list of ``BaseMetric`` instances, these metrics will be used by the ``bridge.valid`` method to evaluate the model performance during training and testing. diff --git a/docs/Intro/Learning.rst b/docs/Intro/Learning.rst index 7f14346..ccbb06b 100644 --- a/docs/Intro/Learning.rst +++ b/docs/Intro/Learning.rst @@ -21,7 +21,7 @@ In ABL Kit, building the learning part involves two steps: import sklearn import torchvision - from abl.learning import BasicNN, ABLModel + from ablkit.learning import BasicNN, ABLModel Building a base model --------------------- diff --git a/docs/Intro/Quick-Start.rst b/docs/Intro/Quick-Start.rst index f721004..00ac650 100644 --- a/docs/Intro/Quick-Start.rst +++ b/docs/Intro/Quick-Start.rst @@ -48,7 +48,7 @@ To facilitate uniform processing, ABL Kit provides the ``BasicNN`` class to conv .. code:: python import torch - from abl.learning import BasicNN + from ablkit.learning import BasicNN loss_fn = torch.nn.CrossEntropyLoss() optimizer = torch.optim.RMSprop(cls.parameters(), lr=0.001) @@ -59,7 +59,7 @@ The base model built above is trained to make predictions on instance-level data .. code:: python - from abl.learning import ABLModel + from ablkit.learning import ABLModel model = ABLModel(base_model) @@ -72,7 +72,7 @@ To build the reasoning part, we first define a knowledge base by creating a subc .. code:: python - from abl.reasoning import KBBase + from ablkit.reasoning import KBBase class AddKB(KBBase): def __init__(self, pseudo_label_list=list(range(10))): @@ -89,7 +89,7 @@ In such scenarios, the reasoner can minimize inconsistency and return the pseudo .. code:: python - from abl.reasoning import Reasoner + from ablkit.reasoning import Reasoner reasoner = Reasoner(kb) @@ -102,7 +102,7 @@ ABL Kit provides two basic metrics, namely ``SymbolAccuracy`` and ``ReasoningMet .. code:: python - from abl.data.evaluation import ReasoningMetric, SymbolAccuracy + from ablkit.data.evaluation import ReasoningMetric, SymbolAccuracy metric_list = [SymbolAccuracy(), ReasoningMetric(kb=kb)] @@ -115,7 +115,7 @@ Now, we use ``SimpleBridge`` to combine learning and reasoning in a unified ABL .. code:: python - from abl.bridge import SimpleBridge + from ablkit.bridge import SimpleBridge bridge = SimpleBridge(model, reasoner, metric_list) diff --git a/docs/Intro/Reasoning.rst b/docs/Intro/Reasoning.rst index 217acb3..ee0595c 100644 --- a/docs/Intro/Reasoning.rst +++ b/docs/Intro/Reasoning.rst @@ -22,7 +22,7 @@ In ABL Kit, building the reasoning part involves two steps: .. code:: python - from abl.reasoning import KBBase, GroundKB, PrologKB, Reasoner + from ablkit.reasoning import KBBase, GroundKB, PrologKB, Reasoner Building a knowledge base ------------------------- diff --git a/docs/index.rst b/docs/index.rst index f176f7f..2785955 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -32,11 +32,11 @@ :maxdepth: 1 :caption: API - API/abl.data - API/abl.learning - API/abl.reasoning - API/abl.bridge - API/abl.utils + API/ablkit.data + API/ablkit.learning + API/ablkit.reasoning + API/ablkit.bridge + API/ablkit.utils .. toctree:: :maxdepth: 1 diff --git a/examples/hed/bridge.py b/examples/hed/bridge.py index 0706786..82ab177 100644 --- a/examples/hed/bridge.py +++ b/examples/hed/bridge.py @@ -4,13 +4,13 @@ from typing import Any, List, Optional, Tuple, Union import torch -from abl.bridge import SimpleBridge -from abl.data.evaluation import BaseMetric -from abl.data.structures import ListData -from abl.learning import ABLModel, BasicNN -from abl.learning.torch_dataset import RegressionDataset -from abl.reasoning import Reasoner -from abl.utils import print_log +from ablkit.bridge import SimpleBridge +from ablkit.data.evaluation import BaseMetric +from ablkit.data.structures import ListData +from ablkit.learning import ABLModel, BasicNN +from ablkit.learning.torch_dataset import RegressionDataset +from ablkit.reasoning import Reasoner +from ablkit.utils import print_log from datasets import get_pretrain_data from models.nn import SymbolNetAutoencoder diff --git a/examples/hed/consistency_metric.py b/examples/hed/consistency_metric.py index 48f0a5e..f49bb2f 100644 --- a/examples/hed/consistency_metric.py +++ b/examples/hed/consistency_metric.py @@ -1,8 +1,8 @@ from typing import Optional -from abl.data.evaluation.base_metric import BaseMetric -from abl.data.structures import ListData -from abl.reasoning import KBBase +from ablkit.data.evaluation.base_metric import BaseMetric +from ablkit.data.structures import ListData +from ablkit.reasoning import KBBase class ConsistencyMetric(BaseMetric): diff --git a/examples/hed/hed.ipynb b/examples/hed/hed.ipynb index befea83..f74f03a 100644 --- a/examples/hed/hed.ipynb +++ b/examples/hed/hed.ipynb @@ -24,8 +24,8 @@ "import torch\n", "import torch.nn as nn\n", "\n", - "from abl.learning import ABLModel, BasicNN\n", - "from abl.utils import ABLLogger, print_log\n", + "from ablkit.learning import ABLModel, BasicNN\n", + "from ablkit.utils import ABLLogger, print_log\n", "\n", "from bridge import HedBridge\n", "from consistency_metric import ConsistencyMetric\n", diff --git a/examples/hed/main.py b/examples/hed/main.py index d66d197..226ba3a 100644 --- a/examples/hed/main.py +++ b/examples/hed/main.py @@ -4,8 +4,8 @@ import os.path as osp import torch import torch.nn as nn -from abl.learning import ABLModel, BasicNN -from abl.utils import ABLLogger, print_log +from ablkit.learning import ABLModel, BasicNN +from ablkit.utils import ABLLogger, print_log from bridge import HedBridge from consistency_metric import ConsistencyMetric diff --git a/examples/hed/reasoning/reasoning.py b/examples/hed/reasoning/reasoning.py index 02910ef..1d27763 100644 --- a/examples/hed/reasoning/reasoning.py +++ b/examples/hed/reasoning/reasoning.py @@ -3,8 +3,8 @@ import os import numpy as np -from abl.reasoning import PrologKB, Reasoner -from abl.utils import reform_list +from ablkit.reasoning import PrologKB, Reasoner +from ablkit.utils import reform_list CURRENT_DIR = os.path.abspath(os.path.dirname(__file__)) diff --git a/examples/hwf/hwf.ipynb b/examples/hwf/hwf.ipynb index aaf15f3..3e9b4d5 100644 --- a/examples/hwf/hwf.ipynb +++ b/examples/hwf/hwf.ipynb @@ -25,11 +25,11 @@ "import torch\n", "import torch.nn as nn\n", "\n", - "from abl.bridge import SimpleBridge\n", - "from abl.data.evaluation import ReasoningMetric, SymbolAccuracy\n", - "from abl.learning import ABLModel, BasicNN\n", - "from abl.reasoning import KBBase, Reasoner\n", - "from abl.utils import ABLLogger, print_log\n", + "from ablkit.bridge import SimpleBridge\n", + "from ablkit.data.evaluation import ReasoningMetric, SymbolAccuracy\n", + "from ablkit.learning import ABLModel, BasicNN\n", + "from ablkit.reasoning import KBBase, Reasoner\n", + "from ablkit.utils import ABLLogger, print_log\n", "\n", "from datasets import get_dataset\n", "from models.nn import SymbolNet" @@ -235,7 +235,7 @@ "metadata": {}, "outputs": [], "source": [ - "from abl.data.structures import ListData\n", + "from ablkit.data.structures import ListData\n", "\n", "# ListData is a data structure provided by ABL Kit that can be used to organize data examples\n", "data_examples = ListData()\n", diff --git a/examples/hwf/main.py b/examples/hwf/main.py index f8e10d9..4787aca 100644 --- a/examples/hwf/main.py +++ b/examples/hwf/main.py @@ -5,11 +5,11 @@ import numpy as np import torch from torch import nn -from abl.bridge import SimpleBridge -from abl.data.evaluation import ReasoningMetric, SymbolAccuracy -from abl.learning import ABLModel, BasicNN -from abl.reasoning import GroundKB, KBBase, Reasoner -from abl.utils import ABLLogger, print_log +from ablkit.bridge import SimpleBridge +from ablkit.data.evaluation import ReasoningMetric, SymbolAccuracy +from ablkit.learning import ABLModel, BasicNN +from ablkit.reasoning import GroundKB, KBBase, Reasoner +from ablkit.utils import ABLLogger, print_log from datasets import get_dataset from models.nn import SymbolNet diff --git a/examples/mnist_add/main.py b/examples/mnist_add/main.py index 025f9d4..41b9d02 100644 --- a/examples/mnist_add/main.py +++ b/examples/mnist_add/main.py @@ -5,11 +5,11 @@ import torch from torch import nn from torch.optim import RMSprop, lr_scheduler -from abl.bridge import SimpleBridge -from abl.data.evaluation import ReasoningMetric, SymbolAccuracy -from abl.learning import ABLModel, BasicNN -from abl.reasoning import GroundKB, KBBase, PrologKB, Reasoner -from abl.utils import ABLLogger, print_log +from ablkit.bridge import SimpleBridge +from ablkit.data.evaluation import ReasoningMetric, SymbolAccuracy +from ablkit.learning import ABLModel, BasicNN +from ablkit.reasoning import GroundKB, KBBase, PrologKB, Reasoner +from ablkit.utils import ABLLogger, print_log from datasets import get_dataset from models.nn import LeNet5 diff --git a/examples/mnist_add/mnist_add.ipynb b/examples/mnist_add/mnist_add.ipynb index e178914..4202c99 100644 --- a/examples/mnist_add/mnist_add.ipynb +++ b/examples/mnist_add/mnist_add.ipynb @@ -25,11 +25,11 @@ "import torch.nn as nn\n", "from torch.optim import RMSprop, lr_scheduler\n", "\n", - "from abl.bridge import SimpleBridge\n", - "from abl.data.evaluation import ReasoningMetric, SymbolAccuracy\n", - "from abl.learning import ABLModel, BasicNN\n", - "from abl.reasoning import KBBase, Reasoner\n", - "from abl.utils import ABLLogger, print_log\n", + "from ablkit.bridge import SimpleBridge\n", + "from ablkit.data.evaluation import ReasoningMetric, SymbolAccuracy\n", + "from ablkit.learning import ABLModel, BasicNN\n", + "from ablkit.reasoning import KBBase, Reasoner\n", + "from ablkit.utils import ABLLogger, print_log\n", "\n", "from datasets import get_dataset\n", "from models.nn import LeNet5" @@ -280,7 +280,7 @@ } ], "source": [ - "from abl.data.structures import ListData\n", + "from ablkit.data.structures import ListData\n", "\n", "# ListData is a data structure provided by ABL Kit that can be used to organize data examples\n", "data_examples = ListData()\n", diff --git a/examples/zoo/kb.py b/examples/zoo/kb.py index 86b1886..9a08077 100644 --- a/examples/zoo/kb.py +++ b/examples/zoo/kb.py @@ -1,7 +1,7 @@ import openml from z3 import If, Implies, Int, Not, Solver, Sum, sat # noqa: F401 -from abl.reasoning import KBBase +from ablkit.reasoning import KBBase class ZooKB(KBBase): diff --git a/examples/zoo/main.py b/examples/zoo/main.py index 3ecd856..3b5158a 100644 --- a/examples/zoo/main.py +++ b/examples/zoo/main.py @@ -4,11 +4,11 @@ import os.path as osp import numpy as np from sklearn.ensemble import RandomForestClassifier -from abl.bridge import SimpleBridge -from abl.data.evaluation import ReasoningMetric, SymbolAccuracy -from abl.learning import ABLModel -from abl.reasoning import Reasoner -from abl.utils import ABLLogger, avg_confidence_dist, print_log, tab_data_to_tuple +from ablkit.bridge import SimpleBridge +from ablkit.data.evaluation import ReasoningMetric, SymbolAccuracy +from ablkit.learning import ABLModel +from ablkit.reasoning import Reasoner +from ablkit.utils import ABLLogger, avg_confidence_dist, print_log, tab_data_to_tuple from get_dataset import load_and_preprocess_dataset, split_dataset from kb import ZooKB diff --git a/examples/zoo/zoo.ipynb b/examples/zoo/zoo.ipynb index e84a89d..bca0e43 100644 --- a/examples/zoo/zoo.ipynb +++ b/examples/zoo/zoo.ipynb @@ -23,11 +23,11 @@ "import numpy as np\n", "from sklearn.ensemble import RandomForestClassifier\n", "\n", - "from abl.bridge import SimpleBridge\n", - "from abl.data.evaluation import ReasoningMetric, SymbolAccuracy\n", - "from abl.learning import ABLModel\n", - "from abl.reasoning import Reasoner\n", - "from abl.utils import ABLLogger, avg_confidence_dist, print_log, tab_data_to_tuple\n", + "from ablkit.bridge import SimpleBridge\n", + "from ablkit.data.evaluation import ReasoningMetric, SymbolAccuracy\n", + "from ablkit.learning import ABLModel\n", + "from ablkit.reasoning import Reasoner\n", + "from ablkit.utils import ABLLogger, avg_confidence_dist, print_log, tab_data_to_tuple\n", "\n", "from get_dataset import load_and_preprocess_dataset, split_dataset\n", "from kb import ZooKB" diff --git a/tests/conftest.py b/tests/conftest.py index 2b71466..29cdafb 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -5,9 +5,9 @@ import torch import torch.nn as nn import torch.optim as optim -from abl.data.structures import ListData -from abl.learning import BasicNN -from abl.reasoning import GroundKB, KBBase, PrologKB, Reasoner +from ablkit.data.structures import ListData +from ablkit.learning import BasicNN +from ablkit.reasoning import GroundKB, KBBase, PrologKB, Reasoner class LeNet5(nn.Module): diff --git a/tests/test_abl_model.py b/tests/test_abl_model.py index c9e256e..1b0fa57 100644 --- a/tests/test_abl_model.py +++ b/tests/test_abl_model.py @@ -3,7 +3,7 @@ from unittest.mock import Mock, create_autospec import numpy as np import pytest -from abl.learning import ABLModel +from ablkit.learning import ABLModel class TestABLModel(object): diff --git a/tests/test_reasoning.py b/tests/test_reasoning.py index 04b1f84..fa96dce 100644 --- a/tests/test_reasoning.py +++ b/tests/test_reasoning.py @@ -2,7 +2,7 @@ import numpy as np import platform import pytest -from abl.reasoning import PrologKB, Reasoner +from ablkit.reasoning import PrologKB, Reasoner class TestKBBase(object):