将逻辑推理融入神经网络,用可微逻辑公式实现知识驱动学习。
LTNtorch: PyTorch Implementation of Logic Tensor Networks
- 用模糊逻辑构建可微分的逻辑计算图,支持梯度下降优化。
- 通过三步流程:公式实例化、评估与损失计算、反向传播更新参数。
- 提供完整PyTorch实现与二分类示例,适合研究神经符号系统者。
逻辑张量网络(LTN)是一种神经符号框架,能有效融合深度学习与逻辑推理。它允许定义逻辑知识库,并将其作为神经模型的目标函数。通过最小化由表达学习任务事实的逻辑公式构成的损失函数,使模型参数在梯度下降下优化,从而实现基于逻辑的推理学习。该框架利用模糊逻辑——一种允许[0,1]区间连续真值的经典逻辑松弛——使学习成为可能。具体训练包含三步:首先,使用训练数据对公式进行实例化;其次,评估公式并计算损失函数;最后,通过逻辑计算图反向传播梯度,调整神经模型权重以最大化知识库的满足度。LTNtorch是完全文档化且经过测试的PyTorch实现。本文阐述了LTN的形式化及其在LTNtorch中的实现方式,并提供了一个基础的二分类示例。
原文摘要 · Abstract (English)
Logic Tensor Networks (LTN) is a Neuro-Symbolic framework that effectively incorporates deep learning and logical reasoning. In particular, LTN allows defining a logical knowledge base and using it as the objective of a neural model. This makes learning by logical reasoning possible as the parameters of the model are optimized by minimizing a loss function composed of a set of logical formulas expressing facts about the learning task. The framework learns via gradient-descent optimization. Fuzzy logic, a relaxation of classical logic permitting continuous truth values in the interval [0,1], makes this learning possible. Specifically, the training of an LTN consists of three steps. Firstly, (1) the training data is used to ground the formulas. Then, (2) the formulas are evaluated, and the loss function is computed. Lastly, (3) the gradients are back-propagated through the logical computational graph, and the weights of the neural model are changed so the knowledge base is maximally satisfied. LTNtorch is the fully documented and tested PyTorch implementation of Logic Tensor Networks. This paper presents the formalization of LTN and how LTNtorch implements it. Moreover, it provides a basic binary classification example.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。