Module Expr Str Import alias Import alias identifier ImportFrom alias alias alias ImportFrom alias Assign NameStore Call AttributeLoad NameLoad attr NameLoad ClassDef bases NameLoad body Expr Str FunctionDef arguments args NameParam NameParam NameParam defaults Num kwarg body If Call NameLoad NameLoad TupleLoad NameLoad NameLoad NameLoad body Assign AttributeStore NameLoad attr NameLoad orelse Expr Call AttributeLoad NameLoad attr NameLoad keyword NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults Num kwarg body If CompareEq NameLoad Str body Assign AttributeStore NameLoad attr Call NameLoad keyword NameLoad keyword Call AttributeLoad NameLoad attr Str Num keyword Call AttributeLoad NameLoad attr Str Num keyword Call AttributeLoad NameLoad attr Str Num keyword Call AttributeLoad NameLoad attr Str Num keyword Call AttributeLoad NameLoad attr Str NameLoad orelse If CompareEq NameLoad Str body Assign AttributeStore NameLoad attr Call NameLoad keyword NameLoad keyword Call AttributeLoad NameLoad attr Str Num keyword Call AttributeLoad NameLoad attr Str Num keyword Call AttributeLoad NameLoad attr Str Str keyword Call AttributeLoad NameLoad attr Str Num keyword Call AttributeLoad NameLoad attr Str Num keyword Call AttributeLoad NameLoad attr Str Num orelse If CompareEq NameLoad Str body Assign AttributeStore NameLoad attr Call NameLoad keyword NameLoad keyword Call AttributeLoad NameLoad attr Str Str keyword Call AttributeLoad NameLoad attr Str Num keyword Call AttributeLoad NameLoad attr Str Num orelse Assign NameStore Call AttributeLoad Str attr NameLoad Set Str Str Str Raise Call NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Assign NameStore Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr NameLoad keyword Num Expr Call AttributeLoad NameLoad attr Call AttributeLoad Str attr AttributeLoad NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Assign NameStore Call AttributeLoad NameLoad attr NameLoad Assign NameStore IfExp Call NameLoad NameLoad Str AttributeLoad NameLoad attr AttributeLoad NameLoad attr Return Call NameLoad NameLoad keyword NameLoad decorator_list NameLoad FunctionDef arguments args NameParam NameParam defaults body Expr Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body If Call NameLoad AttributeLoad NameLoad attr NameLoad body Expr Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad orelse Raise Call NameLoad Str decorator_list FunctionDef arguments args NameParam NameParam defaults body Return Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad decorator_list FunctionDef arguments args NameParam defaults body TryExcept body Return AttributeLoad AttributeLoad NameLoad attr attr handlers ExceptHandler type NameLoad body Return AttributeLoad AttributeLoad NameLoad attr attr decorator_list NameLoad FunctionDef arguments args NameParam NameParam NameParam defaults NameLoad body Expr Str Assign NameStore Call AttributeLoad NameLoad attr NameLoad If CompareIs NameLoad NameLoad body Return BinOpDiv NameLoad Call AttributeLoad NameLoad attr NameLoad keyword Num keyword NameLoad orelse Return NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam NameParam NameParam defaults Num Num NameLoad body Expr Str If CompareEq NameLoad Num body Assign NameStore Call NameLoad AttributeLoad NameLoad attr orelse If Call NameLoad NameLoad NameLoad body Assign NameStore TupleLoad NameLoad For NameStore NameLoad body Assign NameStore SubscriptLoad AttributeLoad AttributeLoad NameLoad attr attr Index NameLoad If CompareIs NameLoad NameLoad body Expr Yield TupleLoad NameLoad Call NameLoad GeneratorExp SubscriptLoad NameLoad Index NameLoad comprehension NameStore SubscriptLoad Call AttributeLoad NameLoad attr NameLoad Slice BinOpSub UnaryOpUSub NameLoad Num Num orelse Expr Yield TupleLoad NameLoad Call NameLoad GeneratorExp TupleLoad SubscriptLoad NameLoad Index NameLoad SubscriptLoad NameLoad Index NameLoad comprehension NameStore SubscriptLoad Call AttributeLoad NameLoad attr NameLoad Slice BinOpSub UnaryOpUSub NameLoad Num Num decorator_list FunctionDef arguments args NameParam NameParam NameParam NameParam NameParam defaults Num Num NameLoad body Expr Str If CompareEq NameLoad Num body Assign NameStore Call NameLoad AttributeLoad NameLoad attr orelse If Call NameLoad NameLoad NameLoad body Assign NameStore TupleLoad NameLoad For NameStore NameLoad body Assign NameStore SubscriptLoad Call AttributeLoad NameLoad attr SubscriptLoad NameLoad ExtSlice Slice Index NameLoad Slice BinOpSub UnaryOpUSub NameLoad Num Num If CompareIs NameLoad NameLoad body Expr Yield TupleLoad NameLoad Call NameLoad GeneratorExp NameLoad comprehension NameStore NameLoad orelse Expr Yield TupleLoad NameLoad Call NameLoad GeneratorExp TupleLoad NameLoad SubscriptLoad NameLoad Index TupleLoad NameLoad NameLoad comprehension NameStore NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam NameParam NameParam defaults Num Num NameLoad body Expr Str If CompareEq NameLoad Num body Assign NameStore Call NameLoad SubscriptLoad AttributeLoad NameLoad attr Index Num orelse If Call NameLoad NameLoad NameLoad body Assign NameStore TupleLoad NameLoad For NameStore NameLoad body Assign NameStore SubscriptLoad Call AttributeLoad NameLoad attr SubscriptLoad NameLoad ExtSlice Index NameLoad Slice Slice BinOpSub UnaryOpUSub NameLoad Num Num If CompareIs NameLoad NameLoad body Expr Yield TupleLoad NameLoad Call NameLoad GeneratorExp NameLoad comprehension NameStore NameLoad orelse Expr Yield TupleLoad NameLoad Call NameLoad GeneratorExp TupleLoad NameLoad SubscriptLoad NameLoad Index TupleLoad NameLoad NameLoad comprehension NameStore NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str Return BinOpDiv Call AttributeLoad NameLoad attr keyword Num Call AttributeLoad Call AttributeLoad NameLoad attr keyword Num attr decorator_list decorator_list
N/A N/A 
Train and apply a topic model to vectorized texts. For example::

    >>> # first, stream a corpus with metadata from disk
    >>> pages = ([pid, title, text] for pid, title, text
    ...          in textacy.corpora.wikipedia.get_plaintext_pages('enwiki-latest-pages-articles.xml.bz2', max_n_pages=100))
    >>> content_stream, metadata_stream = textacy.fileio.read.split_content_and_metadata(pages, 2, itemwise=False)
    >>> metadata_stream = ({'pageid': m[0], 'title': m[1]} for m in metadata_stream)
    >>> corpus = textacy.TextCorpus.from_texts('en', content_stream, metadata=metadata_stream)
    >>> # next, tokenize and vectorize the corpus
    >>> terms_lists = (doc.as_terms_list(words=True, ngrams=False, named_entities=True)
    ...                for doc in corpus)
    >>> doc_term_matrix, id2term = corpus.as_doc_term_matrix(
    ...     terms_lists, weighting='tfidf', normalize=True, smooth_idf=True,
    ...     min_df=3, max_df=0.95, max_n_terms=100000)
    >>> # now initialize and train a topic model
    >>> model = textacy.tm.TopicModel('nmf', n_topics=20)
    >>> model.fit(doc_term_matrix)
    >>> # transform the corpus and interpret our model
    >>> doc_topic_matrix = model.transform(doc_term_matrix)
    >>> for topic_idx, top_terms in model.top_topic_terms(id2term, top_n=10):
    ...     print('topic {}:'.format(topic_idx), '   '.join(top_terms))
    >>> for topic_idx, top_docs in model.top_topic_docs(doc_topic_matrix, top_n=5):
    ...     print('
{}'.format(topic_idx))
    ...     for j in top_docs:
    ...         print(corpus[j].metadata['title'])
    >>> for doc_idx, topics in model.top_doc_topics(doc_topic_matrix, docs=range(5), top_n=2):
    ...     print('{}: {}'.format(corpus[doc_idx].metadata['title'], topics))
    >>> for i, val in enumerate(model.topic_weights(doc_topic_matrix)):
    ...     print(i, val)
    >>> # assess topic quality through a coherence metric
    >>> # WIP...
    >>> # persist our topic model to disk
    >>> model.save('nmf-20topics.pkl')
 N/A logging N/A numpy np sklearn.decomposition NMF LatentDirichletAllocation TruncatedSVD sklearn.externals joblib N/A logger N/A N/A logging getLogger __name__ TopicModel N/A object N/A N/A 
    Args:
        model ({'nmf', 'lda', 'lsa'} or ``sklearn.decomposition.<model>``)
        n_topics (int, optional): number of topics in the model to be initialized
        kwargs:
            variety of parameters used to initialize the model; see individual
            sklearn pages for full details

    Raises:
        ValueError: if ``model`` not in ``{'nmf', 'lda', 'lsa'}`` or is not an
            NMF, LatentDirichletAllocation, or TruncatedSVD instance

    Notes:
        - http://scikit-learn.org/stable/modules/generated/sklearn.decomposition.NMF.html
        - http://scikit-learn.org/stable/modules/generated/sklearn.decomposition.LatentDirichletAllocation.html
        - http://scikit-learn.org/stable/modules/generated/sklearn.decomposition.TruncatedSVD.html
     __init__ N/A N/A self model n_topics N/A 10 kwargs N/A N/A N/A isinstance model N/A NMF LatentDirichletAllocation TruncatedSVD N/A N/A N/A self model model N/A N/A N/A N/A self init_model model n_topics n_topics kwargs N/A init_model N/A N/A self model n_topics N/A 10 kwargs N/A N/A N/A model nmf N/A N/A N/A self model N/A NMF n_components n_topics alpha N/A N/A kwargs get alpha 0.1 l1_ratio N/A N/A kwargs get l1_ratio 0.5 max_iter N/A N/A kwargs get max_iter 200 random_state N/A N/A kwargs get random_state 1 shuffle N/A N/A kwargs get shuffle False N/A N/A N/A model lda N/A N/A N/A self model N/A LatentDirichletAllocation n_topics n_topics max_iter N/A N/A kwargs get max_iter 10 random_state N/A N/A kwargs get random_state 1 learning_method N/A N/A kwargs get learning_method online learning_offset N/A N/A kwargs get learning_offset 10.0 batch_size N/A N/A kwargs get batch_size 128 n_jobs N/A N/A kwargs get n_jobs 1 N/A N/A N/A model lsa N/A N/A N/A self model N/A TruncatedSVD n_components n_topics algorithm N/A N/A kwargs get algorithm randomized n_iter N/A N/A kwargs get n_iter 5 random_state N/A N/A kwargs get random_state 1 N/A N/A msg N/A N/A model "{}" invalid; must be {} format model N/A nmf lda lsa N/A N/A ValueError msg N/A save N/A N/A self filename N/A N/A N/A _ N/A N/A joblib dump N/A self model filename compress 3 N/A N/A N/A logger info N/A N/A {} model saved to {} format N/A self model filename N/A load N/A N/A cls filename N/A N/A N/A model N/A N/A joblib load filename N/A n_topics N/A N/A hasattr model n_topics N/A model n_topics N/A model n_components N/A N/A cls model n_topics n_topics N/A classmethod fit N/A N/A self doc_term_matrix N/A N/A N/A N/A N/A N/A self model fit doc_term_matrix N/A partial_fit N/A N/A self doc_term_matrix N/A N/A N/A N/A isinstance N/A self model LatentDirichletAllocation N/A N/A N/A N/A N/A self model partial_fit doc_term_matrix N/A N/A N/A TypeError only LatentDirichletAllocation models have partial_fit N/A transform N/A N/A self doc_term_matrix N/A N/A N/A N/A N/A N/A self model transform doc_term_matrix N/A n_topics N/A N/A self N/A N/A N/A N/A N/A N/A N/A self model n_topics N/A N/A N/A AttributeError N/A N/A N/A N/A self model n_components N/A property get_doc_topic_matrix N/A N/A self doc_term_matrix normalize N/A True N/A N/A 
        Transform a document-term matrix into a document-topic matrix, where rows
        correspond to documents and columns to the topics in the topic model.

        Args:
            doc_term_matrix (array-like or sparse matrix): corpus represented as a
                document-term matrix with shape (n_docs, n_terms); NOTE: LDA expects
                tf-weighting, while NMF and LSA may do better with tfidf-weighting!
            normalize (bool, optional): if True, the values in each row are normalized,
                i.e. topic weights on each document sum to 1

        Returns:
            ``numpy.ndarray``: document-topic matrix with shape (n_docs, n_topics)
         N/A doc_topic_matrix N/A N/A self transform doc_term_matrix N/A N/A normalize True N/A N/A N/A doc_topic_matrix N/A N/A np sum doc_topic_matrix axis 1 keepdims True N/A N/A doc_topic_matrix N/A top_topic_terms N/A N/A self id2term topics top_n weights N/A -1 10 False N/A N/A 
        Get the top ``top_n`` terms by weight per topic in ``model``.

        Args:
            id2term (list(str) or dict): 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: term string
            topics (int or seq(int), optional): topic(s) for which to return top terms;
                if -1 (default), all topics' terms are returned
            top_n (int, optional): number of top terms to return per topic
            weights (bool, optional): if True, terms are returned with their corresponding
                topic weights; otherwise, terms are returned without weights

        Yields:
            tuple(int, tuple(str)) or tuple(int, tuple((str, float))):
                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)))]
         N/A N/A topics -1 N/A N/A topics N/A range N/A self n_topics N/A N/A N/A isinstance topics int N/A N/A topics N/A topics N/A topic_idx topics N/A N/A topic N/A N/A N/A self model components_ N/A topic_idx N/A N/A weights False N/A N/A N/A N/A topic_idx N/A tuple N/A N/A id2term N/A i N/A i N/A N/A N/A np argsort topic N/A N/A N/A top_n 1 -1 N/A N/A N/A N/A topic_idx N/A tuple N/A N/A N/A id2term N/A i N/A topic N/A i N/A i N/A N/A N/A np argsort topic N/A N/A N/A top_n 1 -1 N/A top_topic_docs N/A N/A self doc_topic_matrix topics top_n weights N/A -1 10 False N/A N/A 
        Get the top ``top_n`` docs by weight per topic in ``doc_topic_matrix``.

        Args:
            doc_topic_matrix (numpy.ndarray): document-topic matrix with shape
                (n_docs, n_topics), the result of calling
                :func:`get_doc_topic_matrix() <textacy.topic_modeling.get_doc_topic_matrix>`
            topics (seq(int) or int, optional): topic(s) for which to return top docs;
                if -1, all topics' docs are returned
            top_n (int, optional): number of top docs to return per topic
            weights (bool, optional): if True, docs are returned with their corresponding
                (normalized) topic weights; otherwise, docs are returned without weights

        Yields:
            tuple(int, tuple(int)) or tuple(int, tuple(int, float)):
                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 ints
                representing the top ``top_n`` related docs; otherwise, the second
                is a tuple of (int, float) pairs representing the top ``top_n``
                related docs and their associated weights wrt the topic; for example::

                    >>> list(TopicModel.top_doc_terms(dtm, topics=(0, 1), top_n=2, weights=False))
                    [(0, (4, 2)), (1, (1, 3))]
                    >>> list(TopicModel.top_doc_terms(dtm, topics=0, top_n=2, weights=True))
                    [(0, ((4, 0.3217), (2, 0.2154)))]
         N/A N/A topics -1 N/A N/A topics N/A range N/A self n_topics N/A N/A N/A isinstance topics int N/A N/A topics N/A topics N/A topic_idx topics N/A N/A top_doc_idxs N/A N/A N/A np argsort N/A doc_topic_matrix N/A N/A N/A topic_idx N/A N/A N/A top_n 1 -1 N/A N/A weights False N/A N/A N/A N/A topic_idx N/A tuple N/A doc_idx N/A doc_idx top_doc_idxs N/A N/A N/A N/A topic_idx N/A tuple N/A N/A doc_idx N/A doc_topic_matrix N/A N/A doc_idx topic_idx N/A doc_idx top_doc_idxs N/A top_doc_topics N/A N/A self doc_topic_matrix docs top_n weights N/A -1 3 False N/A N/A 
        Get the top ``top_n`` topics by weight per doc for ``docs`` in ``doc_topic_matrix``.

        Args:
            doc_topic_matrix (numpy.ndarray): document-topic matrix with shape
                (n_docs, n_topics), the result of calling
                :func:`get_doc_topic_matrix() <textacy.topic_modeling.get_doc_topic_matrix>`
            docs (seq(int) or int, optional): docs for which to return top topics;
                if -1, all docs' top topics are returned
            top_n (int, optional): number of top topics to return per doc
            weights (bool, optional): if True, docs are returned with their corresponding
                (normalized) topic weights; otherwise, docs are returned without weights

        Yields:
            tuple(int, tuple(int)) or tuple(int, tuple(int, float)):
                next tuple corresponding to a doc; the first element is the doc's
                index; if ``weights`` is False, the second element is a tuple of ints
                representing the top ``top_n`` related topics; otherwise, the second
                is a tuple of (int, float) pairs representing the top ``top_n``
                related topics and their associated weights wrt the doc; for example::

                    >>> list(TopicModel.top_doc_topics(dtm, docs=(0, 1), top_n=2, weights=False))
                    [(0, (1, 4)), (1, (3, 2))]
                    >>> list(TopicModel.top_doc_topics(dtm, docs=0, top_n=2, weights=True))
                    [(0, ((1, 0.2855), (4, 0.2412)))]
         N/A N/A docs -1 N/A N/A docs N/A range N/A N/A doc_topic_matrix shape N/A 0 N/A N/A N/A isinstance docs int N/A N/A docs N/A docs N/A doc_idx docs N/A N/A top_topic_idxs N/A N/A N/A np argsort N/A doc_topic_matrix N/A N/A doc_idx N/A N/A N/A N/A top_n 1 -1 N/A N/A weights False N/A N/A N/A N/A doc_idx N/A tuple N/A topic_idx N/A topic_idx top_topic_idxs N/A N/A N/A N/A doc_idx N/A tuple N/A N/A topic_idx N/A doc_topic_matrix N/A N/A doc_idx topic_idx N/A topic_idx top_topic_idxs N/A topic_weights N/A N/A self doc_topic_matrix N/A N/A N/A 
        Get the overall weight of topics across an entire corpus. Note: Values depend
        on whether topic weights per document in ``doc_topic_matrix`` were normalized,
        or not. I suppose either way makes sense... o_O

        Args:
            doc_topic_matrix (numpy.ndarray): document-topic matrix with shape
                (n_docs, n_topics), the result of calling
                :func:`get_doc_topic_matrix() <textacy.topic_modeling.get_doc_topic_matrix>`

        Returns:
            ``numpy.ndarray``: the ith element is the ith topic's overall weight
         N/A N/A N/A N/A doc_topic_matrix sum axis 0 N/A N/A N/A N/A doc_topic_matrix sum axis 0 sum N/A N/A