lightopic._lightopic ==================== .. py:module:: lightopic._lightopic Classes ------- .. autoapisummary:: lightopic._lightopic.Lightopic Module Contents --------------- .. py:class:: Lightopic The Lightopic class is to be used with a trained topic model that has been serialised appropriately (see docs for `lightopic.LightBERTopic.save_lightopic`). Methods will transform new data by reducing the embeddings or putting them into topics. .. py:method:: load(model_directory: str) -> None .. py:method:: reduce_embeddings(embeddings: numpy.ndarray, output_type: str = 'reduced') -> numpy.ndarray Reduce the dimensions of an input array of embeddings. :param embeddings: An array of embeddings. :type embeddings: numpy.ndarray :param output_type: Set the dimensions of the output. Defaults to "reduced", which will reduce to the dimensions used for clustering. (If you used the BERTopic defaults this will be 5.) Setting this to "2d" will output 2-dimensional vectors that you can use for plotting. :type output_type: str, optional :raises ValueError: if `output_type` is not either `"reduced"` or `"2d"`. :raises ValueError: the dimension of the `embeddings` must be compatible with the Lightopic model, i.e. it must match either the full dimension of the original embeddings (`self.len_full_embedding`) or that of the reduced embeddings (`self.len_umap_embedding`). :returns: The reduced embeddings. :rtype: numpy.ndarray .. py:method:: transform(embeddings: numpy.ndarray, calculate_probabilities: bool = True) -> tuple[numpy.ndarray, numpy.ndarray] Transform new documents with the model. :param embeddings: Array of embeddings :type embeddings: numpy.ndarray :param calculate_probabilities: Return probabilities for all topics? Defaults to True. :type calculate_probabilities: bool, optional :raises ValueError: the dimension of the `embeddings` must be compatible with the Lightopic model, i.e. it must match either the full dimension of the original embeddings (`self.len_full_embedding`) or that of the reduced embeddings (`self.len_umap_embedding`). :returns: The topic assignments and probabilities. :rtype: tuple[numpy.ndarray, numpy.ndarray]