prakharg24 commited on
Commit
b8dedc5
·
verified ·
1 Parent(s): ac15dd5

Update my_pages/ica.py

Browse files
Files changed (1) hide show
  1. my_pages/ica.py +24 -50
my_pages/ica.py CHANGED
@@ -11,7 +11,7 @@ def render():
11
  add_instruction_text(
12
  """
13
  Explore the intention-convention-arbitrariness (ICA) framework.<br>
14
- Use different sliders to uncover examples in the ICA triangle.
15
  """
16
  )
17
 
@@ -22,42 +22,25 @@ def render():
22
  "Arbitrary": 0.34
23
  }
24
 
25
- col1, col2 = st.columns([0.6, 0.4])
26
- with col1:
27
- control_choice = st.radio(
28
- "Select dimension to adjust",
29
- ["Intentional", "Conventional", "Arbitrary"],
30
- horizontal=True,
31
- label_visibility="collapsed"
32
- )
33
-
34
- # Current values
35
  w = st.session_state.weights
36
- current_value = w[control_choice]
37
 
 
 
 
 
38
  with col2:
39
- new_value = st.slider(control_choice, 0.0, 1.0, current_value, 0.01, label_visibility="collapsed")
40
-
41
- # Adjust others proportionally
42
- diff = new_value - current_value
43
- others = [k for k in w.keys() if k != control_choice]
44
- total_other = w[others[0]] + w[others[1]]
45
-
46
- if total_other > 0:
47
- w[others[0]] -= diff * (w[others[0]] / total_other)
48
- w[others[1]] -= diff * (w[others[1]] / total_other)
49
-
50
- w[control_choice] = new_value
51
-
52
- # Clamp small floating point errors
53
- for k in w:
54
- w[k] = max(0.0, min(1.0, round(w[k], 4)))
55
-
56
- # Normalize back to sum=1
57
- total = sum(w.values())
58
- if total != 0:
59
- for k in w:
60
- w[k] = round(w[k] / total, 4)
61
 
62
  # Triangle vertices
