Weight Learning

The weights of the soft-constrained clauses in Markov Logic Networks (MLNs) can be estimated from training data using supervised learning techniques. The goal is to learn a model (i.e., weighted clauses) by estimating the weight values from training examples. Since the learning paradigm is supervised, the training examples is a collection of input ground atoms (i.e., input evidence) and their corresponding output query atoms (i.e., annotation). The learned model should be capable of inferring as correct as possible the marginal probabilities or the maximum a-posteriori estimation of query atoms, given an input of ground evidence facts.

There are several weight estimation methods in the literature, the majority of them are batch learning methods that optimise the conditional log likelihood of the Markov Logic model -- for example see the works of Singla and Domingos (2005) and Lowd and Domingos (2007). LoMRF implements batch and on-line weight learning methods that optimize the max-margin, that is the ratio between the probability of correct truth assignment of query atoms (taken by the training data) and the closest competing incorrect truth assignment (estimated by the trained model) -- for details see the works of Huynh and Mooney, (2009, 2011) and Duchi et al. (2011). Max-margin training is better suited to problems where the goal is to maximise the classification accuracy.

Weight learning in LoMRF

In order to perform weight learning in LoMRF the following definitions are required:

Weight learning using the lomrf wlearn command-line tool

To demonstrate the usage of LoMRF from command-line interface for weight learning, assume that we have one knowledge base file, named as theory.mln, and one training file, named as training.db containing both the evidence and the supervision. Please note that the supervision is a collection of the expected ground atoms of the non-evidence atoms (i.e., query atoms).

In our example knowledge-base we have the following predicates:

Predicate Name Number of arguments Predicate identity Description
NonEvidence_A 2 NonEvidence_A/2 first non-evidence predicate
NonEvidence_B 2 NonEvidence_B/2 second non-evidence predicate
Ev_A 1 EV_A/1 first evidence predicate
Ev_B 1 EV_B/1 second evidence predicate

As it is presented in the above table, there are two non-evidence predicates, NonEvidence_A and NonEvidence_B, where each one takes two terms as arguments. Therefore their atomic signatures are NonEvidence_A/2 and NonEvidence_B/2. Similarly, there are two evidence predicates Ev_A and Ev_B that they take one term as argument. Therefore, the atomic signatures of Ev_A and Ev_B are Ev_A/1 and Ev_B/1, respectively. As stated above, for all of them LoMRF assumes Closed-world assumption.

Batch Max-Margin learning

Max-margin learning considers all training data at once in order to estimate the weights of the given formulas defined in the input theory file.

lomrf wlearn -alg MAX_MARGIN -i theory.mln -t training.db -o learned.mln -ne NonEvidence_A/2,NonEvidence_B/2

Where the parameter '-alg MAX_MARGIN' defines that we are using max-margin training method. The paramter '-i theory.mln' is the input theory that contains all MLN logic formulas (both soft-constrained and hard-constrained). The method will try to estimate the weights of all resulting soft-constrained clauses of the MLN logic formulas. All hard-constrained clauses will remain the same. Parameter '-t training.db' is the input training file, that is the file that contains all ground predicates (both evidence and non-evidence). The parameter '-o learned.mln' specifies the resulting output file. Finally, the parameter '-ne NonEvidence_A/2,NonEvidence_B/2' defines which predicates are non-evidence (thus will be the query atoms).

Important Note: Max-margin learner requires the proprietary Gurobi solver installed on your system, because the learning algorithm needs to solve a Quadratic Optimization problem. In case the solver is not present the learning procedure will terminated and notify you to install the software.

Online weight learning (CDA or AdaGrad)

Suppose that we have multiple training micro-batches of training data named as training1.db, training2.db, etc. Then we can run an online weight learner to estimate the weights of the formulas defined in the input theory file, given a path of input training files.

lomrf wlearn -alg CDA -i theory.mln -t /path/to/training/batches/ -o learned.mln -ne NonEvidence_A/2,NonEvidence_B/2

or

lomrf wlearn -alg ADAGRAD -i theory.mln -t /path/to/training/batches/ -o learned.mln -ne NonEvidence_A/2,NonEvidence_B/2

Where the parameter '-alg' defines that we are using either 'CDA' or 'ADAGRAD' training method. The paramter '-i theory.mln' is the input theory that contains all MLN logic formulas (both soft-constrained and hard-constrained). The method will try to estimate the weights of all resulting soft-constrained clauses of the MLN logic formulas. All hard-constrained clauses will remain the same. Parameter '-t /path/to/training/batches/' is the path to the directory that contains all training files (*.db), where each one contains ground predicates (both evidence and non-evidence) that belong to the same micro-batch. The parameter '-o learned.mln' specifies the resulting output file. Finally, the parameter '-ne NonEvidence_A/2,NonEvidence_B/2' defines which predicates are non-evidence (thus will be the query atoms).

Weight Leaning Examples

For a detailed weight learning tutorial in LoMRF, see Sections Weight Learning Examples and Temporal Weight Learning Examples. Sources from the examples are located in the LoMRF-data project (follow the instructions in Download Example Data).

Command-line Interface Options for Weight Learning

By executing the lomrf wlearn -h (or lomrf wlearn --help) command from the command-line interface, we get a print of multiple parameters. Below we explain all LoMRF weight learning command-line interface parameters:

Basic weight learning options

Advanced weight learning options