Datasets:

Modalities:
Text
Formats:
json
Languages:
English
ArXiv:
License:

Duplicates and Contamination

#2
by vlhandfo - opened

When working with this dataset, I found that there are duplicated instances in this dataset, including sentence pairs that appear in multiple partitions. There are also 11 instances where the sentence pairs are the same, but the scores are different. I have included my EDA code below:

from datasets import load_dataset
import pandas as pd

dataset = load_dataset("mteb/stsbenchmark-sts")

# Convert the dataset to a pandas DataFrame for easier manipulation
train_df = pd.DataFrame(dataset['train'])
dev_df = pd.DataFrame(dataset['validation'])
test_df = pd.DataFrame(dataset['test'])

# Combine all splits into a single DataFrame for duplication analysis
all_df = pd.concat([train_df, dev_df, test_df], ignore_index=True).reset_index(drop=True)

duplicated_sentence_pairs = all_df[all_df[['sentence1', 'sentence2']].duplicated(keep=False)]
# display(duplicated_sentence_pairs.sort_values(by=['sentence1', 'sentence2']))
num_duplicated_pairs = duplicated_sentence_pairs[['sentence1', 'sentence2']].drop_duplicates().shape[0]
print("Number of (sentence1, sentence2) pairs appearing in multiple times:", num_duplicated_pairs)
# >> 55

# keep duplicated sentence pairs that appear in more than one split
duplicated_cross_split = duplicated_sentence_pairs[
    duplicated_sentence_pairs.groupby(['sentence1', 'sentence2'])['split'].transform('nunique') > 1
].sort_values(by=['sentence1', 'sentence2', 'split'])
num_unique_pairs = duplicated_cross_split[['sentence1', 'sentence2']].drop_duplicates().shape[0]
print("Number of (sentence1, sentence2) pairs appearing in multiple splits:", num_unique_pairs)
# >> 15

contamination_counts = {}
for i, group in duplicated_cross_split.groupby(['sentence1', 'sentence2']):
    contamination_type = tuple(set(group["split"].tolist()))
    contamination_counts[contamination_type] = contamination_counts.get(contamination_type, 0) + 1

print("Number of different types of contamination:", contamination_counts)
# >> {('train', 'dev'): 6, ('test', 'train'): 7, ('test', 'dev'): 2}

same_score = duplicated_sentence_pairs[duplicated_sentence_pairs[['sentence1', 'sentence2', 'score']].duplicated(keep=False)].sort_values(by=['sentence1', 'sentence2'])

rows_not_in_same_score = duplicated_sentence_pairs.loc[duplicated_sentence_pairs.index.difference(same_score.index)].sort_values(by=['sentence1', 'sentence2'])
print("Instances of the same sentence pairs with different scores:", len(rows_not_in_same_score) // 2)
# >> 11

Sign up or log in to comment