parameters: (self)
docstring: :description: creates new batch with parent level topics as documents
docstring_summary: :description: creates new batch with parent level topics as documents
docstring_tokens: : description : creates new batch with parent level topics as documents
function: def _create_parent_phi_batch(self):
          """
          :description: creates new batch with parent level topics as documents
          """
          batch_dict = {}
          NNZ = 0
          batch = artm.messages.Batch()
          batch.id = str(uuid.uuid4())
          batch_id = batch.id
          batch.description = "__parent_phi_matrix_batch__"
          for topic_name_idx in range(len(self._parent_model.topic_names)):
              topic_name = self._parent_model.topic_names[topic_name_idx]
              if self._model_name == "p_wt":
                  phi = self._parent_model.get_phi(
                      topic_names={topic_name}, model_name=self._parent_model.model_pwt)
              else:
                  phi = self._parent_model.get_phi(
                      topic_names={topic_name}, model_name=self._parent_model.model_nwt)
              if not topic_name_idx:
                  # batch.token is the same for all topics, create it once
                  topics_and_tokens_info = \
                      self._parent_model.master.get_phi_info(
                          self._parent_model.model_nwt)
                  for token, class_id in \
                          zip(topics_and_tokens_info.token, topics_and_tokens_info.class_id):
                      if token not in batch_dict:
                          batch.token.append(token)
                          batch.class_id.append(class_id)
                          batch_dict[token] = len(batch.token) - 1
  
              # add item (topic) to batch
              item = batch.item.add()
              item.title = topic_name
              field = item.field.add()
              indices = phi[topic_name] > 0
              for class_token_tt, weight in  \
                      zip(phi.index[indices], phi[topic_name][indices]):
                  field.token_id.append(batch_dict[class_token_tt[1]])
                  field.token_weight.append(float(weight))
                  NNZ += weight
          self.parent_batch = batch
          with open(self._phi_batch_path, 'wb') as fout:
              fout.write(batch.SerializeToString())
function_tokens: def _create_parent_phi_batch ( self ) : batch_dict = { } NNZ = 0 batch = artm . messages . Batch ( ) batch . id = str ( uuid . uuid4 ( ) ) batch_id = batch . id batch . description = "__parent_phi_matrix_batch__" for topic_name_idx in range ( len ( self . _parent_model . topic_names ) ) : topic_name = self . _parent_model . topic_names [ topic_name_idx ] if self . _model_name == "p_wt" : phi = self . _parent_model . get_phi ( topic_names = { topic_name } , model_name = self . _parent_model . model_pwt ) else : phi = self . _parent_model . get_phi ( topic_names = { topic_name } , model_name = self . _parent_model . model_nwt ) if not topic_name_idx : # batch.token is the same for all topics, create it once topics_and_tokens_info = self . _parent_model . master . get_phi_info ( self . _parent_model . model_nwt ) for token , class_id in zip ( topics_and_tokens_info . token , topics_and_tokens_info . class_id ) : if token not in batch_dict : batch . token . append ( token ) batch . class_id . append ( class_id ) batch_dict [ token ] = len ( batch . token ) - 1 # add item (topic) to batch item = batch . item . add ( ) item . title = topic_name field = item . field . add ( ) indices = phi [ topic_name ] > 0 for class_token_tt , weight in zip ( phi . index [ indices ] , phi [ topic_name ] [ indices ] ) : field . token_id . append ( batch_dict [ class_token_tt [ 1 ] ] ) field . token_weight . append ( float ( weight ) ) NNZ += weight self . parent_batch = batch with open ( self . _phi_batch_path , 'wb' ) as fout : fout . write ( batch . SerializeToString ( ) )