tmnt.inference

Inferencers to make predictions and analyze data using trained topic models.

Classes

BaseInferencer(estimator, vectorizer, device) Base inference object for text encoding with a trained topic model.
BowVAEInferencer(estimator[, pre_vectorizer])
MetricSeqVEDInferencer(estimator, max_length) Inferencer for sequence variational encoder-decoder models using BERT trained via Metric Learning
SeqVEDInferencer(estimator, max_length[, ...]) Inferencer for sequence variational encoder-decoder models using a pretrained Transformer model
class BaseInferencer(estimator, vectorizer, device)[source]

Bases: object

Base inference object for text encoding with a trained topic model.

save(model_dir)[source]

Save model and vectorizer to disk

Parameters:model_dir (str) – Model directory to save parmaeters, config, vocabulary and vectorizer
Return type:None
class BowVAEInferencer(estimator, pre_vectorizer=None)[source]

Bases: BaseInferencer

get_likelihood_stats(data_mat, n_samples=50)[source]

Get the expected elbo and its variance for input data using sampling :type data_mat: :param data_mat: Document term matrix

predict_text(txt, pred_threshold=0.5)[source]

Take a list of input documents/passages as strings and return document encodings (topics) and classification outputs

Parameters:
  • txt (List[str]) – List of input document strings
  • pred_threshold (float) – Threshold to use for multilabel classification
Return type:

Tuple[List[str], List[ndarray], ndarray]

Returns:

top predicted labels, encodings, posteriors

class SeqVEDInferencer(estimator, max_length, pre_vectorizer=None, device='cpu')[source]

Bases: BaseInferencer

Inferencer for sequence variational encoder-decoder models using a pretrained Transformer model

class MetricSeqVEDInferencer(estimator, max_length, pre_vectorizer=None, device='cpu')[source]

Bases: SeqVEDInferencer

Inferencer for sequence variational encoder-decoder models using BERT trained via Metric Learning