Alexander Seifert commited on
Commit
f259527
1 Parent(s): b8fe4d8

make get_widget_defaults private

Browse files
src/app.py CHANGED
@@ -1,7 +1,6 @@
1
  """The App module is the main entry point for the application.
2
 
3
  Run `streamlit run app.py` to start the app.
4
-
5
  """
6
 
7
  import pandas as pd
@@ -53,7 +52,7 @@ def _show_menu(pages: list[Page]) -> int:
53
  def _initialize_session_state(pages: list[Page]):
54
  if "active_page" not in st.session_state:
55
  for page in pages:
56
- st.session_state.update(**page.get_widget_defaults())
57
  st.session_state.update(st.session_state)
58
 
59
 
 
1
  """The App module is the main entry point for the application.
2
 
3
  Run `streamlit run app.py` to start the app.
 
4
  """
5
 
6
  import pandas as pd
 
52
  def _initialize_session_state(pages: list[Page]):
53
  if "active_page" not in st.session_state:
54
  for page in pages:
55
+ st.session_state.update(**page._get_widget_defaults())
56
  st.session_state.update(st.session_state)
57
 
58
 
src/subpages/attention.py CHANGED
@@ -91,7 +91,7 @@ class AttentionPage(Page):
91
  name = "Activations"
92
  icon = "activity"
93
 
