You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

Learning.rst 1.7 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. Build the machine learning part
  2. ===============================
  3. First, we build the machine learning part, which needs to be wrapped in the ``ABLModel`` class. We can use machine learning models from scikit-learn or based on PyTorch to create an instance of ``ABLModel``.
  4. - for a scikit-learn model, we can directly use the model to create an instance of ``ABLModel``. For example, we can customize our machine learning model by
  5. .. code:: python
  6. # Load a scikit-learn model
  7. base_model = sklearn.neighbors.KNeighborsClassifier(n_neighbors=3)
  8. model = ABLModel(base_model)
  9. - for a PyTorch-based neural network, we first need to encapsulate it within a ``BasicNN`` object and then use this object to instantiate an instance of ``ABLModel``. For example, we can customize our machine learning model by
  10. .. code:: python
  11. # Load a PyTorch-based neural network
  12. cls = torchvision.models.resnet18(pretrained=True)
  13. # criterion and optimizer are used for training
  14. criterion = torch.nn.CrossEntropyLoss()
  15. optimizer = torch.optim.Adam(cls.parameters())
  16. base_model = BasicNN(cls, criterion, optimizer)
  17. model = ABLModel(base_model)
  18. In the MNIST Add example, the machine learning model looks like
  19. .. code:: python
  20. cls = LeNet5(num_classes=10)
  21. device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
  22. criterion = torch.nn.CrossEntropyLoss()
  23. optimizer = torch.optim.Adam(cls.parameters(), lr=0.001, betas=(0.9, 0.99))
  24. base_model = BasicNN(
  25. cls,
  26. criterion,
  27. optimizer,
  28. device=device,
  29. batch_size=32,
  30. num_epochs=1,
  31. )
  32. model = ABLModel(base_model)

An efficient Python toolkit for Abductive Learning (ABL), a novel paradigm that integrates machine learning and logical reasoning in a unified framework.