topic models besides document termsphrases and similaritieswe can also use some summarization techniques to extract topic or concept based features from text documents the idea of topic models revolves around the process of extracting key themes or concepts from corpus of documents which are represented as topics each topic can be represented as bag or collection of words/terms from the document corpus togetherthese terms signify specific topictheme or concept and each topic can be easily distinguished from other topics by virtue of the semantic meaning conveyed by these terms these concepts can range from simple facts and statements to opinions and outlook topic models are extremely useful in summarizing large corpus of text documents to extract and depict key concepts they are also useful in extracting features from text data that capture latent patterns in the data there are various techniques for topic modeling and most of them involve some form of matrix decomposition some techniques like latent semantic indexing (lsiuse matrix decomposition operationsmore specifically singular valued decomposition (refer back to important mathematical concepts in )to split term-document matrix (transpose of our tf-idf document-term feature matrixinto three matricesus vt you can use the left singular vectors in matrix and multiply it by the singular vectors to get terms and their weights (signifying importanceper topic you can use scikit-learn or gensim to use lsi based topic modeling another technique is latent dirichlet allocation (lda)which uses generative probabilistic model where each document consists of combination of several topics and each term or word can be assigned to specific topic this is similar to plsi based model (probabilistic lsieach latent topic contains dirichlet prior over them in the case of lda the math behind this is pretty involving and it would not be possible to go into details in the current scope interested readers can refer to page of text analytics with python (apressdipanjan sarkar for further details on lda for the purpose of feature engineeringyou need to remember that when lda is applied on document-term matrix (tf-idf feature matrix)it gets decomposed into two main components document-topic matrixwhich would be the feature matrix we are looking for and topic-term matrixwhich helps us in looking at potential topics in the corpus the following code builds an lda model to extract features and topics from our sample corpus in [ ]from sklearn decomposition import latentdirichletallocation lda latentdirichletallocation(n_topics= max_iter= random_state= dt_matrix lda fit_transform(tv_matrixfeatures pd dataframe(dt_matrixcolumns=[' '' ']features out[ ] thusthe dt_matrix refers to the document-topic matrix giving us two features since we chose number of topics to be you can also use the other matrix obtained from the decompositionthe topic-term matrix to see the topics extracted from our corpus using the lda model using the following code in [ ]tt_matrix lda components_ for topic_weights in tt_matrixtopic [(tokenweightfor tokenweight in zip(vocabtopic_weights)topic sorted(topickey=lambda - [ ]