I think this is deprecated.
Have you already checked:

  
      

      TensorFlow
  

  
    

tf.sparse.from_dense  |  TensorFlow Core v2.5.0 1

  Converts a dense tensor into a sparse tensor.


  

  
    
    
  

  


And more in general the sparse tensor guide

  
      

      TensorFlow
  

  
    

Working with sparse tensors  |  TensorFlow Core 1