I have a very large dataset (tens of thousands of records) that I want to deduplicate so I'm reading it in using a file stream and want to use a minhash to identify duplicate objects (those that are similar).
This "works" but is incredibly inefficient and was wondering if anyone has any experience doing something similar that isn't exponential run time.
The reason I am using minhash is because some text that isn't identical can be the same thing with slight modifications in the dataset.
ie: "this is some long form text where most of this will be the same as something else" vs. "this is some long form text where most of this will be the same as something else too"
Here's my code for an example:
const ndjson = require('ndjson')
const fs = require('fs');
var rawData = [];
fs.createReadStream("test-dataset.ndjson")
.pipe(ndjson.parse())
.on('data', (row) => {
// Loads new line delimited JSON file into an object;
rawData.push(row);
})
.on('end', () => {
var deduped = [];
rawData.forEach(item => {
if (filtered.length == 0) {
deduped.push(item);
} else {
var unique = true;
for (let i = 0; i < filtered.length; i++) {
const current = deduped[i];
var jaccard = compareTextMinhash(item.text, current.text); // minhash works
if (jaccard >= .9) {
unique = false;
break;
}
}
if (unique) deduped.push(item);
}
});
return deduped;
});