63
  vertices = np.array([
@@ -76,7 +59,6 @@ def render():
76
  # Plot
77
  fig, ax = plt.subplots()
78
  ax.plot(*np.append(vertices, [vertices[0]], axis=0).T)
79
- # ax.scatter(vertices[:,0], vertices[:,1], c=["blue", "green", "red"], s=100)
80
  ax.text(*vertices[0], "Intentional", ha="center", va="bottom", color="green", weight="heavy")
81
  ax.text(*vertices[1], "Conventional", ha="right", va="top", color="green", weight="heavy")
82
  ax.text(*vertices[2], "Arbitrary", ha="left", va="top", color="green", weight="heavy")
@@ -89,24 +71,16 @@ def render():
89
  ax.patch.set_alpha(0)
90
 
91
  # --- Dummy points scattered inside triangle ---
92
- # (x, y, text)
93
  locations = [
94
  (0.9, 0.1, "Random Seeds", "Random Seeds are highly arbitrary, without any convention or intentionality.", "left", "bottom"),
95
- (0.35, 0.06, "Neural networks for Tabular Data", "Using neural networks of some arbitrary size (hidden layers) for a setting where \
96
- they are not needed is highly conventional, a bit arbitrary, and has very low intentionality.", "left", "bottom"),
97
- (0.4, 0.5, "Pre-trained LLM for a Complex Task", "Using a high performing LLM for a complex task is intentional, however, it also has \
98
- conventionality to it, as a specialized model could have worked, depending on context.\
99
- No arbitrariness.", "right", "bottom"),
100
- (0.5, 0.7, "Best Bias Mitigation for a Particular Setup", "Choosing the most appropriate bias mitigation technique,\
101
- specialized for the particular context, is highly intentional", "center", "bottom"),
102
- (0.7, 0.5, "Randomly chosen Regularization Technique", "Adding regularization to improve robustness, but choosing the regularization technique randomly,\
103
- creates a decision that is intentional and arbitrary, while avoiding conventionality.", "left", "bottom"),
104
- (0.1, 0.1, "ReLU Activation as Default", "Choosing ReLU activation without testing what other activations might also work,\
105
- is a highly conventional decision.", "right", "bottom"),
106
  ]
107
 
108
- torch_radius = 0.177 # how far the "torch" illuminates
109
-
110
  explanations = []
111
  # Illuminate nearby points
112
  for (x, y, label, labeltext, ha, va) in locations:
@@ -126,4 +100,4 @@ def render():
126
  text_to_show = ""
127
  for label, labeltext in explanations:
128
  text_to_show += "<b>" + label + ":</b> " + labeltext + "<br>"
129
- add_red_text(text_to_show)
 
11
  add_instruction_text(
12
  """
13
  Explore the intention-convention-arbitrariness (ICA) framework.<br>
14
+ Use the sliders to adjust the three dimensions simultaneously.
15
  """
16
  )
17
 
 
22
  "Arbitrary": 0.34
23
  }
24
 
 
 
 
 
 
 
 
 
 
 
25
  w = st.session_state.weights
 
26
 
27
+ # --- Three sliders ---
28
+ col1, col2, col3 = st.columns(3)
29
+ with col1:
30
+ i = st.slider("Intentional", 0.0, 1.0, w["Intentional"], 0.01)
31
  with col2:
32
+ c = st.slider("Conventional", 0.0, 1.0, w["Conventional"], 0.01)
33
+ with col3:
34
+ a = st.slider("Arbitrary", 0.0, 1.0, w["Arbitrary"], 0.01)
35
+
36
+ # Normalize to sum = 1
37
+ total = i + c + a
38
+ if total > 0:
39
+ w["Intentional"] = round(i / total, 4)
40
+ w["Conventional"] = round(c / total, 4)
41
+ w["Arbitrary"] = round(a / total, 4)
42
+ else:
43
+ w["Intentional"] = w["Conventional"] = w["Arbitrary"] = round(1/3, 4)
 
 
 
 
 
 
 
 
 
 
44
 
45
  # Triangle vertices
46
  vertices = np.array([
 
59
  # Plot
60
  fig, ax = plt.subplots()
61
  ax.plot(*np.append(vertices, [vertices[0]], axis=0).T)
 
62
  ax.text(*vertices[0], "Intentional", ha="center", va="bottom", color="green", weight="heavy")
63
  ax.text(*vertices[1], "Conventional", ha="right", va="top", color="green", weight="heavy")
64
  ax.text(*vertices[2], "Arbitrary", ha="left", va="top", color="green", weight="heavy")
 
71
  ax.patch.set_alpha(0)
72
 
73
  # --- Dummy points scattered inside triangle ---
 
74
  locations = [
75
  (0.9, 0.1, "Random Seeds", "Random Seeds are highly arbitrary, without any convention or intentionality.", "left", "bottom"),
76
+ (0.35, 0.06, "Neural networks for Tabular Data", "Using neural networks of some arbitrary size (hidden layers) for a setting where they are not needed is highly conventional, a bit arbitrary, and has very low intentionality.", "left", "bottom"),
77
+ (0.4, 0.5, "Pre-trained LLM for a Complex Task", "Using a high performing LLM for a complex task is intentional, however, it also has conventionality to it, as a specialized model could have worked, depending on context. No arbitrariness.", "right", "bottom"),
78
+ (0.5, 0.7, "Best Bias Mitigation for a Particular Setup", "Choosing the most appropriate bias mitigation technique, specialized for the particular context, is highly intentional", "center", "bottom"),
79
+ (0.7, 0.5, "Randomly chosen Regularization Technique", "Adding regularization to improve robustness, but choosing the regularization technique randomly, creates a decision that is intentional and arbitrary, while avoiding conventionality.", "left", "bottom"),
80
+ (0.1, 0.1, "ReLU Activation as Default", "Choosing ReLU activation without testing what other activations might also work, is a highly conventional decision.", "right", "bottom"),
 
 
 
 
 
 
81
  ]
82
 
83
+ torch_radius = 0.177
 
84
  explanations = []
85
  # Illuminate nearby points
86
  for (x, y, label, labeltext, ha, va) in locations:
 
100
  text_to_show = ""
101
  for label, labeltext in explanations:
102
  text_to_show += "<b>" + label + ":</b> " + labeltext + "<br>"
103
+ add_red_text(text_to_show)