From 67fcac93d66e6e7749d4dbf57b2a669c0feab898 Mon Sep 17 00:00:00 2001 From: troyyyyy Date: Thu, 28 Dec 2023 09:13:57 +0800 Subject: [PATCH 1/9] [ENH] add quick start in readme --- README.md | 120 ++++++++++++++++++++++++++++++++++--- docs/Intro/Quick-Start.rst | 11 ++-- 2 files changed, 118 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 2965999..95a01e5 100644 --- a/README.md +++ b/README.md @@ -27,22 +27,22 @@ To learn how to use it, please refer to - [document](https://www.lamda.nju.edu.c ABL is distributed on [PyPI](https://pypi.org/) and can be installed with ``pip``: ```bash - # (TODO) - $ pip install abl +# (TODO) +$ pip install abl ``` For testing purposes, you can install it using: ```bash - $ pip install -i https://test.pypi.org/simple/ --extra-index-url https://mirrors.nju.edu.cn/pypi/web/simple/ abl +$ pip install -i https://test.pypi.org/simple/ --extra-index-url https://mirrors.nju.edu.cn/pypi/web/simple/ abl ``` - + Alternatively, to install ABL by source code, sequentially run following commands in your terminal/command line. ```bash - $ git clone https://github.com/AbductiveLearning/ABL-Package.git - $ cd ABL-Package - $ pip install -v -e . +$ git clone https://github.com/AbductiveLearning/ABL-Package.git +$ cd ABL-Package +$ pip install -v -e . ``` (Optional) If the use of a [Prolog-based knowledge base](https://www.lamda.nju.edu.cn/abl_test/docs/build/html/Intro/Reasoning.html#prolog) is necessary, the installation of [Swi-Prolog](https://www.swi-prolog.org/) is also required: @@ -50,7 +50,7 @@ Alternatively, to install ABL by source code, sequentially run following command For Linux users: ```bash - $ sudo apt-get install swi-prolog +$ sudo apt-get install swi-prolog ``` For Windows and Mac users, please refer to the [Swi-Prolog Download Page](https://www.swi-prolog.org/Download.html). @@ -64,3 +64,107 @@ We provide several examples in `examples/`. Each example is stored in a separate + [Hand written Equation Decipherment](https://github.com/AbductiveLearning/ABL-Package/tree/Dev/examples/hed) + [Zoo](https://github.com/AbductiveLearning/ABL-Package/tree/Dev/examples/zoo) +## A Simple Example + +We use the MNIST Addition task as a quick start example. In this task, pairs of MNIST handwritten images and their sums are given, alongwith a domain knowledge base which contain information on how to perform addition operations. Our objective is to input a pair of handwritten images and accurately determine their sum. + +### Working with Data + + +ABL-Package requires data in the format of `(X, gt_pseudo_label, Y)` where `X` is a list of input examples containing instances, `gt_pseudo_label` is the ground-truth label of each example in `X` and `Y` is the ground-truth reasoning result of each example in `X`. Note that `gt_pseudo_label` is only used to evaluate the machine learning model's performance but not to train it. + +In the MNIST Addition task, the data loading looks like: + +```python +# The 'datasets' module below is located in 'examples/mnist_add/' +from datasets import get_dataset + +# train_data and test_data are tuples in the format (X, gt_pseudo_label, Y) +# If get_pseudo_label is set to False, the gt_pseudo_label in each tuple will be None. +train_data = get_dataset(train=True, get_pseudo_label=True) +test_data = get_dataset(train=False, get_pseudo_label=True) +``` + +### Building the Learning Part + +Learning part is constructed by first defining a base model for machine learning. The ABL-Package offers considerable flexibility, supporting any base model that conforms to the scikit-learn style (which requires the implementation of fit and predict methods), or a PyTorch-based neural network (which has defined the architecture and implemented forward method). In this example, we build a simple LeNet5 network as the base model. + +```python +# The 'models' module below is located in 'examples/mnist_add/' +from models.nn import LeNet5 + +cls = LeNet5(num_classes=10) +``` + +To facilitate uniform processing, ABL-Package provides the `BasicNN` class to convert a PyTorch-based neural network into a format compatible with scikit-learn models. To construct a `BasicNN` instance, aside from the network itself, we also need to define a loss function, an optimizer, and the computing device. + +```python +​import torch +​from abl.learning import BasicNN +​ +​loss_fn = torch.nn.CrossEntropyLoss() +​optimizer = torch.optim.RMSprop(cls.parameters(), lr=0.001, alpha=0.9) +​device = torch.device("cuda" if torch.cuda.is_available() else "cpu") +​base_model = BasicNN(model=cls, loss_fn=loss_fn, optimizer=optimizer, device=device) +``` + +The base model built above are 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 +​ +​model = ABLModel(base_model) +``` + +### Building the Reasoning Part + +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 +​ +class AddKB(KBBase): + def __init__(self, pseudo_label_list=list(range(10))): + super().__init__(pseudo_label_list) + +​ def logic_forward(self, nums): + return sum(nums) +​ +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 +​ +reasoner = Reasoner(kb) +``` + +### Building Evaluation Metrics + +ABL-Package 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 +​ +metric_list = [SymbolAccuracy(prefix="mnist_add"), ReasoningMetric(kb=kb, prefix="mnist_add")] +``` + +### Bridging Learning and Reasoning + +Now, we use `SimpleBridge` to combine learning and reasoning in a +unified ABL framework. + +```python +from abl.bridge import SimpleBridge +​ +bridge = SimpleBridge(model, reasoner, metric_list) +``` + +Finally, we proceed with training and testing. + +```python +​bridge.train(train_data, loops=1) +bridge.test(test_data) +``` \ No newline at end of file diff --git a/docs/Intro/Quick-Start.rst b/docs/Intro/Quick-Start.rst index 58b4745..a186371 100644 --- a/docs/Intro/Quick-Start.rst +++ b/docs/Intro/Quick-Start.rst @@ -15,12 +15,13 @@ Working with Data ----------------- ABL-Package requires data in the format of ``(X, gt_pseudo_label, Y)`` where ``X`` is a list of input examples containing instances, -``gt_pseudo_label`` is the ground-truth label of each example in ``X`` and ``Y`` is the ground-truth reasoning result of each example in ``X``. Note that ``gt_pseudo_label`` is only used to evaluate the machine learning model's performance but not to train it. If examples in ``X`` are unlabeled, ``gt_pseudo_label`` should be ``None``. +``gt_pseudo_label`` is the ground-truth label of each example in ``X`` and ``Y`` is the ground-truth reasoning result of each example in ``X``. Note that ``gt_pseudo_label`` is only used to evaluate the machine learning model's performance but not to train it. In the MNIST Addition task, the data loading looks like .. code:: python + # The 'datasets' module below is located in 'examples/mnist_add/' from datasets import get_dataset # train_data and test_data are tuples in the format (X, gt_pseudo_label, Y) @@ -33,14 +34,14 @@ Read more about `preparing datasets `_. Building the Learning Part -------------------------- -Learnig part is constructed by first defining a base model for machine learning. The ABL-Package offers considerable flexibility, supporting any base model that conforms to the scikit-learn style (which requires the implementation of ``fit`` and ``predict`` methods), or a PyTorch-based neural network (which has defined the architecture and implemented ``forward`` method). +Learning part is constructed by first defining a base model for machine learning. The ABL-Package offers considerable flexibility, supporting any base model that conforms to the scikit-learn style (which requires the implementation of ``fit`` and ``predict`` methods), or a PyTorch-based neural network (which has defined the architecture and implemented ``forward`` method). In this example, we build a simple LeNet5 network as the base model. .. code:: python + # The 'models' module below is located in 'examples/mnist_add/' from models.nn import LeNet5 - # The number of pseudo-labels is 10 cls = LeNet5(num_classes=10) To facilitate uniform processing, ABL-Package provides the ``BasicNN`` class to convert a PyTorch-based neural network into a format compatible with scikit-learn models. To construct a ``BasicNN`` instance, aside from the network itself, we also need to define a loss function, an optimizer, and the computing device. @@ -51,7 +52,7 @@ To facilitate uniform processing, ABL-Package provides the ``BasicNN`` class to from abl.learning import BasicNN loss_fn = torch.nn.CrossEntropyLoss() - optimizer = torch.optim.RMSprop(cls.parameters(), lr=0.001, alpha=0.9) + optimizer = torch.optim.RMSprop(cls.parameters(), lr=0.001) device = torch.device("cuda" if torch.cuda.is_available() else "cpu") base_model = BasicNN(model=cls, loss_fn=loss_fn, optimizer=optimizer, device=device) @@ -123,7 +124,7 @@ Finally, we proceed with training and testing. .. code:: python - bridge.train(train_data, loops=1, segment_size=0.01) + bridge.train(train_data, loops=1) bridge.test(test_data) Read more about `bridging machine learning and reasoning `_. From a95963ab4cbcb79f6e443b7466252024cabbab9d Mon Sep 17 00:00:00 2001 From: troyyyyy Date: Thu, 28 Dec 2023 09:19:41 +0800 Subject: [PATCH 2/9] [ENH] simplify quick start --- README.md | 7 +++---- docs/Intro/Quick-Start.rst | 7 +++---- examples/mnist_add/datasets/get_dataset.py | 2 +- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 95a01e5..37d013c 100644 --- a/README.md +++ b/README.md @@ -80,9 +80,8 @@ In the MNIST Addition task, the data loading looks like: from datasets import get_dataset # train_data and test_data are tuples in the format (X, gt_pseudo_label, Y) -# If get_pseudo_label is set to False, the gt_pseudo_label in each tuple will be None. -train_data = get_dataset(train=True, get_pseudo_label=True) -test_data = get_dataset(train=False, get_pseudo_label=True) +train_data = get_dataset(train=True) +test_data = get_dataset(train=False) ``` ### Building the Learning Part @@ -148,7 +147,7 @@ ABL-Package provides two basic metrics, namely `SymbolAccuracy` and `ReasoningMe ```python from abl.data.evaluation import ReasoningMetric, SymbolAccuracy ​ -metric_list = [SymbolAccuracy(prefix="mnist_add"), ReasoningMetric(kb=kb, prefix="mnist_add")] +metric_list = [SymbolAccuracy(), ReasoningMetric(kb=kb)] ``` ### Bridging Learning and Reasoning diff --git a/docs/Intro/Quick-Start.rst b/docs/Intro/Quick-Start.rst index a186371..5c2f1a4 100644 --- a/docs/Intro/Quick-Start.rst +++ b/docs/Intro/Quick-Start.rst @@ -25,9 +25,8 @@ In the MNIST Addition task, the data loading looks like from datasets import get_dataset # train_data and test_data are tuples in the format (X, gt_pseudo_label, Y) - # If get_pseudo_label is set to False, the gt_pseudo_label in each tuple will be None. - train_data = get_dataset(train=True, get_pseudo_label=True) - test_data = get_dataset(train=False, get_pseudo_label=True) + train_data = get_dataset(train=True) + test_data = get_dataset(train=False) Read more about `preparing datasets `_. @@ -105,7 +104,7 @@ ABL-Package provides two basic metrics, namely ``SymbolAccuracy`` and ``Reasonin from abl.data.evaluation import ReasoningMetric, SymbolAccuracy - metric_list = [SymbolAccuracy(prefix="mnist_add"), ReasoningMetric(kb=kb, prefix="mnist_add")] + metric_list = [SymbolAccuracy(), ReasoningMetric(kb=kb)] Read more about `building evaluation metrics `_ diff --git a/examples/mnist_add/datasets/get_dataset.py b/examples/mnist_add/datasets/get_dataset.py index c6d84a9..53423da 100644 --- a/examples/mnist_add/datasets/get_dataset.py +++ b/examples/mnist_add/datasets/get_dataset.py @@ -5,7 +5,7 @@ from torchvision.transforms import transforms CURRENT_DIR = os.path.abspath(os.path.dirname(__file__)) -def get_dataset(train=True, get_pseudo_label=False): +def get_dataset(train=True, get_pseudo_label=True): transform = transforms.Compose( [transforms.ToTensor(), transforms.Normalize((0.1307,), (0.3081,))] ) From b8e09e8eed0214b1efe73c5611a5e51d561ab4fd Mon Sep 17 00:00:00 2001 From: troyyyyy Date: Thu, 28 Dec 2023 09:21:26 +0800 Subject: [PATCH 3/9] [FIX] fix typo --- README.md | 2 +- docs/Intro/Quick-Start.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 37d013c..af49c3a 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ In the MNIST Addition task, the data loading looks like: # The 'datasets' module below is located in 'examples/mnist_add/' from datasets import get_dataset -# train_data and test_data are tuples in the format (X, gt_pseudo_label, Y) +# train_data and test_data are tuples in the format of (X, gt_pseudo_label, Y) train_data = get_dataset(train=True) test_data = get_dataset(train=False) ``` diff --git a/docs/Intro/Quick-Start.rst b/docs/Intro/Quick-Start.rst index 5c2f1a4..68feddf 100644 --- a/docs/Intro/Quick-Start.rst +++ b/docs/Intro/Quick-Start.rst @@ -24,7 +24,7 @@ In the MNIST Addition task, the data loading looks like # The 'datasets' module below is located in 'examples/mnist_add/' from datasets import get_dataset - # train_data and test_data are tuples in the format (X, gt_pseudo_label, Y) + # train_data and test_data are tuples in the format of (X, gt_pseudo_label, Y) train_data = get_dataset(train=True) test_data = get_dataset(train=False) From dac0a89fbf087a856197b64b066f87ef2302ec4a Mon Sep 17 00:00:00 2001 From: troyyyyy Date: Thu, 28 Dec 2023 09:23:09 +0800 Subject: [PATCH 4/9] [FIX] fix typo --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index af49c3a..8d5c1b8 100644 --- a/README.md +++ b/README.md @@ -61,10 +61,10 @@ We provide several examples in `examples/`. Each example is stored in a separate + [MNIST Addition](https://github.com/AbductiveLearning/ABL-Package/blob/Dev/examples/mnist_add) + [Hand Written Formula](https://github.com/AbductiveLearning/ABL-Package/blob/Dev/examples/hwf) -+ [Hand written Equation Decipherment](https://github.com/AbductiveLearning/ABL-Package/tree/Dev/examples/hed) ++ [Hand Written Equation Decipherment](https://github.com/AbductiveLearning/ABL-Package/tree/Dev/examples/hed) + [Zoo](https://github.com/AbductiveLearning/ABL-Package/tree/Dev/examples/zoo) -## A Simple Example +## Quick Start We use the MNIST Addition task as a quick start example. In this task, pairs of MNIST handwritten images and their sums are given, alongwith a domain knowledge base which contain information on how to perform addition operations. Our objective is to input a pair of handwritten images and accurately determine their sum. From e48f9909fbb8c712c6452945805cad7d367b34d9 Mon Sep 17 00:00:00 2001 From: troyyyyy Date: Thu, 28 Dec 2023 09:25:09 +0800 Subject: [PATCH 5/9] [FIX] change name of examples in readme --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8d5c1b8..0c65208 100644 --- a/README.md +++ b/README.md @@ -60,9 +60,9 @@ For Windows and Mac users, please refer to the [Swi-Prolog Download Page](https: We provide several examples in `examples/`. Each example is stored in a separate folder containing a README file. + [MNIST Addition](https://github.com/AbductiveLearning/ABL-Package/blob/Dev/examples/mnist_add) -+ [Hand Written Formula](https://github.com/AbductiveLearning/ABL-Package/blob/Dev/examples/hwf) -+ [Hand Written Equation Decipherment](https://github.com/AbductiveLearning/ABL-Package/tree/Dev/examples/hed) -+ [Zoo](https://github.com/AbductiveLearning/ABL-Package/tree/Dev/examples/zoo) ++ [Handwritten Formula](https://github.com/AbductiveLearning/ABL-Package/blob/Dev/examples/hwf) ++ [Handwritten Equation Decipherment](https://github.com/AbductiveLearning/ABL-Package/tree/Dev/examples/hed) ++ [Zoo](https://gitub.com/AbductiveLearning/ABL-Package/tree/Dev/examples/zoo) ## Quick Start From 9eb45ca077ef00d681b8ea947df7f1bc9ee46345 Mon Sep 17 00:00:00 2001 From: Tony-HYX <605698554@qq.com> Date: Thu, 28 Dec 2023 10:18:09 +0800 Subject: [PATCH 6/9] [DOC] Minor changes --- README.md | 2 +- docs/README.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0c65208..412025a 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ where both data and (logical) domain knowledge are available. Key Features of ABL-Package: -- **Great Flexibility**: Adaptable to a variety of machine learning modules and logical reasoning components. +- **Great Flexibility**: Adaptable to various machine learning modules and logical reasoning components. - **User-Friendly**: Provide data, model, and KB, and get started with just a few lines of code. - **High-Performance**: Optimization for high accuracy and fast training speed. diff --git a/docs/README.rst b/docs/README.rst index 1287302..7b7248b 100644 --- a/docs/README.rst +++ b/docs/README.rst @@ -8,7 +8,7 @@ where both data and (logical) domain knowledge are available. Key Features of ABL-Package: -- **Great Flexibility**: Adaptable to a variety of machine learning modules and logical reasoning components. +- **Great Flexibility**: Adaptable to various machine learning modules and logical reasoning components. - **User-Friendly**: Provide data, model, and KB, and get started with just a few lines of code. - **High-Performance**: Optimization for high accuracy and fast training speed. From 828bbe5ed24940e8f88d4f18b4ec34fd8c4e6423 Mon Sep 17 00:00:00 2001 From: Tony-HYX <605698554@qq.com> Date: Thu, 28 Dec 2023 10:32:52 +0800 Subject: [PATCH 7/9] [DOC] minior changes --- README.md | 4 ++-- docs/README.rst | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 412025a..e3636b3 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,8 @@ Key Features of ABL-Package: - **High-Performance**: Optimization for high accuracy and fast training speed. ABL-Package encapsulates advanced ABL techniques, providing users with -an efficient and convenient package to develop dual-driven ABL systems -that leverage both data and knowledge. +an efficient and convenient package to develop dual-driven ABL systems, +which leverage the power of both data and knowledge. To learn how to use it, please refer to - [document](https://www.lamda.nju.edu.cn/abl_test/docs/build/html/Overview/Abductive-Learning.html). diff --git a/docs/README.rst b/docs/README.rst index 7b7248b..e036557 100644 --- a/docs/README.rst +++ b/docs/README.rst @@ -13,8 +13,8 @@ Key Features of ABL-Package: - **High-Performance**: Optimization for high accuracy and fast training speed. ABL-Package encapsulates advanced ABL techniques, providing users with -an efficient and convenient package to develop dual-driven ABL systems -that leverage both data and knowledge. +an efficient and convenient package to develop dual-driven ABL systems, +which leverage the power of both data and knowledge. .. image:: _static/img/ABL.png From dff232e20ad11361146ab32461d6a39d0f05a2b1 Mon Sep 17 00:00:00 2001 From: troyyyyy Date: Thu, 28 Dec 2023 10:43:40 +0800 Subject: [PATCH 8/9] [FIX] change name of examples in readme --- examples/hed/main.py | 4 ++-- examples/hwf/main.py | 6 +++--- examples/mnist_add/main.py | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/examples/hed/main.py b/examples/hed/main.py index c672765..f4e7564 100644 --- a/examples/hed/main.py +++ b/examples/hed/main.py @@ -35,12 +35,12 @@ def main(): "--batch-size", type=int, default=32, help="base model batch size (default : 32)" ) parser.add_argument( - "--segment_size", type=int or float, default=1000, help="segment size (default : 1000)" + "--segment_size", type=int, default=1000, help="segment size (default : 1000)" ) parser.add_argument("--save_interval", type=int, default=1, help="save interval (default : 1)") parser.add_argument( "--max-revision", - type=int or float, + type=int, default=10, help="maximum revision in reasoner (default : 10)", ) diff --git a/examples/hwf/main.py b/examples/hwf/main.py index 328e849..963fa15 100644 --- a/examples/hwf/main.py +++ b/examples/hwf/main.py @@ -87,19 +87,19 @@ def main(): "--loops", type=int, default=5, help="number of loop iterations (default : 5)" ) parser.add_argument( - "--segment_size", type=int or float, default=1000, help="segment size (default : 1000)" + "--segment_size", type=int, default=1000, help="segment size (default : 1000)" ) parser.add_argument("--save_interval", type=int, default=1, help="save interval (default : 1)") parser.add_argument( "--max-revision", - type=int or float, + type=int, default=-1, help="maximum revision in reasoner (default : -1)", ) parser.add_argument( "--require-more-revision", type=int, - default=5, + default=0, help="require more revision in reasoner (default : 0)", ) parser.add_argument( diff --git a/examples/mnist_add/main.py b/examples/mnist_add/main.py index ab1fa98..b74b82e 100644 --- a/examples/mnist_add/main.py +++ b/examples/mnist_add/main.py @@ -53,12 +53,12 @@ def main(): "--loops", type=int, default=2, help="number of loop iterations (default : 2)" ) parser.add_argument( - "--segment_size", type=int or float, default=0.01, help="segment size (default : 0.01)" + "--segment_size", type=int, default=0.01, help="segment size (default : 0.01)" ) parser.add_argument("--save_interval", type=int, default=1, help="save interval (default : 1)") parser.add_argument( "--max-revision", - type=int or float, + type=int, default=-1, help="maximum revision in reasoner (default : -1)", ) From c72ac8870a48041e02455abf83988cbe60b71649 Mon Sep 17 00:00:00 2001 From: troyyyyy Date: Thu, 28 Dec 2023 10:43:52 +0800 Subject: [PATCH 9/9] [ENH] add references in readme --- README.md | 12 ++++++++---- docs/Examples/MNISTAdd.rst | 2 +- docs/Intro/Quick-Start.rst | 2 +- docs/README.rst | 6 ++++++ 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index e3636b3..e24b6ce 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ ABL-Package encapsulates advanced ABL techniques, providing users with an efficient and convenient package to develop dual-driven ABL systems, which leverage the power of both data and knowledge. -To learn how to use it, please refer to - [document](https://www.lamda.nju.edu.cn/abl_test/docs/build/html/Overview/Abductive-Learning.html). +To learn how to use it, please refer to - [document](https://www.lamda.nju.edu.cn/abl_test/docs/build/html/index.html). ## Installation @@ -62,7 +62,7 @@ We provide several examples in `examples/`. Each example is stored in a separate + [MNIST Addition](https://github.com/AbductiveLearning/ABL-Package/blob/Dev/examples/mnist_add) + [Handwritten Formula](https://github.com/AbductiveLearning/ABL-Package/blob/Dev/examples/hwf) + [Handwritten Equation Decipherment](https://github.com/AbductiveLearning/ABL-Package/tree/Dev/examples/hed) -+ [Zoo](https://gitub.com/AbductiveLearning/ABL-Package/tree/Dev/examples/zoo) ++ [Zoo](https://github.com/AbductiveLearning/ABL-Package/tree/Dev/examples/zoo) ## Quick Start @@ -164,6 +164,10 @@ bridge = SimpleBridge(model, reasoner, metric_list) Finally, we proceed with training and testing. ```python -​bridge.train(train_data, loops=1) +​bridge.train(train_data, loops=1, segment_size=0.01) bridge.test(test_data) -``` \ No newline at end of file +``` + +## References + +For more information about ABL, please refer to: [Zhou, 2019](https://link.springer.com/epdf/10.1007/s11432-018-9801-4?author_access_token=jgJe1Ox3Mk-K7ORSnX7jtfe4RwlQNchNByi7wbcMAY7_PxTx-xNLP7Lp0mIZ04ORp3VG4wioIBHSCIAO3B_TBJkj87YzapmdnYVSQvgBIO3aEpQWppxZG25KolINetygc2W_Cj2gtoBdiG_J1hU3pA==) and [Zhou and Huang, 2022](https://www.lamda.nju.edu.cn/publication/chap_ABL.pdf). \ No newline at end of file diff --git a/docs/Examples/MNISTAdd.rst b/docs/Examples/MNISTAdd.rst index c038349..c05fd85 100644 --- a/docs/Examples/MNISTAdd.rst +++ b/docs/Examples/MNISTAdd.rst @@ -376,6 +376,6 @@ Out: abl - INFO - Eval start: loop(val) [1] abl - INFO - Evaluation ended, mnist_add/character_accuracy: 0.986 mnist_add/reasoning_accuracy: 0.973 abl - INFO - Saving model: loop(save) [1] - abl - INFO - Checkpoints will be saved to results/20231222_22_25_07/weights/model_checkpoint_loop_1.pth + abl - INFO - Checkpoints will be saved to log_dir/weights/model_checkpoint_loop_1.pth abl - INFO - Test start: abl - INFO - Evaluation ended, mnist_add/character_accuracy: 0.983 mnist_add/reasoning_accuracy: 0.967 diff --git a/docs/Intro/Quick-Start.rst b/docs/Intro/Quick-Start.rst index 68feddf..658e0ba 100644 --- a/docs/Intro/Quick-Start.rst +++ b/docs/Intro/Quick-Start.rst @@ -123,7 +123,7 @@ Finally, we proceed with training and testing. .. code:: python - bridge.train(train_data, loops=1) + bridge.train(train_data, loops=1, segment_size=0.01) bridge.test(test_data) Read more about `bridging machine learning and reasoning `_. diff --git a/docs/README.rst b/docs/README.rst index e036557..09280d0 100644 --- a/docs/README.rst +++ b/docs/README.rst @@ -52,3 +52,9 @@ For Linux users: $ sudo apt-get install swi-prolog For Windows and Mac users, please refer to the `Swi-Prolog Download Page `_. + +References +---------- + +For more information about ABL, please refer to: `Zhou, 2019 `_ +and `Zhou and Huang, 2022 `_. \ No newline at end of file