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:
- model
NumpyViterbiInference 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.
- model
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:
- path
Path Path to model to load.
- path
- 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:
- Returns:
floatDescription
- Raises:
ValueErrorDescription
- 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.