(
        self,
        id2term: Sequence[str] | Dict[int, str],
        *,
        topics: int | Sequence[int] = -1,
        top_n: int = 10,
        weights: bool = False,
    )
Get the top ``top_n`` terms by weight per topic in ``model``.

        Args:
            id2term: Object that returns the term string corresponding to term id ``i``
                through ``id2term[i]``; could be a list of strings where the index
                represents the term id, such as that returned by
                ``sklearn.feature_extraction.text.CountVectorizer.get_feature_names()``,
                or a mapping of term id to term string.
            topics: Topic(s) for which to return top terms;
                if -1 (default), all topics' terms are returned.
            top_n: Number of top terms to return per topic
            weights: If True, terms are returned with their corresponding
                topic weights; otherwise, terms are returned without weights

        Yields:
            Next tuple corresponding to a topic; the first element is the topic's
            index; if ``weights`` is False, the second element is a tuple of str
            representing the top ``top_n`` related terms; otherwise, the second
            is a tuple of (str, float) pairs representing the top ``top_n``
            related terms and their associated weights wrt the topic; for example::

                >>> list(TopicModel.top_topic_terms(id2term, topics=(0, 1), top_n=2, weights=False))
                [(0, ('foo', 'bar')), (1, ('bat', 'baz'))]
                >>> list(TopicModel.top_topic_terms(id2term, topics=0, top_n=2, weights=True))
                [(0, (('foo', 0.1415), ('bar', 0.0986)))]
Get the top ``top_n`` terms by weight per topic in ``model``.
Get the top top_n terms by weight per topic in model .
def top_topic_terms(
        self,
        id2term: Sequence[str] | Dict[int, str],
        *,
        topics: int | Sequence[int] = -1,
        top_n: int = 10,
        weights: bool = False,
    ) -> Iterable[Tuple[int, Tuple[str, ...]]] | Iterable[
        Tuple[int, Tuple[Tuple[str, float], ...]]
    ]:
        """
        Get the top ``top_n`` terms by weight per topic in ``model``.

        Args:
            id2term: Object that returns the term string corresponding to term id ``i``
                through ``id2term[i]``; could be a list of strings where the index
                represents the term id, such as that returned by
                ``sklearn.feature_extraction.text.CountVectorizer.get_feature_names()``,
                or a mapping of term id to term string.
            topics: Topic(s) for which to return top terms;
                if -1 (default), all topics' terms are returned.
            top_n: Number of top terms to return per topic
            weights: If True, terms are returned with their corresponding
                topic weights; otherwise, terms are returned without weights

        Yields:
            Next tuple corresponding to a topic; the first element is the topic's
            index; if ``weights`` is False, the second element is a tuple of str
            representing the top ``top_n`` related terms; otherwise, the second
            is a tuple of (str, float) pairs representing the top ``top_n``
            related terms and their associated weights wrt the topic; for example::

                >>> list(TopicModel.top_topic_terms(id2term, topics=(0, 1), top_n=2, weights=False))
                [(0, ('foo', 'bar')), (1, ('bat', 'baz'))]
                >>> list(TopicModel.top_topic_terms(id2term, topics=0, top_n=2, weights=True))
                [(0, (('foo', 0.1415), ('bar', 0.0986)))]
        """
        if topics == -1:
            topics = range(self.n_topics)
        elif isinstance(topics, int):
            topics = (topics,)

        for topic_idx in topics:
            topic = self.model.components_[topic_idx]
            if weights is False:
                yield (
                    topic_idx,
                    tuple(id2term[i] for i in np.argsort(topic)[: -top_n - 1 : -1]),
                )
            else:
                yield (
                    topic_idx,
                    tuple(
                        (id2term[i], topic[i])
                        for i in np.argsort(topic)[: -top_n - 1 : -1]
                    ),
                )
def top_topic_terms ( self , id2term : Sequence [ str ] | Dict [ int , str ] , * , topics : int | Sequence [ int ] = - 1 , top_n : int = 10 , weights : bool = False , ) -> Iterable [ Tuple [ int , Tuple [ str , ... ] ] ] | Iterable [ Tuple [ int , Tuple [ Tuple [ str , float ] , ... ] ] ] : if topics == - 1 : topics = range ( self . n_topics ) elif isinstance ( topics , int ) : topics = ( topics , ) for topic_idx in topics : topic = self . model . components_ [ topic_idx ] if weights is False : yield ( topic_idx , tuple ( id2term [ i ] for i in np . argsort ( topic ) [ : - top_n - 1 : - 1 ] ) , ) else : yield ( topic_idx , tuple ( ( id2term [ i ] , topic [ i ] ) for i in np . argsort ( topic ) [ : - top_n - 1 : - 1 ] ) , )