\section{Introduction}
\label{sec:introduction}

Deep Neural Networks~\citep{lecun2015deep} have been a break-through for several classification problems involving sequential or high-dimensional data. 
However, deep neural architectures strongly rely on a large amount of labeled data to develop powerful feature representations.
Unfortunately, it is difficult and labor intensive to annotate large collections of data. Prior knowledge based on First-Order Logic (FOL)
represents a natural solution to make learning efficient when the training data is scarce and some additional knowledge is available.
The integration of logic inference with learning could also overcome another limitation of deep architectures, which is that they mainly act as black-boxes from a human perspective, making their usage challenging in failure critical applications.
For these reasons, neural-symbolic approaches~\citep{de2020statistical,garcez2019neural} integrating logic and learning have recently gained a lot of attention in the machine learning and artificial intelligence communities.
One of the most common approaches to integrate a deep learner with logic relies on the relaxation of the FOL knowledge to a differentiable form using t-norms. Then, the resulting constraints can be enforced using gradient-based optimization techniques~\citep{diligenti2017semantic,donadello2017logic}. However, most work in this area approached the problem of translating rules expressed by logic into a differentiable form as a collection of heuristics, that often lack consistency and have no clear justification from a theoretical point of view. For example, there is no agreement about the relation between the selected t-norm and the aggregation performed to express quantification.


In this paper, we show how  the mere selection of a \textit{t-norm generator} leads to the full specification of the cost function of a complex learning problem, where both data and logic background knowledge is available. The translations of the logic connectives, the quantifiers and the final loss implementing the constraints are shown to be univocally determined by the generator choice. This leads to a principled and semantically consistent translation. Moreover, the classical fitting of the training data, common to all supervised learning schemes,  becomes a special case of a logic constraint. Since a careful choice of the loss function has been pivotal into the success of deep learning, the paper also investigates the relation between the supervised fitting loss and the generator choice.
Indeed, when restricted to simple supervised learning, the presented theoretical apparatus provides a clean justification to the popular cross-entropy loss~\citep{goodfellow2016deep}, that has been shown to provide faster convergence and to reduce the vanishing gradient problem in very deep structures.
Finally, the experimental results show that, when integrating logic knowledge, a careful choice of the generator can both provide a faster convergence speed of the training process and a better final accuracy, following from having preserved the semantics of the prior knowledge. While these results can be applied to any neural-symbolic learning task, the theory suggests also the definition of new loss functions for supervised learning, which are potentially more effective than the cross-entropy to limit the vanishing gradient issue.

The paper is organized as follows: Section~\ref{sec:related_works} presents some prior work on the integration of learning and logic inference, Section~\ref{sec:FL} presents the basic concepts about t-norms, generators and aggregator functions and Section~\ref{sec:nsl} introduces a general neural-symbolic framework used to extend supervised learning with logic rules.
Section \ref{sec:Lgen} presents the main results of this paper, showing the link between t-norm generators and loss functions and how these can be exploited in neural-symbolic approaches. Section~\ref{sec:exp} presents the experimental results and, finally, Section~\ref{sec:conc} draws some conclusions.





\section{Related Works}
\label{sec:related_works}
Neural-symbolic approaches~\citep{besold2017neural,garcez2012neural} aim at combining symbolic reasoning into (deep) neural networks. Logic is exploited to express the learner  internal structure (e.g. by templating the network architecture) or output structure (e.g. by constructing loss terms). First-Order Logic (FOL) is often selected as the declarative framework for the knowledge because of its flexibility and expressive power.
Neural-symbolic methodologies are rooted in previous work from the Statistical Relational Learning community~\citep{raedt2016statistical,de2020statistical}, which developed frameworks for performing logic inference in the presence of uncertainty. For example, Markov Logic Networks~\citep{richardson2006markov} and Probabilistic Soft Logic~\citep{bach2017hinge} integrate First-Order Logic and probabilistic graphical models.
A common solution to integrate logic reasoning with uncertainty and deep learning relies on using deep neural networks to approximate the truth values (i.e. fuzzy semantics) or the probabilities (i.e. probabilistic semantics) of predicates. The overall architecture is then differentiable and can be  optimized end-to-end.  This approach is followed with minor variants by Semantic-Based Regularization~\citep{diligenti2017semantic}, the Lyrics framework~\citep{marra2019lyrics}, Logic Tensor Networks~\citep{donadello2017logic} for classification approaches.
For neuro-symbolic approaches based on probabilistic logic, this methodology is followed by the works like Semantic Loss~\citep{xu2017semantic}, Differentiable Reasoning~\citep{van2019semi}, Relational Neural Machines~\citep{marra2020relational} and DeepProbLog~\citep{manhaeve2018deepproblog}.

When exploiting a fuzzy semantics to relax the logic, it is of fundamental importance to define how to perform the relaxation of the formulas in the knowledge base.
For instance, \citet{serafini2017learning} introduces a learning framework where formulas are converted according to \L ukasiewicz logic t-norm and t-conorms. \citet{giannini2018convex} also proposes to convert the formulas according to \L ukasiewicz logic, however this paper exploits the weak conjunction in place of the t-norms to get convex functional constraints. A more practical approach has been considered in Semantic-Based Regularization (SBR), where all the fundamental t-norms have been evaluated on different learning tasks~\citep{diligenti2017semantic}.
The work by \citet{van2019differentiable} exploits a combination of logical operators to get the most significant performance improvement.

However, in spite of the extensive prior work in this area, it has not emerged an unified principle to express the cost function to be optimized in terms of fuzzy logic theory. In particular, all the aforementioned approaches rely on a fixed loss function linearly measuring the distance of the formulas from the 1-value. Even if it may be justified from a logical point of view, as the strong logical negation is defined as $\neg x=1-x$, it is not clear whether this choice is principled from a learning standpoint, since all deep learning approaches use very different loss functions to enforce the fitting of the supervised data.
From a learning point of view, different quantifier conversions can be taken into account and validated, as well. For instance, the arithmetic mean and maximum operator have been used to convert the universal and existential quantifiers in \citet{diligenti2017semantic}, respectively. Different possibilities have been considered for the universal quantifier in \citet{donadello2017logic}, while the existential quantifier depends on this choice via the application of the strong negation using the DeMorgan law. The Arithmetic mean operator has been shown to achieve better performances in the conversion of the universal quantifier~\citep{donadello2017logic}, with
the existential quantifier implemented by Skolemization. However, the universal and existential quantifiers can be thought of as a generalized AND and OR, respectively. Therefore, converting the quantifiers using a mean operator has no direct justification inside a logic theory.

This paper extends the preliminary formalization sketched by \citet{giannini2019relation}, together with a more comprehensive experimental validation.

\section{Background on T-Norm Fuzzy Logic}
\label{sec:FL}
Many-valued logics have been introduced in order to extend the admissible set of truth values from \emph{true} ($1$), \emph{false} ($0$) to a scale of truth-degree having \emph{absolutely true} and \emph{absolutely false} as boundary cases. In particular, in fuzzy logic the set of truth values coincides with the real unit interval $[0,1]$.
In this section, the basic notions of fuzzy logic together with some remarkable examples are introduced. According to \citet{hajek2013metamathematics}, a fuzzy logic can be defined upon a certain \emph{t-norm} (triangular norm) representing an extension of the Boolean conjunction. 
\begin{definition}[t-norm]\label{def:tnorm}
	$T:[0,1]^2\to[0,1]$ is a t-norm if and only if for every $x,y,z\in[0,1]$:
	\[
	\begin{array}{cc}
	T(x,y)=T(y,x), & T(x,T(y,z))=T(T(x,y),z),\\
	T(x,1)=x, & T(x,0)=0, \\
	\multicolumn{2}{c}{x\leq y\quad \longrightarrow\quad T(x,z)\leq T(y,z) \ .}
	\end{array}
	\]
	$T$ is a continuous t-norm if it is continuous as function.
