docstr: Fits a topic model to documents in <texts>.
  Example:
      tm = ktrain.text.get_topic_model(docs, n_topics=20,
                                      n_features=1000, min_df=2, max_df=0.95)
  Args:
      texts (list of str): list of texts
      n_topics (int): number of topics.
                      If None, n_topics = min{400, sqrt[# documents/2]})
      n_features (int):  maximum words to consider
      max_df (float): words in more than max_df proportion of docs discarded
      stop_words (str or list): either 'english' for built-in stop words or
                                a list of stop words to ignore
      model_type(str): type of topic model to fit. One of {'lda', 'nmf'}.  Default:'lda'
      max_iter (int): maximum iterations.  5 is default if using lda_mode='online' or nmf.
                          If lda_mode='batch', this should be increased (e.g., 1500).
      lda_max_iter (int): alias for max_iter for backwards compatilibity
      lda_mode (str):  one of {'online', 'batch'}. Ignored if model_type !='lda'
      token_pattern(str): regex pattern to use to tokenize documents.
      verbose(bool): verbosity
      hyperparam_kwargs(dict): hyperparameters for LDA/NMF
                               Keys in this dict can be any of the following:
                                   alpha: alpha for LDA  default: 5./n_topics
                                   beta: beta for LDA.  default:0.01
                                   nmf_alpha: alias for alpha for backwars compatilibity
                                   l1_ratio: l1_ratio for NMF. default: 0
                                   ngram_range:  whether to consider bigrams, trigrams. default: (1,1)
docstr_tok: ["Fits","a","topic","model","to","documents","in","<","texts",">",".","Example",":","tm","=","ktrain.text.get_topic_model","(","docs",",","n_topics=20",",","n_features=1000",",","min_df=2",",","max_df=0.95",")","Args",":","texts","(","list","of","str",")",":","list","of","texts","n_topics","(","int",")",":","number","of","topics",".","If","None",",","n_topics","=","min","{","400",",","sqrt","[","#","documents\/2","]","}",")","n_features","(","int",")",":","maximum","words","to","consider","max_df","(","float",")",":","words","in","more","than","max_df","proportion","of","docs","discarded","stop_words","(","str","or","list",")",":","either","'english","'","for","built-in","stop","words","or","a","list","of","stop","words","to","ignore","model_type","(","str",")",":","type","of","topic","model","to","fit",".","One","of","{","'lda","'",",","'nmf","'","}",".","Default",":","'lda'","max_iter","(","int",")",":","maximum","iterations",".","5","is","default","if","using","lda_mode='online","'","or","nmf",".","If","lda_mode='batch","'",",","this","should","be","increased","(","e.g.",",","1500",")",".","lda_max_iter","(","int",")",":","alias","for","max_iter","for","backwards","compatilibity","lda_mode","(","str",")",":","one","of","{","'online","'",",","'batch","'","}",".","Ignored","if","model_type","!","='lda'","token_pattern","(","str",")",":","regex","pattern","to","use","to","tokenize","documents",".","verbose","(","bool",")",":","verbosity","hyperparam_kwargs","(","dict",")",":","hyperparameters","for","LDA\/NMF","Keys","in","this","dict","can","be","any","of","the","following",":","alpha",":","alpha","for","LDA","default",":","5.\/n_topics","beta",":","beta","for","LDA",".","default:0.01","nmf_alpha",":","alias","for","alpha","for","backwars","compatilibity","l1_ratio",":","l1_ratio","for","NMF",".","default",":","0","ngram_range",":","whether","to","consider","bigrams",",","trigrams",".","default",":","(","1,1",")"]
code: def __init__(
      self,
      texts=None,
      n_topics=None,
      n_features=10000,
      min_df=5,
      max_df=0.5,
      stop_words="english",
      model_type="lda",
      max_iter=5,
      lda_max_iter=None,
      lda_mode="online",
      token_pattern=None,
      verbose=1,
      hyperparam_kwargs=None,
  ):
      """
      Fits a topic model to documents in <texts>.
      Example:
          tm = ktrain.text.get_topic_model(docs, n_topics=20,
                                          n_features=1000, min_df=2, max_df=0.95)
      Args:
          texts (list of str): list of texts
          n_topics (int): number of topics.
                          If None, n_topics = min{400, sqrt[# documents/2]})
          n_features (int):  maximum words to consider
          max_df (float): words in more than max_df proportion of docs discarded
          stop_words (str or list): either 'english' for built-in stop words or
                                    a list of stop words to ignore
          model_type(str): type of topic model to fit. One of {'lda', 'nmf'}.  Default:'lda'
          max_iter (int): maximum iterations.  5 is default if using lda_mode='online' or nmf.
                              If lda_mode='batch', this should be increased (e.g., 1500).
          lda_max_iter (int): alias for max_iter for backwards compatilibity
          lda_mode (str):  one of {'online', 'batch'}. Ignored if model_type !='lda'
          token_pattern(str): regex pattern to use to tokenize documents.
          verbose(bool): verbosity
          hyperparam_kwargs(dict): hyperparameters for LDA/NMF
                                   Keys in this dict can be any of the following:
                                       alpha: alpha for LDA  default: 5./n_topics
                                       beta: beta for LDA.  default:0.01
                                       nmf_alpha: alias for alpha for backwars compatilibity
                                       l1_ratio: l1_ratio for NMF. default: 0
                                       ngram_range:  whether to consider bigrams, trigrams. default: (1,1)
  
      """
      self.verbose = verbose
  
      # estimate n_topics
      if n_topics is None:
          if texts is None:
              raise ValueError(
                  "If n_topics is None, texts must be supplied"
              )
          estimated = max(1, int(math.floor(math.sqrt(len(texts) / 2))))
          n_topics = min(400, estimated)
          if verbose:
              print("n_topics automatically set to %s" % (n_topics))
  
      # train model
      if texts is not None:
          (model, vectorizer) = self.train(
              texts,
              model_type=model_type,
              n_topics=n_topics,
              n_features=n_features,
              min_df=min_df,
              max_df=max_df,
              stop_words=stop_words,
              max_iter=max_iter,
              lda_max_iter=lda_max_iter,
              lda_mode=lda_mode,
              token_pattern=token_pattern,
              hyperparam_kwargs=hyperparam_kwargs,
          )
      else:
          vectorizer = None
          model = None
  
      # save model and vectorizer and hyperparameter settings
      self.vectorizer = vectorizer
      self.model = model
      self.n_topics = n_topics
      self.n_features = n_features
      if verbose:
          print("done.")
  
      # these variables are set by self.build():
      self.topic_dict = None
      self.doc_topics = None
      self.bool_array = None
  
      self.scorer = None  # set by self.train_scorer()
      self.recommender = None  # set by self.train_recommender()
      return
  
imports: import time
  from ..None import utils
  from ..imports import *
  from .None import preprocessor
  from .None import textutils
label_desc: Use image node_id 1 to create a new TopicModel object  with example: obj = TopicModel(texts, n_topics, n_features, min_df, max_df, stop_words, model_type, max_iter, lda_max_iter, lda_mode, token_pattern, verbose, hyperparam_kwargs)