messageanalyzer.topic_modeling ============================== .. py:module:: messageanalyzer.topic_modeling Functions --------- .. autoapisummary:: messageanalyzer.topic_modeling.topic_modeling Module Contents --------------- .. py:function:: topic_modeling(messages: List[str], n_topics: int = 5, n_words: int = 10, random_state: int = 123) -> Dict[str, List[str]] Perform topic modeling using Non-negative Matrix Factorization (NMF). :param messages: List of messages for topic modeling. :type messages: List[str] :param n_topics: Number of topics to extract, by default 5. :type n_topics: int, optional :param n_words: Number of top words to display per topic, by default 10. :type n_words: int, optional :param random_state: Random seed for reproducibility, by default 123. :type random_state: int, optional :returns: A dictionary where each key is a topic label (e.g., "Topic 1") and each value is a list of the most representative words for that topic. :rtype: Dict[str, List[str]] :raises TypeError: If `messages` is not a list of strings. .. rubric:: Examples >>> messages = ["Learning Data science at MDS is amazing!", "I prefer to work with Python than R"] >>> topic_modeling(messages, n_topics = 3, n_words = 3) {'Topic 1': ['mds', 'science', 'learning'], 'Topic 2': ['work', 'python', 'prefer'], 'Topic 3': ['amazing', 'data', 'learning']}