I would like to run this piece of rapidfuzz code mentioned in this post on a list with 200,000 elements. I am wondering what's the best way to optimize this for a faster run on GPU?
Find fuzzy match string in a list with matching string value and their count
import pandas as pd
from rapidfuzz import fuzz
elements = ['vikash', 'vikas', 'Vinod', 'Vikky', 'Akash', 'Vinodh', 'Sachin', 'Salman', 'Ajay', 'Suchin', 'Akash', 'vikahs']
results = [[name, [], 0] for name in elements]
for (i, element) in enumerate(elements):
for (j, choice) in enumerate(elements[i+1:]):
if fuzz.ratio(element, choice, score_cutoff=90):
results[i][2] += 1
results[i][1].append(choice)
results[j+i+1][2] += 1
results[j+i+1][1].append(element)
data = pd.DataFrame(results, columns=['name', 'duplicates', 'duplicate_count'])
Expected Output -
name duplicates duplicate_count
0 vikash [vikas] 1
1 vikas [vikash, vikahs] 2
2 Vinod [Vinodh] 1
3 Vikky [] 0
4 Akash [Akash] 1
5 Vinodh [Vinod] 1
6 Sachin [] 0
7 Salman [] 0
8 Ajay [] 0
9 Suchin [] 0
10 Akash [Akash] 1
11 vikahs [vikas] 1
The
rapidfuzz
library has a function for speedup which takes the parallel processing power of CPU to quicken the process.The
workers
argument enables parallel processing. With the valueworkers=-1
, you will be using all the cores available.Output