\end{definition}
Table~\ref{tab:fuzzySem} reports the algebraic definition of t-norms and other logical operators definable by the chosen t-norm for G\"{o}del, \L ukasiewicz and Product logics respectively, which are referred as the fundamental fuzzy logics because all the continuous t-norms can be obtained from them by ordinal sums~\citep{mostert1957structure,jenei2002note}. The notation of the logical operators in Table~\ref{tab:fuzzySem} is given by the following definitions according to a certain t-norm $T$:
\begin{definition}[definable connectives from a t-norm]\label{def:conn}
	\[
	\begin{array}{lr}
	(\mbox{t-norm}) &  x\otimes y = T(x,y)\\
	(\mbox{residual-impl}) &  x\Rightarrow y = \max\{z:\,x\otimes z\leq y\} \\
	(\mbox{bi-residuum}) & x\Leftrightarrow y = (x\Rightarrow y)\otimes(y\Rightarrow x)\\
	(\mbox{weak-conj}) & x\wedge y =x\otimes (x\Rightarrow y) \\ 
	(\mbox{weak-disj}) & x\vee y \!=\! ((x\!\Rightarrow\! y)\Rightarrow y)\otimes((y\Rightarrow x)\Rightarrow x) \\ 
	(\mbox{residual-neg}) & \sim x = x\Rightarrow0 \\ 
	(\mbox{strong-neg}) & \neg x = 1-x \\ 
	(\mbox{t-conorm}) & x\oplus y = \neg( \neg x\otimes\neg y) \\ 
	(\mbox{material-impl}) & x\rightarrow y = \neg x\oplus y 
	\end{array}
	\]
\end{definition}



\begin{table}[tb]
	\small
	\centering
	\begin{tabular}{|c|c|c|c|}
		\hline
		& G\"{o}del & \L ukasiewicz & Product \\
		\hline
		\hline
		$x\otimes y$ & $\min\{x,y\}$ & $\max\{0,x+y-1\}$ & $x\cdot y$ \\
		\hline
		$x\Rightarrow y$ & $x\leq y?1:y$ & $\min\{1,1-x+y\}$ & $x\leq y?1:\frac{y}{x}$ \\
		\hline
		$x\Leftrightarrow y$ & $x\leq y?x:y$ & $1-|x-y|$ &
		$x=y?1:\min\{\frac{x}{y},\frac{y}{x}\}$
		\\
		\hline
		$x\wedge y$ & $\min\{x,y\}$ & $\min\{x,y\}$ & $\min\{x,y\}$ \\
		\hline
		$x\vee y$ & $\max\{x,y\}$ & $\max\{x,y\}$ & $\max\{x,y\}$ \\
		\hline
		$\sim x$ & $x=0?1:0$ & $1-x$ & $x=0?1:0$ \\
		\hline
		$\neg x$ & $1-x$ & $1-x$ & $1-x$ \\
		\hline
		$x \oplus y$ & $\max\{x,y\}$ & $\min\{1,x+y\}$ & $x+y-x\cdot y$ \\
		\hline
		$x \rightarrow y$ & $\max\{1-x,y\}$ & $\min\{1,1-x+y\}$ & $1-x+x\cdot y$ \\
		\hline
	\end{tabular}
\vspace{0.1cm}
	\caption[Truth Functions for the Fundamental Fuzzy Logics]{The truth functions for the residuum, bi-residuum, weak conjunction, weak disjunction, residual negation, strong neation, t-conorms and material implication of the fundamental fuzzy logics.}
	\label{tab:fuzzySem}
\end{table}


\subsection{Archimedean T-Norms}
\label{sec:gent-norm}

In mathematics, t-norms \citep{klement2004triangular1,klement2013triangular} are a special kind of binary operations on the real unit interval $[0, 1]$ especially used in engineering applications of fuzzy logic. Table~\ref{tab:fuzzySem} reports the fundamental continuous t-norms, however in the literature a wide class of t-norms has been considered. In addition, there are several techniques to construct customized t-norms that are more suitable to deal with a certain problem by rotations or ordinal sums of other t-norms or defining parametric classes. This section introduces \emph{Archimedean} t-norms~\citep{klement2004triangular3}, a special class of t-norms that can be constructed by means of unary monotone functions, called \emph{generators}.

\begin{definition}
	A t-norm $T$ is said to be \emph{Archimedean} if for every $x\in(0,1)$, $T(x,x)<x$. In addition, $T$ is said \emph{strict} if for all $x\in(0,1)$, $0<T(x,x)<x$ otherwise is said \emph{nilpotent}.
\end{definition}
For instance, the \L ukasiewicz  ($T_L$) and Product ($T_P$) t-norms are respectively nilpotent and strict, while the G\"{o}del ($T_G$) t-norm is not archimedean, indeed it is \emph{idempotent} ($T_G(x,x)=x$, for all $x\in[0,1]$).
In addition, \L ukasiewicz and Product t-norms are enough to represent the whole classes of nilpotent and strict Archimedean t-norms \citep{klement2013triangular}.

\begin{theorem}
	Any nilpotent t-norm is isomorphic to $T_L$ and any strict t-norm is isomorphic to $T_P$.
\end{theorem}

A fundamental result for the construction of t-norms by \emph{additive generators} is based on the following theorem \citep{klement2004triangular2}.
\begin{theorem}
	Let $g:[0,1]\to[0,+\infty]$ be a strictly decreasing function with $g(1)=0$  and $g(x)+g(y)\in Range(g)\cup[g(0^+),+\infty]$ for all $x, y$ in $[0, 1]$, and $g^{(-1)}$ its pseudo-inverse. Then the function $T:[0,1]\to[0,1]$ defined as
	\begin{equation}\label{eq:t-normgen}
	T(x,y)=g^{-1}\left(\min\{g(0^+),g(x)+g(y)\}\right) \ .
	\end{equation}
	is a t-norm and $g$ is said an \emph{additive generator} for $T$. $T$ is strict if $g(0^+)=+\infty$, otherwise $T$ is nilpotent. .
\end{theorem}

\begin{example}
	If we take $g(x)=1-x$, we get $T_L$
	\[
	T(x,y)=1-\min\{1,1-x+1-y\}=\max\{0,x+y-1\} \ ,
	\]
	while taking $g(x)=-\log(x)$, we get $T_P$
	\[
	T(x,y)=\exp\big( -(\min\{+\infty,-\log(x)-\log(y)\}) \big) = x\cdot y \ .
	\]
\end{example}
An interesting consequence of equation (\ref{eq:t-normgen}) is that it allows us to define also the other fuzzy connectives, deriving from the t-norm, as depending on the additive generator. For instance: 
\begin{eqnarray}\label{eq:genres}
x\Rightarrow y &=& g^{-1}\left(\max\{0,g(y)-g(x)\}\right) \nonumber\\ 
x\Leftrightarrow y &=& g^{-1}\left(|g(x)-g(y)|\right) \\
x\oplus y &=& 1-g^{-1}\left(\min\{g(0^+),g(1-x)+g(1-y)\}\right) \nonumber
\end{eqnarray}

