-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathrun_clustering.py
More file actions
60 lines (52 loc) · 1.93 KB
/
run_clustering.py
File metadata and controls
60 lines (52 loc) · 1.93 KB
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
60
# coding: utf-8
# imports
import logging
import pickle
import matplotlib.pyplot as plt
import seaborn as sns;
import numpy as np
from sklearn.cluster import KMeans
import os
import debugpy
import tqdm
import argparse
os.environ["CUDA_LAUNCH_BLOCKING"] = "1"
sns.set()
import torch
import pickle
from datasets import Dataset, load_from_disk
from transformers import BertForMaskedLM
from CGMFormer import EmbExtractor
device = 'cuda' if torch.cuda.is_available() else 'cpu'
# debugpy.listen(("192.168.72.58", 5681))
# print("Waiting for debugger attach...")
# debugpy.wait_for_client()
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('--checkpoint_path', type=str, help='Path to the checkpoint')
parser.add_argument('--data_path', type=str, help='Path to the data')
parser.add_argument('--save_path', type=str, help='Path to save embeddings')
parser.add_argument('--filter_target', type=str, help='Filter target')
return parser.parse_args()
def main():
args = parse_args()
filter_target = "type"
embex = EmbExtractor(model_type="Pretrained",
max_length=289,
num_classes=0,
emb_mode="sample",
sample_emb_style="mean_pool",
filter_data=None,
filter_target=args.filter_target,
max_nsamples=2000,
emb_layer=0,
emb_label=['index', 'p_id', 'id', 'filled', 'types', 'hba1c'],
labels_to_plot=['index'],
forward_batch_size=48,
nproc=16)
embs = embex.extract_embs(args.checkpoint_path,
args.data_path,
args.save_path,
f"mean_preTrainCheckpoint_Colas_1028_vec_{args.filter_target}")
if __name__ == "__main__":
main()