ludusc commited on
Commit
2a4bd0a
1 Parent(s): 1c46c0c

using csv now

Browse files
backend/disentangle_concepts.py CHANGED
@@ -4,8 +4,8 @@ from sklearn.model_selection import train_test_split
4
  import torch
5
  import PIL
6
 
7
- def get_separation_space(type_bin, annotations):
8
- abstracts = np.array([ann[type_bin] for ann in annotations['annotations']])
9
  abstract_idxs = list(np.argsort(abstracts))[:200]
10
  repr_idxs = list(np.argsort(abstracts))[-200:]
11
  X = np.array([annotations['z_vectors'][i] for i in abstract_idxs+repr_idxs])
 
4
  import torch
5
  import PIL
6
 
7
+ def get_separation_space(type_bin, annotations, df):
8
+ abstracts = np.array([float(ann) for ann in df[type_bin]])
9
  abstract_idxs = list(np.argsort(abstracts))[:200]
10
  repr_idxs = list(np.argsort(abstracts))[-200:]
11
  X = np.array([annotations['z_vectors'][i] for i in abstract_idxs+repr_idxs])
data/annotated_files/sim_seeds0000-10000.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4e82d206b3aa231c00176a24c8de33a6299e92e65b23013a40538146b8d24ff8
3
+ size 5645518
pages/1_Disentanglement.py CHANGED
@@ -37,7 +37,8 @@ with st.expander("See more instruction", expanded=False):
37
  annotations_file = './data/annotated_files/annotations_parallel_seeds0000-10000.pkl'
38
  with open(annotations_file, 'rb') as f:
39
  annotations = pickle.load(f)
40
-
 
41
  concepts = './data/concepts.txt'
42
  with open(concepts) as f:
43
  labels = [line.strip() for line in f.readlines()]
@@ -94,7 +95,7 @@ smoothgrad_col_1, smoothgrad_col_2, smoothgrad_col_3, smoothgrad_col_4, smoothgr
94
 
95
  # ---------------------------- DISPLAY COL 1 ROW 1 ------------------------------
96
  with output_col_1:
97
- separation_vector, number_important_features = get_separation_space(concept_id, annotations)
98
  # st.write(f'Class ID {input_id} - {input_label}: {pred_prob*100:.3f}% confidence')
99
  st.write('Separation vector', separation_vector)
100
  header_col_1.write(f'Concept {concept_id} - Number of relevant nodes: {number_important_features}')
 
37
  annotations_file = './data/annotated_files/annotations_parallel_seeds0000-10000.pkl'
38
  with open(annotations_file, 'rb') as f:
39
  annotations = pickle.load(f)
40
+
41
+ ann_df = pd.read_csv('./data/annotated_files/sim_seeds0000-10000.csv')
42
  concepts = './data/concepts.txt'
43
  with open(concepts) as f:
44
  labels = [line.strip() for line in f.readlines()]
 
95
 
96
  # ---------------------------- DISPLAY COL 1 ROW 1 ------------------------------
97
  with output_col_1:
98
+ separation_vector, number_important_features = get_separation_space(concept_id, annotations, ann_df)
99
  # st.write(f'Class ID {input_id} - {input_label}: {pred_prob*100:.3f}% confidence')
100
  st.write('Separation vector', separation_vector)
101
  header_col_1.write(f'Concept {concept_id} - Number of relevant nodes: {number_important_features}')