Approximate Text Deduplication With SimHash
The Approximate Text Deduplication with SimHash operator uses the SimHash algorithm to generate a digital fingerprint for text. The operator compares these fingerprints using their Hamming distance to quickly identify near-duplicate items. This operator is primarily used for fuzzy deduplication of long texts (over 1,000 words), such as identifying repeated malicious comments from the same user or merging knowledge base entries with similar questions. For short texts, this operator is not recommended as their sparse features can lead to false positives. This topic explains how to configure the Approximate Text Deduplication with SimHash operator.
Prerequisites
Using the workflow feature requires you to purchase the unstructured data processing feature for your instance.
You have created a workflow. For more information, see Create and manage a workflow.
Permissions
In a Basic project, project administrators, developers, analysts, and custom project roles with the Dataset-Use permission can use all datasets within the project for the operator's input and output.
Supported data format
The Approximate Text Deduplication with SimHash operator processes text from the specified input field. If the field contains a URL, the operator fetches and parses the content at that URL; otherwise, it treats the field's value as plain text.
Procedure
In the top menu bar of the Dataphin homepage, choose Develop > Data Development.
In the top menu bar of the Develop page, select your project.
In the left-side navigation pane, choose Data Processing > Workflow. From the Workflow list, click the target workflow to open its canvas. Drag the SimHash Approximate Text Deduplication operator from the Operator Library on the left to the canvas. Configure the parameters in the SimHash Approximate Text Deduplication pane that appears on the right.
Parameter
Description
Step name
Enter a name for the operator. The name can contain any characters and be up to 256 characters long.
Input configuration
Dataset
Select the dataset to process. You can select a hybrid dataset or a table dataset. After you select a dataset, you must also select a version. By default, the first version of the dataset in ascending order is selected.
If this operator is downstream of another, this dataset is typically the output dataset of the upstream operator.
Input field
The system processes the input based on the field type:
If the field is a URL type, the system automatically fetches the resource that the link points to and parses its structured or semi-structured content (from file formats such as .txt, .md, .csv, .json, .xml, and .html).
If the field is not a URL, the system treats its value as plain text.
NoteEstimate the document size after parsing. If the input exceeds the model's maximum length, the system may truncate or reject it, affecting the integrity of the analysis results.
Filter condition (Optional)
Enter a filter condition using SQL syntax. You only need to provide the content that follows the
WHEREclause. You can use global system variables, such as${bizdate}.Operator configuration
Function mode
The SimHash Approximate Text Deduplication operator supports the following three function modes:
Compare and Mark Duplicates: Calculates the SimHash value for the input text and compares it against a pre-calculated SimHash field in a comparison dataset. It then marks whether the input is a duplicate based on the selected criterion without deleting or modifying the input content.
Calculate SimHash Only: Calculates the SimHash value for the input content without deleting or modifying it.
NoteCompare and Mark Duplicates and Calculate SimHash Only are supported in offline, real-time, and online workflows.
Null values in a dataset are not processed during deduplication.
Comparison dataset
Select the dataset that stores the reference SimHash values for comparison. The operator compares these values with the input field to identify duplicates. You can select a hybrid dataset or a table dataset.
NoteThis parameter is available only when function mode is set to Compare and Mark Duplicates.
Comparison SimHash field
Select the field that serves as the comparison baseline. This field must contain pre-calculated SimHash values from the comparison dataset. The operator compares the SimHash value of the input field against this reference field based on the selected duplication criterion. It does not recalculate the values in this field.
NoteThis parameter is available only when function mode is set to Compare and Mark Duplicates.
Duplication criterion
After calculating the SimHash values for two texts, the system calculated their Hamming distance. A smaller Hamming distance indicates greater similarity.
Only highly similar is a duplicate: Hamming distance is less than or equal to 1.
Moderately similar is a duplicate: Hamming distance is less than or equal to 3. This is the recommended setting.
Slightly similar is a duplicate: Hamming distance is less than or equal to 5.
NoteThis parameter is available only when function mode is set to Compare and Mark Duplicates.
Output configuration
Dataset
You can choose to write the output to the source dataset (the output is written back to the source dataset) or an Other Dataset (the output is written to a specified dataset). If the metadata table of the source dataset does not have a primary key, the output must be written to another dataset.
If you select another dataset, you must also specify a hybrid dataset or table dataset and its version as the output dataset. By default, the first version of the dataset in ascending order is selected. You can also select a different version of the source dataset.
If you select source dataset, the output metadata is written to the corresponding metadata table of the same version of the source dataset.
Load policy
If the metadata table of the selected output dataset contains a primary key, the default behavior is to update records on a primary key conflict. If a primary key does not exist, the default behavior is to append data.
Append data: Appends data directly to the target table. If a primary key or constraint conflict occurs, an error is reported.
Update on primary key conflict: When a primary key or constraint conflict occurs, the system deletes the existing row and then inserts the new data.
Overwrite: Deletes the data in the target table and then writes new data.
NoteWhen the function mode is set to Compare and Deduplicate or Calculate SimHash only and the output dataset is set to Source Dataset, the load policy only supports Update on Primary Key Conflict.
Field mapping
The SimHash Approximate Text Deduplication operator always outputs the following fields:
is_duplicate: Specifies whether the input content is a duplicate of the value in the comparison SimHash field. The possible values areyes(duplicate),no(not a duplicate), andfailed(calculation failed). This field is output only when the function mode is set to Comparison and Deduplication, and the output dataset is set to Other Dataset.simhash: The SimHash signature value.
By default, the operator's output fields are mapped to fields with the same name in the output dataset. You can also manually select target fields for custom mapping. Additionally, you can map passthrough fields from the source dataset to the target dataset. You can manage field mappings in the following ways:
Add Output Field: Click to add a new, empty field mapping row. This feature is supported only when the output dataset is set to Other Dataset.
Batch Mapping: Click to open batch mapping options, such as map by name and map by row number. This feature is supported only when the output dataset is set to Other Dataset.
Delete Mapping: Click the Delete icon to remove a field mapping row. You cannot delete the mapping for the operator's required output fields.
NoteWhen function mode is set to Compare and Mark Duplicates, mapping the
simhashfield is optional.After you finish the configuration, click Save in the menu bar at the top of the canvas.
After you configure an operator, you can connect it to upstream or downstream operators to complete your workflow.