-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path9_prepare_and_parse_ood_sets.py
59 lines (46 loc) · 1.44 KB
/
9_prepare_and_parse_ood_sets.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import random
import pandas as pd
from rich.progress import track
from tos.tos_dataset import ToSDataset
random.seed(42)
# Download these directly from https://huggingface.co/datasets/yaful/MAGE/tree/main
dataset_paths = [
"data/mage/test_ood_set_gpt.csv",
"data/mage/test_ood_set_gpt_para.csv",
]
df_ood = pd.read_csv(dataset_paths[0], header=0)
df_ood_para = pd.read_csv(dataset_paths[1], header=0)
print(df_ood.head())
print(df_ood_para.head())
tos_dataset = ToSDataset(
dmrst_parser_dir="/home/ubuntu/Development/DMRST_Parser",
batch_size=1024,
gpu_id=0,
motif_dir="data/motifs",
)
def process_df(df):
dataset = []
for i, row in track(df.iterrows(), total=len(df), description="Processing..."):
text = row["text"]
label = row["label"]
source = row["src"]
document = tos_dataset.parse_document_discourse(
document=text,
source=source,
label=label,
filter_none=True,
add_graph=True,
add_motif_dists=True,
)
dataset.append(document)
return dataset
dataset_ood = process_df(df_ood)
tos_dataset.save_dataset_as_jsonl(
dataset_ood,
"data/mage/test_ood_set_gpt.discourse_parsed.graph_added.motif_dists.jsonl",
)
dataset_ood_para = process_df(df_ood_para)
tos_dataset.save_dataset_as_jsonl(
dataset_ood_para,
"data/mage/test_ood_set_gpt_para.discourse_parsed.graph_added.motif_dists.jsonl",
)