Oh, I now realize that dok_matrix is not needed now. I will explain you clearly, why I added dok_matrix. This code of building cost_matrix was done before in the scoreDuplicateConstrained function, which is now outdated. Here https://github.com/nikitsaraf/dedupe/blob/195bd38532f19dda62883029d5ed3ce99598ac4e/dedupe/core.py#L196-198 using the pairs of the ids, the coordinate matrix was created. So, in that the id_list would contain duplicate pairs of records. Hence, I needed to suppress that duplicacy, so I had used dok_matrix function. Now, here we don't require dok_matrix.