class_docstr: Base class for a recommender model supporting Approximate Nearest Neighbor (ANN) search.
  
  Parameters
  ----------------
  model: object: :obj:`cornac.models.Recommender`, required
      Trained recommender model which to get user/item vectors from.
  
  name: str, required
      Name of the recommender model.
  
  verbose: boolean, optional, default: False
      When True, running logs are displayed.
class_docstr_tok: ["Base","class","for","a","recommender","model","supporting","Approximate","Nearest","Neighbor","(","ANN",")","search",".","Parameters","--","--","--","--","--","--","--","--","model",":","object",":",":","obj",":","`","cornac.models.Recommender","`",",","required","Trained","recommender","model","which","to","get","user\/item","vectors","from",".","name",":","str",",","required","Name","of","the","recommender","model",".","verbose",":","boolean",",","optional",",","default",":","False","When","True",",","running","logs","are","displayed","."]
docstr: Generate top-K item recommendations for a given batch of users. This is to leverage
  parallelization provided by some ANN frameworks.
  
  Parameters
  ----------
  batch_users: list, required
      The original ID of users.
  
  k: int, optional, default=-1
      Cut-off length for recommendations, k=-1 will return ranked list of all items.
  
  remove_seen: bool, optional, default: False
      Remove seen/known items during training and validation from output recommendations.
      This might shrink the list of recommendations to be less than k.
  
  train_set: :obj:`cornac.data.Dataset`, optional, default: None
      Training dataset needs to be provided in order to remove seen items.
  
  Returns
  -------
  recommendations: list
      Recommended items in the form of their original IDs.
docstr_tok: ["Generate","top-K","item","recommendations","for","a","given","batch","of","users",".","This","is","to","leverage","parallelization","provided","by","some","ANN","frameworks",".","Parameters","--","--","--","--","--","batch_users",":","list",",","required","The","original","ID","of","users",".","k",":","int",",","optional",",","default=-1","Cut-off","length","for","recommendations",",","k=-1","will","return","ranked","list","of","all","items",".","remove_seen",":","bool",",","optional",",","default",":","False","Remove","seen\/known","items","during","training","and","validation","from","output","recommendations",".","This","might","shrink","the","list","of","recommendations","to","be","less","than","k.","train_set",":",":","obj",":","`","cornac.data.Dataset","`",",","optional",",","default",":","None","Training","dataset","needs","to","be","provided","in","order","to","remove","seen","items",".","Returns","--","--","--","-","recommendations",":","list","Recommended","items","in","the","form","of","their","original","IDs","."]
code: def recommend_batch(
      self, batch_users, k=-1, remove_seen=False, train_set=None
  ):
      """Generate top-K item recommendations for a given batch of users. This is to leverage
      parallelization provided by some ANN frameworks.
  
      Parameters
      ----------
      batch_users: list, required
          The original ID of users.
  
      k: int, optional, default=-1
          Cut-off length for recommendations, k=-1 will return ranked list of all items.
  
      remove_seen: bool, optional, default: False
          Remove seen/known items during training and validation from output recommendations.
          This might shrink the list of recommendations to be less than k.
  
      train_set: :obj:`cornac.data.Dataset`, optional, default: None
          Training dataset needs to be provided in order to remove seen items.
  
      Returns
      -------
      recommendations: list
          Recommended items in the form of their original IDs.
      """
      user_idx = [self.uid_map.get(uid, -1) for uid in batch_users]
  
      if any(i == -1 for i in user_idx):
          raise ValueError(f"{batch_users} is unknown to the model.")
  
      if k < -1 or k > self.total_items:
          raise ValueError(
              f"k={k} is invalid, there are {self.total_users} users in total."
          )
  
      query = self.user_vectors[user_idx]
      knn_items, distances = self.knn_query(query, k=k)
  
      if remove_seen:
          if train_set is None:
              raise ValueError(
                  "train_set must be provided to remove seen items."
              )
          filtered_knn_items = []
          for u, i in zip(user_idx, knn_items):
              if u >= train_set.csr_matrix.shape[0]:
                  continue
              seen_mask = np.in1d(
                  np.arange(i.size),
                  train_set.csr_matrix.getrow(u).indices,
              )
              filtered_knn_items.append(i[~seen_mask])
          knn_items = filtered_knn_items
  
      recommendations = [
          [self.item_ids[i] for i in knn_items[u]]
          for u in range(len(user_idx))
      ]
      return recommendations
  
file_path: cornac/cornac/models/ann/recom_ann_base.py
imports: import copy
  import warnings
  import numpy
  from ..recommender import Recommender
  from ..recommender import is_ann_supported
  from ..recommender import MEASURE_DOT, MEASURE_COSINE
label_desc: Use image node_id 7 for calling the BaseANN obj's underlying member method code with example usage: obj.recommend_batch(batch_users, k, remove_seen, train_set) and returns: recommendations