Bases: TermEmbedder
Embeds terms with learnable embeddings. The memory for the embeddings is allocated in blocks.
n – Optional int. Limits the returned embeddings to the first n.
A tensor containing the embeddings.
labels – A list of terms.
Returns the tensor of the embeddings of the terms in label in order.
Bases: TermEmbedder
One-hot embedder. Assign each unique term a unique one-hot embedding.
Bases: object
The query object.
Replaces the output variables :param new_values: The new values in order that should replace the output variables. :return: The query with the out_variables replaced by the corresponding new values.
substitution – The dictionary that will be used to perform the substitution. If None, then self.substitution will be used instead.
A new query where the substitution is applied. See the apply_term method from the Term class for details on the substitution.
Bases: ABC
n – The number of folds to make.
i – Which of the folds is the held-out set.
A tuple of the training fold and test fold datasets.
i – index i
j – index j
If j is None, returns a subset with the indices [0,i], else returns a subset with the indices [i, j]
i – index
Returns a string representation of file i suitable for writing to a file. Defaults to to_query.
Bases: Dataset
Bases: Dataset
Bases: Dataset, ABC
Bases: Dataset
Generic dataset adapter that mutates an underlying dataset.
Intended use cases involve generating noisy datasets as well as negative examples.
Bases: object
Dataset mutator that will mutate with a certain probability
Bases: object
Dataset mutator that replaces numeric output with an incorrect value. Only constants are supported.
Bases: Dataset
Dataset that loads queries from a file or a list
Bases: object
Wraps a PyTorch neural network for use with DeepProblog
Mode the network to a cuda device if CUDA is available. :param device: The cuda device to move the network to.
Restore the parameters of this network from a file. :param location: The location of the parameter file. :return:
Bases: object
The optimizer responsible for optimizing the neural parameters in the model.
Accumulate the gradient for a probabilistic parameter. :param k: The key of the parameter. :param grad: The gradient to accumulate. :return:
Bases: Optimizer
An optimizer that also optimizes the probabilistic parameters in the model using stochastic gradient descent.
Adds a named tensor source to the model. :param name: The name of the added tensor source. :param source: The tensor source to add :return:
to_evaluate – List of neural predicates to evaluate
A dictionary with the elements of to_evaluate as keys, and the output of the NN as values.
Recursively build a dictionary containing the most important hyperparameters in the model. :return: A dictionary that contains the values of the most important hyperparameters of the model.
term – A term of the form tensor(_).
If the tensor is of the form tensor(a(*args)), then it well look into tensor source a. :return: Returns the stored tensor identifier by the term.
Write the output of the get_hyperparameter() method in JSON format to a file. :param filename: The path to write the hyperparameters to. :return:
and all parameters of the neural networks, but not the model architecture or neural architectures.
filename – The filename to restore the model from.
parameters and all parameters of the neural networks, but not the model architecture or neural architectures
filename – The filename to save the model to.
complete – If true, save neural networks with information needed to resume training.
Initializes the solver of this model with the given engine and additional arguments. :param engine: The engine that will be used to ground queries in this model. :param kwargs: Additional arguments passed to the solver. :return:
model – The model to evaluate.
dataset – The dataset to evaluate the model on.
verbose – Set the verbosity. If verbose > 0, then print confusion matrix and accuracy.
If verbose > 1, then print all wrong answers. :param eps: If set, then the answer will be treated as a float, and will be considered correct if the difference between the predicted and ground truth value is smaller than eps. :return: The confusion matrix when evaluating model on dataset.
model – The model to evaluate.
dataset – The dataset to evaluate the model on.
verbose – Set the verbosity. If verbose > 0, then print confusion matrix and accuracy.
If verbose > 1, then print all wrong answers. :param threshold: If set, then the answer will be treated as a float, and will be considered correct if the difference between the predicted and ground truth value is smaller than eps. :param empty_answer: The category in the confusion matrix when no answer was returned. Default = “false” :return: The confusion matrix when evaluating model on dataset.
Bases: object
A class that bundles the different steps of inference.
Builds the arithmetic circuit. :param q: The query for which to build the arithmetic circuit. :return: The arithmetic circuit for the given query.
Bases: object
An asbtract engine base class.
query – The query to ground.
kwargs –
A logic formula representing the ground program.
Modifies the given program to a format suited for querying in this engine. :param program: The program to be modified :return: The modified program
Makes a Python function available to the grounding engine. :param func: The Python function to be made available. :param function_name: The name of the predicate that will be used to address this function in logic. :param arity_in: The number of input arguments to func :param arity_out The number of return values of func :return:
Makes a Python function available to the grounding engine. :param func: The Python function to be made available. :param function_name: The name of the predicate that will be used to address this function in logic. :param arity_in: The number of input arguments to func :param arity_out The number of return values of func :return:
Bases: object
A class that contains the result and timing info for evaluating a query.
Bases: Semiring, ABC
The semiring object defines the operations for the evaluation of arithmetic circuits.
Calculates the cross_entropy between the predicted and target probabilities. Also performs the backwards pass for the given result. :param result: The result to calculate loss on. :param target: The target probability. :param weight: The weight of this examplE. A float that is multiplied with the loss before backpropagation. :param q: If there’s more than one query in result, calculate the loss for this query. :param eps: The epsilon used in the cross-entropy loss calculation. :return:
Evaluates the arithmetic circuit. :param model: The model (neural network and parameters) to evaluate the AC in. :param substitution: Optional dict. The substitution applied to the parameterized AC. See apply_term. :param re_evaluate: Force re-evaluation of the neural networks :return: