Update README.md
Browse files
README.md
CHANGED
|
@@ -41,22 +41,37 @@ These changes have been made in order to apply SimCSE method.
|
|
| 41 |
from datasets import load_dataset
|
| 42 |
from tqdm import tqdm
|
| 43 |
import pandas as pd
|
|
|
|
| 44 |
|
| 45 |
def create_trios(df, save_path):
|
| 46 |
list_of_examples = []
|
| 47 |
unique_premises = df.drop_duplicates("premise")["premise"]
|
| 48 |
for premise in tqdm(unique_premises):
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
examples_df = pd.DataFrame(list_of_examples, columns=["premise", "entailment", "contradiction"])
|
| 53 |
-
examples_df.dropna(inplace=True)
|
| 54 |
examples_df.to_csv(save_path)
|
| 55 |
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
```
|
| 61 |
|
| 62 |
**How to download**
|
|
|
|
| 41 |
from datasets import load_dataset
|
| 42 |
from tqdm import tqdm
|
| 43 |
import pandas as pd
|
| 44 |
+
import numpy as np
|
| 45 |
|
| 46 |
def create_trios(df, save_path):
|
| 47 |
list_of_examples = []
|
| 48 |
unique_premises = df.drop_duplicates("premise")["premise"]
|
| 49 |
for premise in tqdm(unique_premises):
|
| 50 |
+
premise_dataset = df[(df["premise"] == premise)]
|
| 51 |
+
positive_examples = premise_dataset[premise_dataset["label"] == "entailment"]["hypothesis"]
|
| 52 |
+
negative_examples = premise_dataset[premise_dataset["label"] == "contradiction"]["hypothesis"]
|
| 53 |
+
|
| 54 |
+
if len(positive_examples) == 0 or len(negative_examples) == 0:
|
| 55 |
+
continue
|
| 56 |
+
|
| 57 |
+
for positive_example in positive_examples:
|
| 58 |
+
for negative_example in negative_examples:
|
| 59 |
+
list_of_examples.append((premise, positive_example, negative_example))
|
| 60 |
+
|
| 61 |
+
|
| 62 |
examples_df = pd.DataFrame(list_of_examples, columns=["premise", "entailment", "contradiction"])
|
|
|
|
| 63 |
examples_df.to_csv(save_path)
|
| 64 |
|
| 65 |
+
|
| 66 |
+
if __name__ == "__main__":
|
| 67 |
+
dataset1 = load_dataset("kor_nli", "snli")["train"]
|
| 68 |
+
dataset2 = load_dataset("kor_nli", "multi_nli")["train"]
|
| 69 |
+
df_1 = pd.DataFrame(dataset1)
|
| 70 |
+
df_2 = pd.DataFrame(dataset2)
|
| 71 |
+
df_full = pd.concat([df_1, df_2])
|
| 72 |
+
df_full.dropna(inplace=True)
|
| 73 |
+
df_full["label"] = ["neutral" if label == 1 else "contradiction" if label == 2 else "entailment" for label in df_full["label"]]
|
| 74 |
+
create_trios(df_full, <insert your path>)
|
| 75 |
```
|
| 76 |
|
| 77 |
**How to download**
|