Inference#

class ingredient_parser.inference.NumpyCRFInference(model_file: Path, combined_name_labels: bool = False)[source]#

Class to performance inference using trained CRF model for ingredient sentence labelling.

Attributes:
modelNumpyViterbiInference

Implementation of Viterbi for inference.

combined_name_labelsbool

Set to True if there only a single NAME label present in the weights. Set to False otherwise.

Methods

load(path)

Load saved model at given path.

marginal(label, position)

Return the probability of label, label, at position, position, for the most recent sequence passed to predict_sequence.

tag_from_features(sentence_features)

Tag a sentence with labels using model.

load(path: Path) None[source]#

Load saved model at given path.

Parameters:
pathPath

Path to model to load.

marginal(label: str, position: int) float[source]#

Return the probability of label, label, at position, position, for the most recent sequence passed to predict_sequence.

Parameters:
labelstr

Label at position.

indexint

Position in sequence.

Returns:
float

Description

Raises:
ValueError

Description

tag_from_features(sentence_features: list[dict[str, str | bool]]) list[tuple[str, float]][source]#

Tag a sentence with labels using model.

This function accepts a list of features for each token, rather than calculating the features from the tokens.

If self.combined_name_labels=True, then we cannot apply transition constraints because they only apply to I_NAME_TOK.

Parameters:
sentence_featureslist[FeatureDict]

List of feature dicts for each token.

Returns:
list[tuple[str, float]]

List of labels.