MNIST Add was first introduced in [1] and the inputs of this task are pairs of MNIST images and the outputs are their sums. The dataset looks like this:
MNIST Addition was first introduced in [1] and the inputs of this task are pairs of MNIST images and the outputs are their sums. The dataset looks like this:
All scikit-learn models satisify this requiremnts, so we can directly use the model to create an instance of ``ABLModel``. For example, we can customize our machine learning model by
All scikit-learn models satisify this requirements, so we can directly use the model to create an instance of ``ABLModel``. For example, we can customize our machine learning model by
.. code:: python
@@ -36,6 +36,7 @@ For a PyTorch-based neural network, we first need to encapsulate it within a ``B
ABL-Package assumes data to be in the form of ``(X, gt_pseudo_label, Y)`` where ``X`` is the input of the machine learning model,
``gt_pseudo_label`` is the ground truth label of each element in ``X`` and ``Y`` is the ground truth reasoning result of each instance in ``X``.
In the MNIST Add task, the data loading looks like
In the MNIST Addition task, the data loading looks like
.. code:: python
@@ -72,10 +72,10 @@ ABL-Package offers several `dataset classes <../API/abl.dataset.html>`_ for diff
Read more about `preparing datasets <Datasets.html>`_.
Building the Machine Learning Part
Building the Learning Part
----------------------------------
To build the machine learning part, we need to wrap our machine learning model into the ``ABLModel`` class. The machine learning model can either be a scikit-learn model or a PyTorch neural network. We use a simple LeNet5 in the MNIST Add example.
To build the machine learning part, we need to wrap our machine learning model into the ``ABLModel`` class. The machine learning model can either be a scikit-learn model or a PyTorch neural network. We use a simple LeNet5 in the MNIST Addition example.
.. code:: python
@@ -141,24 +141,17 @@ function specifying how to perform (deductive) reasoning.
return sum(nums)
kb = AddKB(pseudo_label_list=list(range(10)))
print(kb)
Out:
.. code-block:: none
AddKB is a KB with pseudo_label_list=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], max_err=1e-10, use_cache=True.
Then, we create a reasoner by defining an instance of class
``ReasonerBase`` and passing the knowledge base as an parameter.
``Reasoner`` and passing the knowledge base as an parameter.
The reasoner can be used to minimize inconsistencies between the
knowledge base and the prediction from the learning part.
.. code:: python
from abl.reasoning import ReasonerBase
from abl.reasoning import Reasoner
reasoner = ReasonerBase(kb)
reasoner = Reasoner(kb)
Read more about `building the reasoning part <Reasoning.html>`_.
@@ -168,7 +161,7 @@ Building Evaluation Metrics
ABL-Package provides two basic metrics, namely ``SymbolMetric`` and ``SemanticsMetric``, which are used to evaluate the accuracy of the machine learning model's predictions and the accuracy of the ``logic_forward`` results, respectively.
In the case of MNIST Add example, the metric definition looks like
In the case of MNIST Addition example, the metric definition looks like
.. code:: python
@@ -178,10 +171,10 @@ In the case of MNIST Add example, the metric definition looks like
Read more about `building evaluation metrics <Evaluation.html>`_
Bridging Machine Learning and Reasoning
Bridging Learning and Reasoning
---------------------------------------
Now, we use ``SimpleBridge`` to combine machine learning and reasoning together.
Now, we use ``SimpleBridge`` to combine learning and reasoning in a unified model.
.. code:: python
@@ -189,7 +182,7 @@ Now, we use ``SimpleBridge`` to combine machine learning and reasoning together.