Skip to content

Chapter 10, page 306 #57

@xyang2013

Description

@xyang2013

Should soft_negatives defined as follow instead?

def deranged_shuffle(original):
    while True:
        shuffled = original.copy()
        random.shuffle(shuffled)
        if all(o != s for o, s in zip(original, shuffled)):
            return shuffled

mnli = mnli.filter(lambda x: True if x["label"] == 0 else False)

# Prepare data and add a soft negative
train_dataset = {"anchor": [], "positive": [], "negative": []}
# soft_negatives = mnli["hypothesis"]
# random.shuffle(soft_negatives)
soft_negatives = deranged_shuffle(mnli["hypothesis"])
for row, soft_negative in tqdm(zip(mnli, soft_negatives)):
    train_dataset["anchor"].append(row["premise"])
    train_dataset["positive"].append(row["hypothesis"])
    train_dataset["negative"].append(soft_negative)
train_dataset = Dataset.from_dict(train_dataset)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions