code: def _hfd5_from_dataframe(data, outputfilename):
      items = data["mid"].cat.codes.copy()
      users = data["uid"].cat.codes.copy()
      values = np.ones(len(items)).astype(np.float32)
  
      # create a sparse matrix of all the item/users/likes
      likes = (
          coo_matrix((values, (items, users)))
          .astype(np.float32)
          .tocsr()
      )
  
      with h5py.File(outputfilename, "w") as f:
          g = f.create_group("item_user_likes")
          g.create_dataset("data", data=likes.data)
          g.create_dataset("indptr", data=likes.indptr)
          g.create_dataset("indices", data=likes.indices)
  
          dt = h5py.special_dtype(vlen=str)
          item = list(data["mid"].cat.categories)
          dset = f.create_dataset("item", (len(item),), dtype=dt)
          dset[:] = item
  
          user = list(data["uid"].cat.categories)
          dset = f.create_dataset("user", (len(user),), dtype=dt)
          dset[:] = user
  
file_path: implicit/implicit/datasets/sketchfab.py
imports: import logging
  import os
  import time
  import h5py
  import numpy
  from scipy.sparse import coo_matrix, csr_matrix
  from implicit.datasets import _download
label_desc: Use image node_id 4 for calling a global function with example usage: _hfd5_from_dataframe(data, outputfilename) without return types