code: def get_user_item_recommendations(
      n_users: int,
      n_items: int,
      args: dict,
      item_ids,
      user_ids,
      model: lightfm.LightFM,
  ):
      """
      gets N user-item recommendations for a given model
      :param n_users:
      :param n_items:
      :param args:
      :param item_ids:
      :param user_ids:
      :param model:
  
      :return:
      """
      # get idxs for user-item pairs
      item_idxs, user_idxs = get_item_user_idx(
          args, n_users, n_items, item_ids, user_ids
      )
  
      scores = model.predict(user_ids=user_idxs, item_ids=item_idxs)
  
      # map scores to user-item pairs, sort by score and return top N recommendations per user
      user_item_recommendations_df = (
          pd.DataFrame(
              {
                  "user_idx": user_idxs,
                  "item_idx": item_idxs,
                  "score": scores,
              }
          )
          .groupby("user_idx")
          .apply(
              lambda x: x.sort_values("score", ascending=False).head(
                  args["n_recommendations"]
              )
          )
      )
  
      # map idxs to item ids and user ids
      user_item_recommendations_df["item_id"] = (
          user_item_recommendations_df["item_idx"]
          .astype("str")
          .map(args["item_idx_to_id_map"])
      )
      user_item_recommendations_df["user_id"] = (
          user_item_recommendations_df["user_idx"]
          .astype("str")
          .map(args["user_idx_to_id_map"])
      )
  
      return user_item_recommendations_df[
          ["user_id", "item_id", "score"]
      ]
  
imports: import lightfm
  import numpy
  import pandas
label_desc: Use image node_id 2 for calling a global function with example usage: get_user_item_recommendations(n_users, n_items, args, item_ids, user_ids, model) and returns: user_item_recommendations_df