94
- def get_widget_defaults(self):
95
  return {
96
  "act_n_components": 8,
97
  "act_default_text": """Now I ask you: what can be expected of man since he is a being endowed with strange qualities? Shower upon him every earthly blessing, drown him in a sea of happiness, so that nothing but bubbles of bliss can be seen on the surface; give him economic prosperity, such that he should have nothing else to do but sleep, eat cakes and busy himself with the continuation of his species, and even then out of sheer ingratitude, sheer spite, man would play you some nasty trick. He would even risk his cakes and would deliberately desire the most fatal rubbish, the most uneconomical absurdity, simply to introduce into all this positive good sense his fatal fantastic element. It is just his fantastic dreams, his vulgar folly that he will desire to retain, simply in order to prove to himself--as though that were so necessary-- that men still are men and not the keys of a piano, which the laws of nature threaten to control so completely that soon one will be able to desire nothing but by the calendar. And that is not all: even if man really were nothing but a piano-key, even if this were proved to him by natural science and mathematics, even then he would not become reasonable, but would purposely do something perverse out of simple ingratitude, simply to gain his point. And if he does not find means he will contrive destruction and chaos, will contrive sufferings of all sorts, only to gain his point! He will launch a curse upon the world, and as only man can curse (it is his privilege, the primary distinction between him and other animals), may be by his curse alone he will attain his object--that is, convince himself that he is a man and not a piano-key!""",
 
91
  name = "Activations"
92
  icon = "activity"
93
 
94
+ def _get_widget_defaults(self):
95
  return {
96
  "act_n_components": 8,
97
  "act_default_text": """Now I ask you: what can be expected of man since he is a being endowed with strange qualities? Shower upon him every earthly blessing, drown him in a sea of happiness, so that nothing but bubbles of bliss can be seen on the surface; give him economic prosperity, such that he should have nothing else to do but sleep, eat cakes and busy himself with the continuation of his species, and even then out of sheer ingratitude, sheer spite, man would play you some nasty trick. He would even risk his cakes and would deliberately desire the most fatal rubbish, the most uneconomical absurdity, simply to introduce into all this positive good sense his fatal fantastic element. It is just his fantastic dreams, his vulgar folly that he will desire to retain, simply in order to prove to himself--as though that were so necessary-- that men still are men and not the keys of a piano, which the laws of nature threaten to control so completely that soon one will be able to desire nothing but by the calendar. And that is not all: even if man really were nothing but a piano-key, even if this were proved to him by natural science and mathematics, even then he would not become reasonable, but would purposely do something perverse out of simple ingratitude, simply to gain his point. And if he does not find means he will contrive destruction and chaos, will contrive sufferings of all sorts, only to gain his point! He will launch a curse upon the world, and as only man can curse (it is his privilege, the primary distinction between him and other animals), may be by his curse alone he will attain his object--that is, convince himself that he is a man and not a piano-key!""",
src/subpages/find_duplicates.py CHANGED
@@ -15,7 +15,7 @@ class FindDuplicatesPage(Page):
15
  name = "Find Duplicates"
16
  icon = "fingerprint"
17
 
18
- def get_widget_defaults(self):
19
  return {
20
  "cutoff": 0.95,
21
  }
 
15
  name = "Find Duplicates"
16
  icon = "fingerprint"
17
 
18
+ def _get_widget_defaults(self):
19
  return {
20
  "cutoff": 0.95,
21
  }
src/subpages/hidden_states.py CHANGED
@@ -71,7 +71,7 @@ class HiddenStatesPage(Page):
71
  name = "Hidden States"
72
  icon = "grid-3x3"
73
 
74
- def get_widget_defaults(self):
75
  return {
76
  "n_tokens": 1_000,
77
  "svd_n_iter": 5,
 
71
  name = "Hidden States"
72
  icon = "grid-3x3"
73
 
74
+ def _get_widget_defaults(self):
75
  return {
76
  "n_tokens": 1_000,
77
  "svd_n_iter": 5,
src/subpages/home.py CHANGED
@@ -37,7 +37,7 @@ class HomePage(Page):
37
  name = "Home / Setup"
38
  icon = "house"
39
 
40
- def get_widget_defaults(self):
41
  return {
42
  "encoder_model_name": _SENTENCE_ENCODER_MODEL,
43
  "model_name": _MODEL_NAME,
 
37
  name = "Home / Setup"
38
  icon = "house"
39
 
40
+ def _get_widget_defaults(self):
41
  return {
42
  "encoder_model_name": _SENTENCE_ENCODER_MODEL,
43
  "model_name": _MODEL_NAME,
src/subpages/lossy_samples.py CHANGED
@@ -15,7 +15,7 @@ class LossySamplesPage(Page):
15
  name = "Samples by Loss"
16
  icon = "sort-numeric-down-alt"
17
 
18
- def get_widget_defaults(self):
19
  return {
20
  "skip_correct": True,
21
  "samples_by_loss_show_df": True,
 
15
  name = "Samples by Loss"
16
  icon = "sort-numeric-down-alt"
17
 
18
+ def _get_widget_defaults(self):
19
  return {
20
  "skip_correct": True,
21
  "samples_by_loss_show_df": True,
src/subpages/metrics.py CHANGED
@@ -52,7 +52,7 @@ class MetricsPage(Page):
52
  name = "Metrics"
53
  icon = "graph-up-arrow"
54
 
55
- def get_widget_defaults(self):
56
  return {
57
  "normalize": True,
58
  "zero_diagonal": False,
 
52
  name = "Metrics"
53
  icon = "graph-up-arrow"
54
 
55
+ def _get_widget_defaults(self):
56
  return {
57
  "normalize": True,
58
  "zero_diagonal": False,
src/subpages/page.py CHANGED
@@ -10,7 +10,7 @@ from transformers import AutoTokenizer # type: ignore
10
 
11
  @dataclass
12
  class Context:
13
- """This object facilitates passing around the applications state between different pages."""
14
 
15
  model: AutoModelForSequenceClassification
16
  tokenizer: AutoTokenizer
@@ -34,8 +34,8 @@ class Page:
34
  name: str
35
  icon: str
36
 
37
- def get_widget_defaults(self):
38
- """This function holds the default settings for all the page's widgets.
39
 
40
  Returns:
41
  dict: A dictionary of widget defaults, where the keys are the widget names and the values are the default.
 
10
 
11
  @dataclass
12
  class Context:
13
+ """This object facilitates passing around the application's state between different pages."""
14
 
15
  model: AutoModelForSequenceClassification
16
  tokenizer: AutoTokenizer
 
34
  name: str
35
  icon: str
36
 
37
+ def _get_widget_defaults(self):
38
+ """This function holds the default settings for all widgets contained on this page.
39
 
40
  Returns:
41
  dict: A dictionary of widget defaults, where the keys are the widget names and the values are the default.
src/subpages/probing.py CHANGED
@@ -29,7 +29,7 @@ class ProbingPage(Page):
29
  name = "Probing"
30
  icon = "fonts"
31
 
32
- def get_widget_defaults(self):
33
  return {"probing_textarea": _DEFAULT_SENTENCES}
34
 
35
  def render(self, context: Context):
 
29
  name = "Probing"
30
  icon = "fonts"
31
 
32
+ def _get_widget_defaults(self):
33
  return {"probing_textarea": _DEFAULT_SENTENCES}
34
 
35
  def render(self, context: Context):
src/subpages/random_samples.py CHANGED
@@ -10,7 +10,7 @@ class RandomSamplesPage(Page):
10
  name = "Random Samples"
11
  icon = "shuffle"
12
 
13
- def get_widget_defaults(self):
14
  return {
15
  "random_sample_size_min": 128,
16
  }
 
10
  name = "Random Samples"
11
  icon = "shuffle"
12
 
13
+ def _get_widget_defaults(self):
14
  return {
15
  "random_sample_size_min": 128,
16
  }