\subsection{Parameterized classes of t-norms}
Given a generator of a t-norm depending on a certain parameter, we can define a class of related t-norms depending on such parameter. For instance, given a generator function $g$ of a t-norm $T$ and $\lambda>0$, then $T^{\lambda}$, corresponding to the generator function $g^{\lambda}(x)=(g(x))^{\lambda}$ denotes a class of increasing t-norms. In addition, let $T_D$  and $T_G$ denote the \emph{Drastic} (defined by $T_D(x,y)=(x=y=1)?1:0$) and G\"{o}del t-norms respectively, we get:
\[
\lim_{\lambda\rightarrow0^+}T^{\lambda}=T_D\qquad\mbox{and}\qquad \lim_{\lambda\rightarrow\infty}T^{\lambda}=T_M  \ .
\]

On the other hand, several parameterized families of t-norms have been introduced and studied in the literature \citep{klement2013triangular}. In the following we recall some prominent examples we will exploit in the experimental evaluation.

\begin{definition}[The Schweizer-Sklar family]
	\label{ex:ss}
	For $\lambda\in(-\infty,+\infty)$, consider:
	\[
	g_{\lambda}^{SS}(x)=
	\left\{
	\begin{array}{lr}
	-\log(x) & \mbox{if }\lambda=0 \\
	\frac{1-x^{\lambda}}{\lambda} & \mbox{otherwise.}
	\end{array}
	\right.
	\]
	The t-norms corresponding to this generator are called  Schweizer-Sklar t-norms, and they are defined according to:
	\[
	T_{\lambda}^{SS}(x,y)=
	\left\{
	\begin{array}{lr}
	T_G(x,y) & \mbox{if }\lambda=-\infty \\
	(x^{\lambda}+y^{\lambda}-1)^{\frac{1}{\lambda}} & \mbox{if }-\infty<\lambda<0 \\
	T_P(x,y) & \mbox{if }\lambda=0 \\
	\max\{0,x^{\lambda}+y^{\lambda}-1\}^{\frac{1}{\lambda}} & \mbox{if }0<\lambda<+\infty \\
	T_D(x,y) & \mbox{if }\lambda=+\infty
	\end{array}
	\right.
	\]
	A Schweizer-Sklar t-norm $T_{\lambda}^{SS}$ is \emph{Archimedean} if and only if $\lambda>-\infty$, \emph{continuous} if and only if $\lambda<+\infty$, \emph{strict} if and only if  $-\infty<\lambda\leq 0$ and \emph{nilpotent} if and only if $\, 0<\lambda<+\infty$. This t-norm family is strictly decreasing for $\lambda\geq0$ and continuous with respect to $\lambda\in[-\infty,+\infty]$, in addition $T_1^{SS}=T_L$.
\end{definition}

\begin{definition}[Frank t-norms]
	\label{ex:frank}
	For $\lambda\in[0,+\infty]$, consider: 
	\[
	g_{\lambda}^F(x)=
	\left\{
	\begin{array}{lr}
	-\log(x) & \mbox{if }\lambda=1 \\
	1-x & \mbox{if }\lambda=+\infty \\
	\log(\frac{\lambda-1}{\lambda^x-1}) & \mbox{otherwise.}
	\end{array}
	\right.
	\] 
	The t-norms corresponding to this generator are called  Frank t-norms and they are strict if $\lambda<+\infty$. The overall class of Frank t-norms is decreasing and continuous.
	\[
	T_{\lambda}^F(x,y)=
	\left\{
	\begin{array}{lr}
	T_G & \mbox{if }\lambda=0\\
	T_P & \mbox{if }\lambda=1\\
	T_L & \mbox{if }\lambda=+\infty\\
	\log_{\lambda}\left(1+\frac{(\lambda^x-1)(\lambda^y-1)}{\lambda-1}\right) & \mbox{otherwise.}
	\end{array}
	\right.
	\]
\end{definition}

\section{Background on the Integration of Learning and Logic Reasoning}
\label{sec:nsl}
According to the \emph{learning from constraints} paradigm~\citep{gnecco2015foundations},  knowledge is represented by a set of constraints and the learning process is conceived as the problem of finding the task functions (implementing FOL predicates) that best satisfy the constraints. 
In particular, many approaches express the supervisions as a special class of constraints forcing the fitting of the positive and negative examples for the task and the additional prior knowledge is expressed as a set of FOL formulas relaxed into continuous and differentiable constraints.
An example of extra prior knowledge that may be available about a learning task, could be a statement like \emph{``any pattern classified as a cat has to be classified as an animal''}, where \emph{cat} and \emph{animal} have to be thought of as the membership functions of two classes to learn. In such a sense, symbolic logic provides a natural way to express factual and abstract knowledge about a problem by means of logical formulas. 
A large class of methodologies falls in this bucket like Probabilistic Soft Logic~\citep{bach2017hinge} or neural-symbolic approaches like Semantic Based Regularization~\citep{diligenti2017semantic}, Logic Tensor Networks~\citep{donadello2017logic}, Semantic Loss~\citep{xu2017semantic}.

Let us consider a multi-task learning problem, where $\bm p=(p_1,\ldots,p_J)$ denotes the vector of real-valued functions (\emph{task functions}) to be determined, where $J$ is the number of tasks.
Given the set $\mathcal{X}\subseteq\mathbb{R}^n$ of available data, a supervised learning problem can be generally formulated as
$
\min_{\bm p}\mathcal{L}(\mathcal{X},\bm p)
$
where $\mathcal{L}$ is a positive-valued functional denoting a certain loss.
In this framework, this setup is expanded assuming that the task functions are FOL predicates and all the available knowledge about these predicates, including supervisions, is collected into a knowledge base expressed via a set of $H$ FOL formulas $KB=\{\psi_1,\ldots,\psi_H\}$.
The learning task is generally expressed as:
$$
\min_{\bm p}\mathcal{L}(\mathcal{X}, KB, \bm p) \ .
$$

The link between FOL knowledge and learning was presented in \citet{marra2019lyrics} and it can be summarized as follows:
\begin{itemize}
	\item each \emph{Individual} is an element of a specific domain, which can be used to ground the predicates defined on such domain. Any replacement of variables with individuals for a certain predicate is called \emph{grounding}.
	\item 
	\emph{Predicates} express the truth degree of some property for an individual (unary predicate) or group of individuals (n-ary predicate). In particular, this paper will focus on learnable predicate functions implemented by (deep) neural networks, even if other models could be used. FOL functions can also be included by learning their approximation like done for predicates, however function-free FOL is used in the paper to keep the notation simple.
	\item The \emph{knowledge base} (KB) is a collection of FOL formulas expressing the learning task. The integration of learning and logical reasoning is achieved by compiling the logical rules into continuous real-valued constraints, which correlate all the defined elements and enforce some desired behaviour on them.
\end{itemize}

For a given rule in the KB, individuals, predicates, logical connectives and quantifiers can all be seen as nodes of an \textit{expression tree}~\citep{diligenti2018delbp}.
The translation to a constraint corresponds to a post-fix visit of the expression tree, where the visit action builds the correspondent portion of computational graph. In particular:
\begin{itemize}
	\item visiting a \textit{variable} substitutes the variable with the corresponding feature representation of the individual to which the variable is currently assigned;
	\item visiting a \textit{predicate} computes the output of the predicate with the current input groundings;
	\item visiting a \textit{connective} combines the grounded predicate values by means of the real-valued operations associated to the connective;
	\item visiting a \textit{quantifier} aggregates the outputs of the expressions obtained for the single individuals (variable groundings).
\end{itemize}

Thus, the compilation of the expression tree allows us to convert formulas into real-valued functions, represented by a computational graph, where predicate functions are composed by means of the truth-functions corresponding to connectives and quantifiers. Given a generic formula $\varphi$, we call the corresponding real-valued function its \textit{functional representation} $f_\varphi$. This representation is tightly dependent on the particular choice of the translating t-norm. For instance, given two predicates $p_1,p_2$ and the formula $\varphi(x)=p_1(x)\Rightarrow p_2(x)$, the functional representation of $\varphi$ in \L ukasiewicz logic is given by $f_{\varphi}(x, \bm p) =\min\{1,1-p_1(x)+p_2(x)\}$.

A special note concerns \emph{quantifiers} that have to be thought of as aggregating operators with respect to the predicate domains. For instance, according to  \citet{novak2012mathematical}, that first proposed a fuzzy generalization of first--order logic, the \emph{universal} and \emph{existential quantifiers} may be converted as the infimum and supremum over a domain variable (or minimum and maximum when dealing with finite domains) that are common to any t-norm fuzzy logic. In particular, given a formula $\varphi(x)$ depending on a certain variable $x\in\mathcal{X}$, where $\mathcal{X}$ denotes the available samples for one of the involved predicates in $\varphi$, the semantics of the quantifiers are fuzzified as:
\[
\begin{array}{ccc}
\psi = \forall x\, \varphi(x) &\longrightarrow& f_\psi(\mathcal{X}, \bm p) = \displaystyle\min_{x\in\mathcal{X}} f_{\varphi}(x,\bm p),\\
\psi = \exists x\, \varphi(x) &\longrightarrow& \displaystyle f_\psi(\mathcal{X}, \bm p) = \max_{x\in\mathcal{X}} f_{\varphi}(x,\bm p).
\end{array}
\]
As shown in the next section, this quantifier translation is not well justified for all t-norms and this paper provides a more principled approach to perform this translation.

Once all the formulas in $KB$ are converted into real-valued functions, their distance from satisfaction (i.e. distance from 1-evaluation) can be computed according to a certain decreasing mapping $L$ expressing the penalty for the violation of any constraint.
Assuming
rule independence, learning can be formulated as the joint minimization over the single rules using the following loss function factorization:
\begin{equation}\label{eq:loss}
\mathcal{L}(\mathcal{X},KB,\bm p) = \sum_{\psi \in KB} \beta_\psi L\big(f_\psi(\mathcal{X},\bm p)\big)
\end{equation}
where any $\beta_\psi$ denotes the weight for the logical constraint $\psi$ in the $KB$, which can be selected via cross-validation or jointly learned \citep{kolb2018learning,marra2019integrating},
$f_{\psi}$ is the functional representation of the formula $\psi$ according to a certain t-norm fuzzy logic and $L$ is a decreasing function denoting the penalty associated to the distance from satisfaction of formulas, so that $L(1)=0$. 
This paper will show that the selected semantics of the $f_\psi$ converting a generic formula $\psi$ and the choice of the $L$ loss are intrinsically connected, and they can be both derived by the selection of a t-norm generator.

\section{Loss Functions by T-Norms Generators}
\label{sec:Lgen}
This section presents an extension of the approach presented in \citet{giannini2019relation}, which was limited to supervised learning, to combine the fuzzy conversion of formulas and the penalty map according to a unified principle. In particular, we investigate the mapping of formulas into constraints by means of generated t-norm fuzzy logics, and we exploit the same additive generator of the t-norm to map the formulas to be satisfied into the functional constraints to be minimized, i.e. we consider $L=g$. Moreover, since the quantifiers can be seen as generalized AND and OR over the grounded expressions (see Remark \ref{re:quant}), we show that the same fuzzy conversion, so as the overall loss function, as expressed in Equation \ref{eq:loss}, only depends on the chosen t-norm generator. 
\begin{remark}\label{re:quant}
	Given a formula $\varphi(x)$ defined on $\mathcal{X}$, the role of the quantifiers have to be interpreted as follows,
	\[
	\begin{array}{c}
\forall x\, \varphi(x)\;\simeq\; \varphi(x_1)\mbox{ AND }\ldots\mbox{ AND }\varphi(x_N)\\
	\exists x\, \varphi(x)\;\simeq\; \varphi(x_1)\mbox{ OR }\ldots\mbox{ OR }\varphi(x_N)
	\end{array}
	\]
	where $\mathcal{X}=\{x_1,\ldots,x_N\}$ denotes the available samples.
\end{remark}
Given a certain formula $\varphi(x)$ depending on a variable $x$ that ranges in the set $\mathcal{X}$ and its corresponding functional representation $f_{\varphi}(x,\bm p)$, the conversion of any universal quantifier may be carried out by means of an Archimedean t-norm $T$, while the existential quantifier by a t-conorm. For instance, given
the formula $\psi=\forall x\,\varphi(x)$, we have: 
\begin{equation}\label{eq:constbygen}
f_{\psi}(\mathcal{X},\bm p) = g^{-1}\left(\min\left\{g(0^+),\sum_{x\in\mathcal{X}}g\big(f_{\varphi}(x,\bm p)\big)\right\}\right)
\end{equation}
where $g$ is an additive generator of the t-norm $T$.

Since any generator function is decreasing and $g(1)=0$, the generator function is a very natural choice to be used as loss $L$ which can be used to map the fuzzy conversion of the formula, as reported in Equation \ref{eq:constbygen}, in a constraint to be minimized. By exploiting the same generator of $T$ to map into a loss function, for $\psi=\forall x\,\varphi(x)$, we get the following term $L\big(f_\psi(\mathcal{X},\bm p)\big)$ to be minimized:
\begin{equation}
\begin{array}{c}
L\big(f_\psi(\mathcal{X},\bm p)\big) \!\!= \!\!\left\{
\begin{array}{ll}
\!\!\min\left\{g(0),\displaystyle\sum_{x\in\mathcal{X}}g(f_{\varphi}(x,\bm p))\right\}  & \!\!\mbox{$T$ nilpotent}\\
&\\
\!\!\displaystyle\sum_{x\in\mathcal{X}}g(f_{\varphi}(x,\bm p)) & \!\!\mbox{$T$ strict}
\end{array}
\right.
\end{array}
\label{eq:loss_form}
\end{equation}

As a consequence, the following result can be provided with respect to the convexity of the loss $L\big(f_\psi(\mathcal{X},\bm p)\big)$.
\begin{proposition}\label{prop:genconv}
	If $g$ is a linear function and $f_\psi$ is concave, $L\big(f_\psi(\mathcal{X},\bm p)\big)$ is convex. 
	If $g$ is a convex function and $f_\psi$ is linear, $L\big(f_\psi(\mathcal{X},\bm p)\big)$ is convex. 
\end{proposition}
\begin{proof}
	Both the arguments follow since if $f_{\psi}$ is concave (we recall that a linear function is both concave and convex, as well) and $g$ is a convex non-increasing function defined over a univariate domain, then $g\circ f_{\psi}$ is convex.
\end{proof}
Proposition \ref{prop:genconv} establishes a general criterion to define convex constraints according to a certain generator depending on the fuzzy conversion $f_{\psi}$ and, in turn, by the logical expression $\psi$.  In Example \ref{ex:conv} are reported some application cases.


\begin{example}\label{ex:conv}
	If $g(x)=1-x$ we get the \L ukasiewicz t-norm, that is nilpotent. Hence, from Equation \ref{eq:loss_form} we get:
	\[
	L\big(f_\psi(\mathcal{X},\bm p)\big) = \min\{1,\sum_{x\in\mathcal{X}}(1-(f_\varphi(x,\bm p)))\} \ .
	\]
	In case $f_\psi$ is concave~\citep{giannini2018convex}, this function is convex.
	
	If $g(x)=-\log(x)$ (Product t-norm) from Equation \ref{eq:loss_form} we get a generalization of the cross-entropy loss:
	\[
	L\big(f_\psi(\mathcal{X},\bm p)\big) = -\sum_{x\in\mathcal{X}}\log(f_\varphi(x)) \ .
	\]
	In case $f_\psi(x)$ is linear (e.g. a literal), this function is convex.
\end{example}

So far, we only considered the case of a general formula $\varphi$. In the following, different cases of interest for $\varphi$ are reported. Given an additive generator $g$ for a t-norm $T$, additional connectives may be expressed with respect to $T$, as reported e.g. by Equation \ref{eq:genres}.
If $p_1,p_2$ are two unary predicate functions sharing the same input domain $\mathcal{X}$, the following formulas yield the following penalty terms,
where we supposed $T$ strict for simplicity:
\[
\begin{array}{c}\label{eq:convFOLgen}
\forall x\,p_1(x) \longrightarrow  \displaystyle\sum_{x \in \mathcal{X}} g(p_1(x))\\
\forall x\,p_1(x)\Rightarrow p_2(x)  \longrightarrow \displaystyle \sum_{x \in \mathcal{X}} \max\{0, g(p_2(x))-g(p_1(x))\}
\\
\forall x\,p_1(x)\Leftrightarrow p_2(x) \longrightarrow \displaystyle \sum_{x \in \mathcal{X}} |g(p_1(x))-g(p_2(x))| 
\end{array}
\]

According to a certain generator, different loss functions may arise from the same FOL formula.
Further, one may think to consider customized loss components that are more suitable for a certain learning problem or exploiting the described construction to get already known machine learning loss, as for the cross-entropy loss (see Example \ref{ex:conv}).
\begin{example}
	If $g(x)=\frac{1}{x}-1$, with corresponding strict t-norm $T(x,y)=\frac{xy}{x+y-xy}$, the functional constraint \ref{eq:loss_form} that is obtained applying $g$ to the formula $\forall x\,p_1(x)\Rightarrow p_2(x)$ is given by
	\[
	L\big(f_\psi(\mathcal{X},\bm p)\big) = \sum_{x \in \mathcal{X}} \max\left\{0, \frac{1}{p_2(x)}-\frac{1}{p_1(x)}\right\} \ .
	\]
	While if $g(x)=1-x^2$, with corresponding nilpotent t-norm $T(x,y)=\min\{1,2-x^2-y^2\}$, the constraint is given by
	\[
	L\big(f_\psi(\mathcal{X},\bm p)\big)\! =\! \min\left\{ \! 1, \!\sum_{x \in \mathcal{X}} \max\left\{0, (p_1(x))^2-(p_2(x))^2\right\}\!\right\} \ .
	\]
\end{example}

\begin{table*}
	$
	\tiny
	\begin{array}{l}
	 \overbrace{g^{-1}\!\left(\!\sum_x g\!\left(\overbrace{g^{-1}\!\left(\!\max\!\left\{0,g(p_3(x))\!-\!g\left(\overbrace{g^{-1}(g(p_1(x))\!+\!g(p_2(x)))}^{conjunction}\right)\!\right\}\!\right)}^{implication}\!\right)\!\right)}^{quantifier} =\displaystyle g^{-1}\left(\sum_x \max\left\{0,g(p_3(x))-g(p_1(x))-g(p_2(x))\right\}\right)\\
	\\
    \end{array}
    $
    \caption{Conversion of the formula $\forall x\,p_1(x)\otimes p_2(x)\Rightarrow p_3(x)$ with respect to the selection of the strict t-norm generator $g$.}
    \label{tab:example_generator}
\end{table*}

An interesting property of this method consists in the fact that, in case of compound formulas, some occurrences of the generator may be simplified. 
For instance, Table~\ref{tab:example_generator} shows the conversion of the formula $\forall x\,p_1(x)\otimes p_2(x)\Rightarrow p_3(x)$ with respect to the selection of a strict t-norm generator $g$.

where the simplification expressed on the right side is general and can be applied for a wide range of logical operators.

However, this property does not hold for all the connectives that are definable upon a certain generated t-norm (see Definition \ref{def:conn}). For instance, $\forall x\;p_1(x)\oplus p_2(x)$ becomes:
\[
g^{-1}\Big(\sum_x g(1-g^{-1}(g(1-p_1(x))+g(1-p_2(x))))\Big)
\]
This suggests to identify the connectives that, on one hand allow the simplification of any occurrence of $g^{-1}$ by applying $g$ in its corresponding functional expression, and on the other hand allow the evaluation of $g$ only on grounded predicates. For short, in the following we say that the formulas build upon such connectives have the \emph{simplification property}.
\begin{lemma}
	Any formula $\varphi$, whose connectives are restricted to $\{\wedge,\vee,\otimes,\Rightarrow,\sim,\Leftrightarrow\}$, has the simplification property.
\end{lemma}
\begin{proof}
	The proof is by induction with respect to the number $l\geq0$ of connectives occurring in $\varphi$.
	\begin{itemize}
		\item If $l=0$, i.e. $\varphi=p_j(x_i)$ for a certain $j\leq J$, $x_i\in\mathcal{X}$; then $g(f_{\varphi})=g(p_j(x_i))$, hence $\varphi$ has the simplification property.
		\item If $l=k+1$, then $\varphi=(\alpha\circ\beta)$ for $\circ\in\{\wedge,\vee,\otimes,\Rightarrow,\sim,\Leftrightarrow\}$ and we have the following cases.
		\begin{itemize}
			\item If $\varphi=(\alpha\wedge\beta)$, then we get 
			$g(\min\{f_{\alpha},f_{\beta}\})=\max\{g(f_{\alpha}),g(f_{\beta})\}$
			and the claim follows by inductive hypothesis on $\alpha,\beta$ whose number of involved connectives is less or equal than $k$. The argument still holds replacing $\wedge$ with $\vee$ and $\min$ with $\max$.
			\item If $\varphi=(\alpha\otimes\beta)$, then we get 
			\[
			\begin{array}{l}
			g(g^{-1}(\min\{g(0^+),g(f_{\alpha})+g(f_{\beta})\})) = \\
			= \min\{g(0^+),g(f_{\alpha})+g(f_{\beta})\} \ .
			\end{array}
			\]
			As in the previous case, the claim follows by inductive hypothesis on $\alpha,\beta$.
			\item The remaining of the cases can be treated at the same way and noting that $\sim\alpha=\alpha\Rightarrow0$.
		\end{itemize}
	\end{itemize}
\end{proof}
The simplification property provides several advantages from an implementation point of view. On one hand it allows the evaluation of the generator function only on grounded predicate expressions and avoids an explicit computation of the pseudo-inverse $g^{-1}$. In addition, this property provides a general method to implement $n$-ary t-norms, of which universal quantifiers can be seen as a special case since we only deal with finite domains (see more in Section \ref{sec:discussion}). 

The simplification property yields an interesting analogy between truth functions and loss functions. In logic, the truth degree of a formula is obtained by combining the truth degree of its sub-formulas by means of connectives and quantifiers. At the same way, the loss corresponding to a formula that satisfies the property is obtained by combining the losses corresponding to its sub-formulas and connectives and quantifiers combine losses rather than truth degrees.

\subsection{Manifold Regularization: an example}
\label{sec:example}
Let us consider a simple multi-task classification problem where the objects $A,B$ must be detected in a set of input images $\mathcal{I}$, represented as a set of features.
The learning task consists in determining the predicates $p_A(i),p_B(i)$, which return true if and only if the input image $i$ is predicted to contain the object $A,B$, respectively.
The positive supervised examples are provided as two sets (or equivalently their membership functions) $P_A \subset \mathcal{I} , P_B \subset \mathcal{I}$ with the images known to contain the object $A,B$, respectively.
The negative supervised examples for $A,B$ are instead provided as two sets $N_A \subset \mathcal{I}, N_B \subset \mathcal{I}$.
Furthermore, the location where the images have been taken is assumed to be known, and a predicate $SameLoc(i_1, i_2)$ can be used to express the fact whether images $i_1,i_2$ have been taken in the same location. It is finally assumed that it is known as prior knowledge that two images taken in the same location are likely to contain the same object.  This knowledge about the environment can be enforced via \emph{Manifold Regularization}, which regularizes the classifier outputs over the manifold built by the image co-location defined via the $SameLoc$ predicate. 
\begin{table}[t]
	\centering










	\begin{tabular}{l}
		\hline
		$\forall i_1,i_2: SameLoc(i_1,i_2) \Rightarrow (p_A(i_1) \Leftrightarrow p_A(i_2))$\\
		$\forall i_1,i_2: SameLoc(i_1,i_2) \Rightarrow (p_B(i_1) \Leftrightarrow p_B(i_2))$\\
		$\forall i: (P_A(i) \Rightarrow p_A(i)) \land (N_A(i) \Rightarrow \lnot p_A(i))$\\
		$\forall i:(P_B(i) \Rightarrow p_B(i)) \land (N_B(i) \Rightarrow \lnot p_B(i))$\\
		$P_A(i10)=1, ~~ P_A(i101)=1, ~~N_B(i11)=1, ~~ P_B(i103)=1$\\
		$SameLoc(i23, i60)=1$\\
		\hline
	\end{tabular}
\vspace{0.1cm}
	\caption{Example of a learning task expressed using FOL.}
	\label{tab:dfl_example}
\end{table}
The semantics of the above learning task can be expressed using FOL via the statement declarations shown in
Table~\ref{tab:dfl_example}, where it was assumed that images $i23, i60$ have been taken in the same location and it holds that $P_A=\{i10,i101\}, ~P_B=\{i103\}, ~ N_A=\{i11\}$ and $N_B=\emptyset$.
The statements define the constraints that the learners must respect, expressed as FOL rules. Please note that also the fitting of the supervisions are expressed as constraints.

Given a selection of a strict t-norm generator $g$ and a set of images $I$, this FOL knowledge is compiled into the following optimization task:
\[
\begin{array}{ll}
\arg \displaystyle\min_{\bm p}
&\beta_1 \displaystyle\sum_{i \in P_A} g(p_A(i)) + \beta_2 \displaystyle\sum_{i \in N_A} g(1-p_A(i)) +\\
&\beta_3 \displaystyle\sum_{i \in P_B} g(p_B(i)) +\beta_4 \displaystyle\sum_{i \in N_B} g(1-p_B(i))+ \\
&\beta_5 \displaystyle\sum_{(i_1,i_2) \in I_{sl}} |g(p_A(i_1))-g(p_A(i_2))| +\\
&\beta_6 \displaystyle\sum_{(i_1,i_2) \in I_{sl}} |g(p_B(i_1))-g(p_B(i_2))|
\end{array}
\]
where $\beta_i$ is a meta-parameter deciding how strongly the $i$-th contribution should be weighted, $I_{sl}$ is the set of image pairs having the same location $I_{sl} = \{(i_1,i_2) : SameLoc(i_1,i_2)\}$ and the first two elements of the cost function express the fitting of the supervised data, while the latter two express the knowledge about co-located images.

\subsection{Discussion}
\label{sec:discussion}
The presented framework can be contextualized among a new class of learning frameworks, which exploit the continuous relaxation of FOL provided by fuzzy operators to integrate logic knowledge in the learning process \citep{diligenti2017semantic,serafini2016logic,marra2019lyrics}. All these frameworks require the user to define all the operators of a given t-norm fuzzy logic. On the other hand, the presented framework requires only the generator to be defined. This provides several advantages like a minimum \textit{implementation effort},  and an improved \textit{numerical stability}. Indeed, it is possible to apply the generator only on grounded atoms by exploiting the simplification property and this allows to apply the non-linear operation (generator) to the atoms, whereas all compositions are performed via stable operators (e.g. min,max,sum). On the contrary, the previous FOL relaxations correspond to an arbitrary mix of non-linear operators, which can potentially lead to numerically unstable implementations.

The presented framework provides a fundamental advantage in the integration with the tensor-based machine learning frameworks like TensorFlow~\citep{abadi2016tensorflow} or PyTorch~\citep{ketkar2017introduction}.
Modern deep learning architectures can be effectively trained by leveraging tensor operations performed via Graphics Processing Units (GPU). However, this ability is conditioned on the possibility of concisely express the operators in terms of simple parallelizable operations like sums or products over $n$ arguments, which are often implemented as atomic operation in GPU computing frameworks and do not require to resort to slow iterative procedures. Fuzzy logic operator can not be easily generalized to their $n$-ary form. For example, the \L ukasiewicz conjunction $T_L(x,y) = \max\{0,x+y-1\}$ can be generalized to $n$-ary form as $T_L(x_1,x_2, \dots, x_n) = \max\{0,\sum_{i=1}^n (x_i) - n + 1\}$. On the other hand, the general SS t-norm for $-\infty < \lambda < 0$, $T^{SS}_{\lambda}(x,y) = (x^\lambda + y^\lambda -1)^{\frac{1}{\lambda}}$, does not have any generalization and the implementation of the $n$-ary form must resort to an iterative application of the binary form, which is very inefficient in tensor-based computations. Previous frameworks like LTN and SBR had to limit the form of the formulas that can be expressed, or carefully select the t-norms in order to provide efficient $n$-ary implementations. However, the presented framework can express operators in $n$-ary form in terms of the generators. Thanks to the simplification property, $n$-ary operators for any Archimedean t-norm can always be expressed as $T(x_1, x_2, \dots, x_n) = g^{-1}(\sum_{i=1}^n g(x_i))$.

\section{Experimental Results}
\label{sec:exp}
The experimental results have been carried out using the \emph{Deep Fuzzy Logic} (DFL) software framework\footnote{\url{ http://sailab.diism.unisi.it/deep-logic-framework/}} which allows to express a learning task as a set of FOL formulas. The formulas are compiled into a learning task using the theory of generators described in the previous section. The learning task is then cast into an optimization problem like shown in Section~\ref{sec:example} and, finally, is solved via tensor propagation within the TensorFlow (TF) environment\footnote{\url{https://www.tensorflow.org/}}~\citep{abadi2016tensorflow}.
In the following of the section, it is assumed that each FOL constant corresponds to a tensor storing its feature representation.
DFL functions and predicates correspond to a TF computational graph. If the graph does not contain any parameter, it is said to be \textit{given}, otherwise the function/predicate is said to be \textit{learnable}, and the parameters will be optimized to maximize the constraints satisfaction.
Please note that any learner expressed as a TF computational graph can be transparently integrated into DFL.

\subsection{The Learning Task}
The CiteSeer dataset~\citep{fakhraei2015collective} consists of 3312 scientific papers, each one assigned to one of 6 classes: Agents, AI, DB, IR, ML and HCI. The papers are not independent as they are connected by a citation network with 4732 links.  
This dataset defines a relational learning benchmark, where it is assumed that the representation of an input document is not sufficient for its classification without exploiting the citation network. The citation network is typically employed by assuming that two papers connected by a citation belong to the same category.
\begin{figure}[th]
	\centering
	\begin{minipage}[t]{.45\linewidth}
		\includegraphics[width=\textwidth]{learning_dynamics_ss_gd.pdf}
		\vspace{-0.85cm}
		\caption{SS - GD}
		\label{fig:ss_gd}
	\end{minipage}
	\begin{minipage}[t]{.45\linewidth}
		\includegraphics[width=\textwidth]{learning_dynamics_frank_gd.pdf}
		\vspace{-0.85cm}
		\caption{Frank - GD}
		\label{fig:frank_gd}
	\end{minipage}
	\label{fig:learning_dynamics_gd}
\end{figure}
\begin{figure}[th]
	\centering
	\begin{minipage}[t]{.45\linewidth}
		\includegraphics[width=\textwidth]{learning_dynamics_ss_adam.pdf}
		\vspace{-0.85cm}
		\caption{SS - Adam}
		\label{fig:ss_adam}
	\end{minipage}
	\begin{minipage}[t]{.45\linewidth}
		\includegraphics[width=\textwidth]{learning_dynamics_frank_adam.pdf}
		\vspace{-0.85cm}
		\caption{Frank - Adam}
		\label{fig:frank_adam}
	\end{minipage}
	\caption{Learning Dynamics in terms of test accuracy on a supervised task when choosing different t-norms generated by the parameterized SS and Frank families: (\ref{fig:ss_gd}) and (\ref{fig:frank_gd}) are learning processes optimized with standard Gradient Descent, while (\ref{fig:ss_adam}) and (\ref{fig:frank_adam}) are optimized with Adam Gradient Descent.}
	\label{fig:learning_dynamics_adam}
\end{figure}
This knowledge can be expressed by providing a general rule of the form:
$\forall x \; \forall y \; cite(x,y) \Rightarrow \big (p(x) \iff p(y)\big)$
where $cite$ is a binary predicate encoding the fact that $x$ is citing $y$ and $p$ is a task function implementing the membership function of one of the six considered categories. This logical formula expresses the manifold regularization, which often emerges in relational learning tasks. Indeed, by linking the prediction of two distinct documents, the behaviour of the underlying task functions is regularized enforcing \textit{smooth} transition over the manifold induced by the $cite$ relation.

Each paper is represented via its bag-of-words, which is a vector having the same size of the vocabulary with the i-th element having a value equal to 1 or 0, depending on whether the i-th word in the vocabulary is present or not present in the document, respectively. The dictionary consists of 3703 unique words. The set of input document representations is indicated as $X$, which is split into a training and test set $X_{tr}$ and $X_{te}$, respectively. The percentage of documents in the two splits is varied across the different experiments.
The six task functions $p_i$ with $i \in \{Agents, AI, DB, IR, ML , HCI\}$ are bound to the six outputs of a Multi-Layer-Perceptron (MLP) implemented in TF. The neural architecture has 3 hidden layers, with 100 ReLU units each, and softmax activation on the output. Therefore, the task functions share the weights of the hidden layers in such a way that all of them can exploit a common hidden representation.
The $cite$ predicate is a given (fully known a prior) function, which outputs 1 if the document passed as first argument cites the document passed as second argument, otherwise it outputs 0. Furthermore, a given function $P_i$ is defined for each $p_i$, such that it outputs $1$ iff $x$ is a positive example for the category $i$ (i.e. it belongs to that category).
A manifold regularization learning problem~\citep{belkin2006manifold} can be defined by providing, $\forall i \in \{Agents, AI, DB, IR, ML, HCI\}$, the following two FOL formulas:
\begin{eqnarray}
\forall x \; \forall y \quad & cite(x,y) \Rightarrow \big (p_{i}(x) \Leftrightarrow p_{i}(y)\big ) \label{eq:manifold} \\
\forall x \quad & P_i(x) \Rightarrow p_{i}(x) \label{eq:supervision}
\end{eqnarray}
where only positive supervisions have been provided because the trained networks for this task employ a softmax activation function on the output layer, which has the effect of imposing mutually exclusivity among the task functions, reinforcing the positive class and discouraging all the others. While this behaviour could have been trivially expressed using logic, this network architecture provides a principled baseline to compare against and it was therefore used across all the experiments for this dataset.

DLF allows the users to specify the weights of formulas, which are treated as hyperparameters. Since we use at most $2$ constraints per predicate, the $\beta$ weight of the constraint expressing the fitting of the supervisions (Equation~\ref{eq:supervision}) is set to a fixed value equal to 1, while the weight of the manifold regularization rule expressed by Equation~\ref{eq:manifold} is cross-validated from the grid of values $\{0.1, 0.01, 0.006, 0.003, 0.001,0.0001\}$.


\subsection{Results}
The experimental results measure the different effects of the integration of logic prior knowledge into supervised learning. In particular, the experiments show how effective the external knowledge is in accelerating the convergence speed of training, in improving the classification accuracy when scarce training data is available and how the proposed methodology compares in absolute terms against other supervised learning approaches.

\paragraph{Training Convergence Rate}
This experimental setup aims at verifying the relation between the choice of the generator and speed of convergence of the training process. In particular, a simple supervised learning setup is assumed for this experiment, where the leaning task is defined by Equation~\ref{eq:supervision} by simply enforcing the fitting of the supervised examples. The training and test sets are composed of 90\% and $10\%$ of the total number of papers, respectively. Two parametric families of t-norms have been considered: the SS family (Definition \ref{ex:ss}) and the Frank family (Definition \ref{ex:frank}). Their parameter $\lambda$ was varied to construct classical t-norms for some special values of the parameter but also to evaluate some intermediate ones. In order to keep a clear intuition behind the results, optimization was initially carried out using simple Gradient Descent with a fixed learning rate equal to $\eta = 10^{-5}$. Results are shown in Figures (\ref{fig:ss_gd}) and (\ref{fig:frank_gd}): it is evident that strict t-norms tend to learn faster than nilpotent ones by penalizing more strongly highly unsatisfied ground formulas. This difference is still remarkably present, although slightly reduced, by exploiting the state-of-the-art dynamic learning rate optimization algorithm Adam~\citep{kingma2014adam} as shown in Figures~\ref{fig:ss_adam} and \ref{fig:frank_adam}.
This finding is consistent with the empirically well known fact that the cross-entropy loss performs well in supervised learning tasks for deep architectures, because it is effective in avoiding gradient vanishing in deep architectures. The cross-entropy loss corresponds to a strict generator with $\lambda=0$ and $\lambda=1$ in the SS and Frank families, respectively. This selection corresponds to a fast and stable converging solution when paired with Adam, while there are faster converging solutions when using a fixed learning rate.

\paragraph{Classification accuracy}
The effect of the selection of the generator on classification accuracy is tested on a classification task with manifold regularization in the transductive setting, where all the data is available at training time, even if only the training set supervisions are used during learning. In particular, the data is split into different datasets, where $\{10\%, 25\%, 50\%, 75\%, 90\%\}$ of the available data is used a test set, while the remaining data forms the training data. During training, the fitting of the supervised data defined by Equation \ref{eq:supervision} can be applied only for the training data, while manifold regularization (Equation \ref{eq:manifold}) can be enforced on all the available data. In this experiment, the Adam optimizer and the SS family of parametric t-norms have been employed. Table \ref{tab:manifold} shows the average test accuracy and its standard deviation over 10 different samples of the train/test splits. As expected, all generator selections improve the final accuracy over what obtained by pure supervised learning, as manifold regularization brings relevant information to the learner.
\begin{table}[t]
	\small
	\centering
		\begin{tabular}{cccccc}
			\hline
			\multirow{2}{*}{$\%$ Test} & \multirow{2}{*}{$\lambda$} & \multicolumn{2}{c}{Supervised} & \multicolumn{2}{c}{Manifold} \\
			\cline{3-6} 
			&&Avg Accuracy & Stddev & Avg Accuracy & Stddev \\
			\hline
			\multirow{5}{*}{10\%} & -1.5 & 72.44 & 0.8  & 79.07 & 1.07\\
			& -1.0 & 72.26 & 0.96  & 79.37 & 0.68\\
			& 0.0 & 71.63 & 0.74  & 79.37 & 0.84\\
			& 1.0 & 71.57 & 0.88  & 78.58 & 0.69\\
			& 1.5 & 71.93 & 1.11  & 77.77 & 0.89\\
			\hline
			\multirow{5}{*}{25\%} & -1.5 & 72.22 & 0.46  & 77.17 & 0.70\\
			& -1.0 & 72.02 & 0.52  & 77.51 & 0.72\\
			& 0.0 & 71.35 & 0.56  & 77.39 & 0.50\\
			& 1.0 & 71.22 & 0.47  & 77.36 & 0.64\\
			& 1.5 & 71.51 & 0.77  & 76.41 & 0.57\\
			\hline
			\multirow{5}{*}{50\%} & -1.5 & 70.94 & 0.56  & 75.52 & 0.46\\
			& -1.0 & 70.98 & 0.51  & 76.16 & 0.32\\
			& 0.0 & 70.49 & 0.52  & 75.71 & 0.39\\
			& 1.0 & 70.07 & 1.71  & 76.39 & 0.46\\
			& 1.5 & 70.09 & 0.47  & 75.97 & 0.55\\
			\hline
			\multirow{5}{*}{75\%} & -1.5 & 67.06 & 0.58  & 72.25 & 0.50\\
			& -1.0 & 66.96 & 0.44  & 72.48 & 0.50\\
			& 0.0 & 67.02 & 0.54  & 72.73 & 0.61\\
			& 1.0 & 66.34 & 0.29  & 73.77 & 0.34\\
			& 1.5 & 65.93 & 0.64  & 73.37 & 0.37\\
			\hline
			\multirow{5}{*}{90\%} & -1.5 & 61.09 & 0.78  & 66.02 & 2.51\\
			& -1.0 & 61.59 & 0.44  & 67.24 & 1.72\\
			& 0.0 & 61.52 & 0.33  & 68.60 & 0.75\\
			& 1.0 & 61.31 & 0.52  & 70.69 & 0.52\\
			& 1.5 & 61.17 & 0.84  & 70.32 & 0.89\\
			\hline
		\end{tabular}
\vspace{0.1cm}
	\caption{Test accuracy of collective classification in transductive setting on the Citeseer dataset for different percentages of available training data and different selections of the parameter $\lambda$ of the SS generator family.}
	\label{tab:manifold}
\end{table}

Table \ref{tab:manifold} also shows test accuracy when the parameter $\lambda$ of the SS parametric family is selected from the grid $\{-1.5, -1, 0, 1, 1.5\}$, where values of $\lambda \le 0$ move across strict t-norms (with $\lambda=0$ being the product t-norm), while values greater than $0$ move across nilpotent t-norms. (with $\lambda=1$ being the \L ukasiewicz t-norm). 
Strict t-norms seem to provide slightly better performances than nilpotent ones on supervised task for almost all the test set splits. However, this does not hold in learning tasks using manifold regularization and a limited number of supervisions, where nilpotent t-norms perform better. An explanation of this behaviour can be found in the different nature of the two constraints, i.e. the supervision constraint of Equation \ref{eq:supervision} and the manifold regularization constraint of Equation \ref{eq:manifold}. Indeed, while supervisions provide hard constraint that need to be strongly satisfied, manifold regularization is a general soft rule, which should allow exceptions. When the number of supervision is small and manifold regularization drives the learning process, the milder behaviour of nilpotent t-norms is better, as it more closely models the semantics of the prior knowledge.
Finally, it is worth noticing that very strict t-norms (e.g. $\lambda = -1.5$ in the provided experiment) provide high standard deviations compared to other t-norms, especially in the manifold regularization setup. This shows the presence of a trade-off between the improved learning speed provided by strict t-norms and the instability due to their extremely non-linear behaviour.

\paragraph{Competitive evaluation}
Table~\ref{tab:competitors} compares the accuracy of the selected neural model (NN) trained only with supervised constraint against other two content-based classifiers, namely logistic regression (LR) and Naive Bayes (NB). These baseline classifiers have been compared against collective classification approaches using the citation network data: Iterative Classification Algorithm (ICA)~\citep{neville2000iterative} and Gibbs Sampling (GS)~\citep{lu2003link} applied on top of the output of the LR and NB content-based classifiers.
\begin{table}[th]
	\small
	\centering
	\begin{tabular}{lc}
			\hline
		& Classification\\
		Method & Accuracy\\
			\hline
		Naive Bayes & 74.87 \\
		ICA Naive Bayes &76.83\\
		GS Naive Bayes &76.80\\
		Logistic Regression &73.21\\
		ICA Logistic Regression &77.32\\
		GS Logistic Regression &76.99\\
		Loopy Belief Propagation & 77.59\\
		Mean Field &77.32 \\
		NN & 72.26 \\
		DFL & \textbf{79.37}\\
			\hline
	\end{tabular}
\vspace{0.1cm}
	\caption{Comparison of the accuracy on the Citeseer dataset obtained by content based and relational classifiers against supervised and relational learning expressed using DFL. All reported results are computed as average over $10$ random splits of the train and test data. The bold number indicates the best performer and a statistically significant improvement over the competitors.}
	\label{tab:competitors}
\end{table}
Furthermore, the results are compared against the two top performers on this task: Loopy Belief Propagation (LBP)~\citep{sen2008collective} and Relaxation Labeling through Mean-Field Approach (MF)~\citep{sen2008collective}. Finally, the results of DFL built by training the same neural network with both supervision and manifold regularization constraints, for which it was used a generator from the SS family with $\lambda=-1$. The accuracy values are obtained as an average over 10-folds created by random splits of $90$\% and $10$\% of the data for the train and test sets, respectively. Unlike the other relational approaches that can only be executed at inference time (collective classification), DFL can distill the knowledge in the weights of the neural network. The accuracy results are the highest among all the tested methodologies in spite of the fact that the neural network trained only on the supervisions performs slightly worse than the other content-based competitors.

\section{Conclusions}
\label{sec:conc}
This paper presents a framework to embed prior knowledge expressed as logic statements into a learning task. In particular, it was shown how the choice of the t-norm generator used to convert the logic into a differentiable form defines the resulting loss function used during learning.
When restricting the attention to supervised learning, the framework recovers popular loss functions like the cross-entropy loss, and allows to define new loss functions corresponding to the choice of the parameters of t-norm parametric forms. The presented theory has driven to the implementation of a general software simulator, called DFL, which bridges logic reasoning and deep learning using the unifying concept of t-norm generator, as general abstraction to translate any FOL declarative knowledge into an optimization problem solved in TensorFlow.











\acks{This project has received funding from the European Union's Horizon 2020 research and innovation program under grant agreement No 825619.}













\vskip 0.2in

\newpage

