steffenc commited on
Commit
55af4cc
·
1 Parent(s): f2bdb54

Adapt syntax for validator v1.1.0 schema

Browse files
dashboard.py CHANGED
@@ -9,8 +9,7 @@ from opendashboards.assets import io, inspect, metric, plot
9
  # Hotkey churn
10
 
11
  DEFAULT_PROJECT = "openvalidators"
12
- DEFAULT_FILTERS = {"tags": {"$in": [f'1.0.{i}' for i in range(10)]}}
13
- DEFAULT_SELECTED_RUNS = ['kt9bzxii']
14
  DEFAULT_SELECTED_HOTKEYS = None
15
  DEFAULT_SRC = 'followup'
16
  DEFAULT_COMPLETION_NTOP = 10
@@ -66,13 +65,13 @@ with tab1:
66
  if n_runs:
67
  df = io.load_data(df_runs_subset, load=True, save=True)
68
  df = inspect.clean_data(df)
 
69
  df_long = inspect.explode_data(df)
70
- df_weights = inspect.weights(df)
71
  else:
72
  st.info(f'You must select at least one run to load data')
73
  st.stop()
74
 
75
- metric.runs(df_long, n_runs)
76
 
77
  st.markdown('#')
78
  st.subheader(":violet[Event] Data")
@@ -83,7 +82,7 @@ with tab1:
83
  st.dataframe(df_long.head(num_rows) if use_long_checkbox else df.head(num_rows),
84
  use_container_width=True)
85
 
86
-
87
 
88
  ### UID Health ###
89
  # TODO: Live time - time elapsed since moving_averaged_score for selected UID was 0 (lower bound so use >Time)
@@ -94,20 +93,21 @@ with tab2:
94
  st.subheader("UID :violet[Health]")
95
  st.info(f"Showing UID health metrics for **{n_runs} selected runs**")
96
 
97
- uid_src = st.radio('Select one:', ['followup', 'answer'], horizontal=True, key='uid_src')
98
-
99
- metric.uids(df_long, uid_src)
100
- uids = st.multiselect('UID:', sorted(df_long[f'{uid_src}_uids'].unique()), key='uid')
 
101
  with st.expander(f'Show UID health data for **{n_runs} selected runs** and **{len(uids)} selected UIDs**'):
102
  st.markdown('#')
103
  st.subheader(f"UID {uid_src.title()} :violet[Health]")
104
  agg_uid_checkbox = st.checkbox('Aggregate UIDs', value=True)
105
  if agg_uid_checkbox:
106
- metric.uids(df_long, uid_src, uids)
107
  else:
108
  for uid in uids:
109
  st.caption(f'UID: {uid}')
110
- metric.uids(df_long, uid_src, [uid])
111
 
112
  st.subheader(f'Cumulative completion frequency')
113
 
@@ -117,18 +117,8 @@ with tab2:
117
  freq_cumulative = freq_col2.checkbox('Cumulative', value=False, key='freq_cumulative')
118
  freq_normalize = freq_col2.checkbox('Normalize', value=True, key='freq_normalize')
119
 
120
- plot.uid_completion_counts(df_long, uids=uids, src=uid_src, ntop=freq_ntop, rm_empty=freq_rm_empty, cumulative=freq_cumulative, normalize=freq_normalize)
121
-
122
-
123
- with st.expander(f'Show UID weights data for **{n_runs} selected runs** and **{len(uids)} selected UIDs**'):
124
 
125
- st.markdown('#')
126
- st.subheader(f"UID {uid_src.title()} :violet[Weights]")
127
-
128
- plot.weights(
129
- df_weights,
130
- uids=uids,
131
- )
132
 
133
  with st.expander(f'Show UID **{uid_src}** leaderboard data for **{n_runs} selected runs**'):
134
 
@@ -139,10 +129,10 @@ with tab2:
139
  uid_agg = uid_col2.selectbox('Aggregation:', ('mean','min','max','size','nunique'), key='uid_agg')
140
 
141
  plot.leaderboard(
142
- df,
143
  ntop=uid_ntop,
144
- group_on=f'{uid_src}_uids',
145
- agg_col=f'{uid_src}_rewards',
146
  agg=uid_agg
147
  )
148
 
@@ -163,24 +153,22 @@ with tab3:
163
  completion_info = st.empty()
164
 
165
  msg_col1, msg_col2 = st.columns(2)
166
- completion_src = msg_col1.radio('Select one:', ['followup', 'answer'], horizontal=True, key='completion_src')
 
 
 
167
  completion_info.info(f"Showing **{completion_src}** completions for **{n_runs} selected runs**")
168
 
169
  completion_ntop = msg_col2.slider('Top k:', min_value=1, max_value=50, value=DEFAULT_COMPLETION_NTOP, key='completion_ntop')
170
 
171
- completion_col = f'{completion_src}_completions'
172
- reward_col = f'{completion_src}_rewards'
173
- uid_col = f'{completion_src}_uids'
174
- time_col = f'{completion_src}_times'
175
-
176
- completions = inspect.completions(df_long, completion_col)
177
 
178
  # Get completions with highest average rewards
179
  plot.leaderboard(
180
  df,
181
  ntop=completion_ntop,
182
- group_on=completion_col,
183
- agg_col=reward_col,
184
  agg='mean',
185
  alias=True
186
  )
@@ -195,9 +183,9 @@ with tab3:
195
 
196
  plot.completion_rewards(
197
  df,
198
- completion_col=completion_col,
199
- reward_col=reward_col,
200
- uid_col=uid_col,
201
  ntop=completion_ntop,
202
  completions=completion_select,
203
  )
@@ -209,14 +197,14 @@ with tab3:
209
  st.markdown('#')
210
  st.subheader('Completion :violet[Length]')
211
 
212
- words_checkbox = st.checkbox('Use words', value=True, key='words_checkbox')
213
 
214
  plot.completion_length_time(
215
  df,
216
- completion_col=completion_col,
217
- uid_col=uid_col,
218
- time_col=time_col,
219
- words=words_checkbox,
220
  )
221
 
222
  ### Prompt-based scoring ###
 
9
  # Hotkey churn
10
 
11
  DEFAULT_PROJECT = "openvalidators"
12
+ DEFAULT_FILTERS = {"tags": {"$in": [f'1.1.{i}' for i in range(10)]}}
 
13
  DEFAULT_SELECTED_HOTKEYS = None
14
  DEFAULT_SRC = 'followup'
15
  DEFAULT_COMPLETION_NTOP = 10
 
65
  if n_runs:
66
  df = io.load_data(df_runs_subset, load=True, save=True)
67
  df = inspect.clean_data(df)
68
+ print(f'\nNans in columns: {df.isna().sum()}')
69
  df_long = inspect.explode_data(df)
 
70
  else:
71
  st.info(f'You must select at least one run to load data')
72
  st.stop()
73
 
74
+ metric.runs(df_long)
75
 
76
  st.markdown('#')
77
  st.subheader(":violet[Event] Data")
 
82
  st.dataframe(df_long.head(num_rows) if use_long_checkbox else df.head(num_rows),
83
  use_container_width=True)
84
 
85
+ step_types = ['all']+['augment','followup','answer']#list(df.name.unique())
86
 
87
  ### UID Health ###
88
  # TODO: Live time - time elapsed since moving_averaged_score for selected UID was 0 (lower bound so use >Time)
 
93
  st.subheader("UID :violet[Health]")
94
  st.info(f"Showing UID health metrics for **{n_runs} selected runs**")
95
 
96
+ uid_src = st.radio('Select event type:', step_types, horizontal=True, key='uid_src')
97
+ df_uid = df_long[df_long.name.str.contains(uid_src)] if uid_src != 'all' else df_long
98
+
99
+ metric.uids(df_uid, uid_src)
100
+ uids = st.multiselect('UID:', sorted(df_uid['uids'].unique()), key='uid')
101
  with st.expander(f'Show UID health data for **{n_runs} selected runs** and **{len(uids)} selected UIDs**'):
102
  st.markdown('#')
103
  st.subheader(f"UID {uid_src.title()} :violet[Health]")
104
  agg_uid_checkbox = st.checkbox('Aggregate UIDs', value=True)
105
  if agg_uid_checkbox:
106
+ metric.uids(df_uid, uid_src, uids)
107
  else:
108
  for uid in uids:
109
  st.caption(f'UID: {uid}')
110
+ metric.uids(df_uid, uid_src, [uid])
111
 
112
  st.subheader(f'Cumulative completion frequency')
113
 
 
117
  freq_cumulative = freq_col2.checkbox('Cumulative', value=False, key='freq_cumulative')
118
  freq_normalize = freq_col2.checkbox('Normalize', value=True, key='freq_normalize')
119
 
120
+ plot.uid_completion_counts(df_uid, uids=uids, src=uid_src, ntop=freq_ntop, rm_empty=freq_rm_empty, cumulative=freq_cumulative, normalize=freq_normalize)
 
 
 
121
 
 
 
 
 
 
 
 
122
 
123
  with st.expander(f'Show UID **{uid_src}** leaderboard data for **{n_runs} selected runs**'):
124
 
 
129
  uid_agg = uid_col2.selectbox('Aggregation:', ('mean','min','max','size','nunique'), key='uid_agg')
130
 
131
  plot.leaderboard(
132
+ df_uid,
133
  ntop=uid_ntop,
134
+ group_on='uids',
135
+ agg_col='rewards',
136
  agg=uid_agg
137
  )
138
 
 
153
  completion_info = st.empty()
154
 
155
  msg_col1, msg_col2 = st.columns(2)
156
+ # completion_src = msg_col1.radio('Select one:', ['followup', 'answer'], horizontal=True, key='completion_src')
157
+ completion_src = st.radio('Select event type:', step_types, horizontal=True, key='completion_src')
158
+ df_comp = df_long[df_long.name==completion_src] if completion_src != 'all' else df_long
159
+
160
  completion_info.info(f"Showing **{completion_src}** completions for **{n_runs} selected runs**")
161
 
162
  completion_ntop = msg_col2.slider('Top k:', min_value=1, max_value=50, value=DEFAULT_COMPLETION_NTOP, key='completion_ntop')
163
 
164
+ completions = inspect.completions(df_long, 'completions')
 
 
 
 
 
165
 
166
  # Get completions with highest average rewards
167
  plot.leaderboard(
168
  df,
169
  ntop=completion_ntop,
170
+ group_on='completions',
171
+ agg_col='rewards',
172
  agg='mean',
173
  alias=True
174
  )
 
183
 
184
  plot.completion_rewards(
185
  df,
186
+ completion_col='completions',
187
+ reward_col='rewards',
188
+ uid_col='uids',
189
  ntop=completion_ntop,
190
  completions=completion_select,
191
  )
 
197
  st.markdown('#')
198
  st.subheader('Completion :violet[Length]')
199
 
200
+ completion_length_radio = st.radio('Use: ', ['characters','words','sentences'], key='completion_length_radio')
201
 
202
  plot.completion_length_time(
203
  df,
204
+ completion_col='completions',
205
+ uid_col='uids',
206
+ time_col='completion_times',
207
+ length_opt=completion_length_radio,
208
  )
209
 
210
  ### Prompt-based scoring ###
opendashboards/assets/inspect.py CHANGED
@@ -4,7 +4,7 @@ import pandas as pd
4
  import opendashboards.utils.utils as utils
5
 
6
  def clean_data(df):
7
- return df.dropna(subset=df.filter(regex='completions|rewards').columns, how='all')
8
 
9
  @st.cache_data
10
  def explode_data(df):
@@ -22,16 +22,6 @@ def explode_data(df):
22
  def completions(df_long, col):
23
  return df_long[col].value_counts()
24
 
25
- @st.cache_data
26
- def weights(df, index='_timestamp'):
27
- # Create a column for each UID and show most recent rows
28
- scores = df['moving_averaged_scores'].apply(pd.Series).fillna(method='ffill')
29
- if index in df.columns:
30
- scores.index = df[index]
31
-
32
- # rename columns
33
- scores.rename({i: f'UID-{i}' for i in range(scores.shape[1])}, axis=1, inplace=True)
34
- return scores
35
 
36
  def run_event_data(df_runs, df, selected_runs):
37
 
 
4
  import opendashboards.utils.utils as utils
5
 
6
  def clean_data(df):
7
+ return df.dropna(subset=df.filter(regex='completions|rewards').columns, how='any')
8
 
9
  @st.cache_data
10
  def explode_data(df):
 
22
  def completions(df_long, col):
23
  return df_long[col].value_counts()
24
 
 
 
 
 
 
 
 
 
 
 
25
 
26
  def run_event_data(df_runs, df, selected_runs):
27
 
opendashboards/assets/io.py CHANGED
@@ -25,7 +25,7 @@ def load_runs(project, filters, min_steps=10):
25
  for i, run in enumerate(all_runs):
26
 
27
  summary = run.summary
28
- step = summary.get('_step',0)
29
  if step < min_steps:
30
  msg.warning(f'Skipped run `{run.name}` because it contains {step} events (<{min_steps})')
31
  continue
@@ -46,11 +46,11 @@ def load_runs(project, filters, min_steps=10):
46
  'num_steps': step,
47
  'num_completions': step*sum(len(v) for k, v in run.summary.items() if k.endswith('completions') and isinstance(v, list)),
48
  'entity': run.entity,
49
- 'id': run.id,
50
- 'name': run.name,
51
  'project': run.project,
52
  'url': run.url,
53
- 'path': os.path.join(run.entity, run.project, run.id),
54
  'start_time': pd.to_datetime(end_time-duration, unit="s"),
55
  'end_time': pd.to_datetime(end_time, unit="s"),
56
  'duration': pd.to_timedelta(duration, unit="s").round('s'),
@@ -78,7 +78,7 @@ def load_data(selected_runs, load=True, save=False):
78
  run = selected_runs.loc[idx]
79
  prog_msg = f'Loading data {i/len(selected_runs)*100:.0f}% ({successful}/{len(selected_runs)} runs, {n_events} events)'
80
 
81
- file_path = os.path.join('data',f'history-{run.id}.csv')
82
 
83
  if load and os.path.exists(file_path):
84
  progress.progress(i/len(selected_runs),f'{prog_msg}... **reading** `{file_path}`')
@@ -89,18 +89,19 @@ def load_data(selected_runs, load=True, save=False):
89
  st.exception(e)
90
  continue
91
  else:
92
- progress.progress(i/len(selected_runs),f'{prog_msg}... **downloading** `{run.path}`')
93
  try:
94
- # Download the history from wandb
95
- df = utils.download_data(run.path)
96
- # Add metadata to the dataframe
97
- df.assign(**run.to_dict())
98
 
 
 
 
99
  if save and run.state != 'running':
100
  df.to_csv(file_path, index=False)
101
  # st.info(f'Saved history to {file_path}')
102
  except Exception as e:
103
- info.warning(f'Failed to download history for `{run.path}`')
104
  st.exception(e)
105
  continue
106
 
 
25
  for i, run in enumerate(all_runs):
26
 
27
  summary = run.summary
28
+ step = summary.get('_step',-1) + 1
29
  if step < min_steps:
30
  msg.warning(f'Skipped run `{run.name}` because it contains {step} events (<{min_steps})')
31
  continue
 
46
  'num_steps': step,
47
  'num_completions': step*sum(len(v) for k, v in run.summary.items() if k.endswith('completions') and isinstance(v, list)),
48
  'entity': run.entity,
49
+ 'run_id': run.id,
50
+ 'run_name': run.name,
51
  'project': run.project,
52
  'url': run.url,
53
+ 'run_path': os.path.join(run.entity, run.project, run.id),
54
  'start_time': pd.to_datetime(end_time-duration, unit="s"),
55
  'end_time': pd.to_datetime(end_time, unit="s"),
56
  'duration': pd.to_timedelta(duration, unit="s").round('s'),
 
78
  run = selected_runs.loc[idx]
79
  prog_msg = f'Loading data {i/len(selected_runs)*100:.0f}% ({successful}/{len(selected_runs)} runs, {n_events} events)'
80
 
81
+ file_path = os.path.join('data',f'history-{run.run_id}.csv')
82
 
83
  if load and os.path.exists(file_path):
84
  progress.progress(i/len(selected_runs),f'{prog_msg}... **reading** `{file_path}`')
 
89
  st.exception(e)
90
  continue
91
  else:
92
+ progress.progress(i/len(selected_runs),f'{prog_msg}... **downloading** `{run.run_path}`')
93
  try:
94
+ # Download the history from wandb and add metadata
95
+ df = utils.download_data(run.run_path).assign(**run.to_dict())
 
 
96
 
97
+ print(f'Downloaded {df.shape[0]} events from `{run.run_path}`. Columns: {df.columns}')
98
+ df.info()
99
+
100
  if save and run.state != 'running':
101
  df.to_csv(file_path, index=False)
102
  # st.info(f'Saved history to {file_path}')
103
  except Exception as e:
104
+ info.warning(f'Failed to download history for `{run.run_path}`')
105
  st.exception(e)
106
  continue
107
 
opendashboards/assets/metric.py CHANGED
@@ -33,15 +33,26 @@ def wandb(df_runs):
33
 
34
 
35
  @st.cache_data
36
- def runs(df_long, n_runs):
37
-
38
- col1, col2, col3 = st.columns(3)
39
- col1.metric(label="Runs", value=n_runs)
40
- col1.metric(label="Events", value=df_long.shape[0])
41
- col2.metric(label="Followup UIDs", value=df_long.followup_uids.nunique())
42
- col2.metric(label="Answer UIDs", value=df_long.answer_uids.nunique())
43
- col3.metric(label="Unique Followups", value=df_long.followup_completions.nunique())
44
- col3.metric(label="Unique Answers", value=df_long.answer_completions.nunique())
 
 
 
 
 
 
 
 
 
 
 
45
  st.markdown('----')
46
 
47
 
@@ -49,30 +60,28 @@ def runs(df_long, n_runs):
49
  @st.cache_data
50
  def uids(df_long, src, uids=None):
51
 
52
- uid_col = f'{src}_uids'
53
- completion_col = f'{src}_completions'
54
  nsfw_col = f'{src}_nsfw_scores'
55
- reward_col = f'{src}_rewards'
56
 
57
  if uids:
58
- df_long = df_long.loc[df_long[uid_col].isin(uids)]
59
 
60
  col1, col2, col3, col4 = st.columns(4)
61
  col1.metric(
62
  label="Success %",
63
- value=f'{df_long.loc[df_long[completion_col].str.len() > 0].shape[0]/df_long.shape[0] * 100:.1f}',
64
  help='Number of successful completions divided by total number of events'
65
  )
66
  col2.metric(
67
  label="Diversity %",
68
- value=f'{df_long[completion_col].nunique()/df_long.shape[0] * 100:.1f}',
69
  help='Number of unique completions divided by total number of events'
70
  )
71
  # uniqueness can be expressed as the average number of unique completions per uid divided by all unique completions
 
72
 
73
  col3.metric(
74
  label="Uniqueness %",
75
- value=f'{df_long.groupby(uid_col)[completion_col].nunique().mean()/df_long[completion_col].nunique() * 100:.1f}',
76
  help='Average number of unique completions per uid divided by all unique completions'
77
  )
78
  col4.metric(
 
33
 
34
 
35
  @st.cache_data
36
+ def runs(df_long):
37
+
38
+ col1, col2, col3, col4 = st.columns(4)
39
+ print(df_long.columns)
40
+
41
+ # Convert to appropriate units e.g. 1.2k instead of 1200.c
42
+ col1.metric('Runs', fmt(df_long.run_id.nunique()))
43
+ col2.metric('Hotkeys', fmt(df_long.hotkey.nunique()))
44
+ col3.metric('Events', fmt(df_long.groupby(['run_id','_step']).ngroups))
45
+ col4.metric('Completions', fmt(df_long.shape[0]))
46
+
47
+ name_type = df_long.name.apply(lambda x: x if not x[-1].isdigit() else x[:-1])
48
+ aggs = df_long.groupby(name_type).agg({'uids': 'nunique', 'completions': 'nunique'})
49
+ print(aggs)
50
+ for i,c in enumerate(st.columns(len(aggs))):
51
+ name = aggs.index[i].title()
52
+ uid_unique, comp_unique = aggs.iloc[i]
53
+ c.metric(label=f'{name} UIDs', value=uid_unique)
54
+ c.metric(label=f'{name} Completions', value=comp_unique)
55
+
56
  st.markdown('----')
57
 
58
 
 
60
  @st.cache_data
61
  def uids(df_long, src, uids=None):
62
 
 
 
63
  nsfw_col = f'{src}_nsfw_scores'
 
64
 
65
  if uids:
66
+ df_long = df_long.loc[df_long['uids'].isin(uids)]
67
 
68
  col1, col2, col3, col4 = st.columns(4)
69
  col1.metric(
70
  label="Success %",
71
+ value=f'{df_long.loc[df_long["completions"].str.len() > 0].shape[0]/df_long.shape[0] * 100:.1f}',
72
  help='Number of successful completions divided by total number of events'
73
  )
74
  col2.metric(
75
  label="Diversity %",
76
+ value=f'{df_long["completions"].nunique()/df_long.shape[0] * 100:.1f}',
77
  help='Number of unique completions divided by total number of events'
78
  )
79
  # uniqueness can be expressed as the average number of unique completions per uid divided by all unique completions
80
+ # uniqueness is the shared completions between selected uids
81
 
82
  col3.metric(
83
  label="Uniqueness %",
84
+ value=f'{df_long.groupby("uids")["completions"].nunique().mean()/df_long["completions"].nunique() * 100:.1f}',
85
  help='Average number of unique completions per uid divided by all unique completions'
86
  )
87
  col4.metric(
opendashboards/assets/plot.py CHANGED
@@ -55,14 +55,14 @@ def weights(df, uids, ntop=10):
55
  use_container_width=True
56
  )
57
 
58
- def completion_length_time(df, completion_col, uid_col, time_col, words=False):
59
  return st.plotly_chart(
60
  plotting.plot_completion_length_time(
61
  df,
62
  uid_col=uid_col,
63
  completion_col=completion_col,
64
  time_col=time_col,
65
- words=words
66
  ),
67
  use_container_width=True
68
  )
 
55
  use_container_width=True
56
  )
57
 
58
+ def completion_length_time(df, completion_col, uid_col, time_col, length_opt='characters'):
59
  return st.plotly_chart(
60
  plotting.plot_completion_length_time(
61
  df,
62
  uid_col=uid_col,
63
  completion_col=completion_col,
64
  time_col=time_col,
65
+ length_opt=length_opt
66
  ),
67
  use_container_width=True
68
  )
opendashboards/utils/plotting.py CHANGED
@@ -62,16 +62,16 @@ def plot_weights(scores: pd.DataFrame, ntop: int = 20, uids: List[Union[str, int
62
  ).update_traces(opacity=0.7)
63
 
64
 
65
- def plot_uid_diversty(df: pd.DataFrame, remove_unsuccessful: bool = False) -> go.Figure:
66
  """Plot uid diversity as measured by ratio of unique to total completions.
67
 
68
  Args:
69
  df (pd.DataFrame): Dataframe of event log.
70
  """
71
- uid_cols = ["followup_uids", "answer_uids"]
72
- completion_cols = ["followup_completions", "answer_completions"]
73
- reward_cols = ["followup_rewards", "answer_rewards"]
74
- list_cols = uid_cols + completion_cols + reward_cols
75
 
76
  df = df[list_cols].explode(column=list_cols)
77
  if remove_unsuccessful:
@@ -98,7 +98,7 @@ def plot_uid_diversty(df: pd.DataFrame, remove_unsuccessful: bool = False) -> go
98
  x="diversity_followup",
99
  y="diversity_answer",
100
  opacity=0.35,
101
- # size="followup_completions_size",
102
  color="reward_mean",
103
  hover_data=["UID"] + merged.columns.tolist(),
104
  marginal_x="histogram",
@@ -112,7 +112,7 @@ def plot_uid_diversty(df: pd.DataFrame, remove_unsuccessful: bool = False) -> go
112
 
113
  def plot_completion_rates(
114
  df: pd.DataFrame,
115
- msg_col: str = "all_completions",
116
  time_interval: str = "H",
117
  time_col: str = "_timestamp",
118
  ntop: int = 20,
@@ -123,7 +123,7 @@ def plot_completion_rates(
123
 
124
  Args:
125
  df (pd.DataFrame): Dataframe of event log.
126
- msg_col (str, optional): List-like column containing completions. Defaults to 'all_completions'.
127
  time_interval (str, optional): Pandas time interval. Defaults to 'H'. See https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#timeseries-offset-aliases
128
  time_col (str, optional): Column containing timestamps as pd.Datetime. Defaults to '_timestamp'.
129
  ntop (int, optional): Number of completions to plot. Defaults to 20.
@@ -163,10 +163,10 @@ def plot_completion_rates(
163
 
164
  def plot_completion_rewards(
165
  df: pd.DataFrame,
166
- msg_col: str = "followup_completions",
167
- reward_col: str = "followup_rewards",
168
  time_col: str = "_timestamp",
169
- uid_col: str = "followup_uids",
170
  ntop: int = 3,
171
  completions: List[str] = None,
172
  completion_regex: str = None,
@@ -175,9 +175,10 @@ def plot_completion_rewards(
175
 
176
  Args:
177
  df (pd.DataFrame): Dataframe of event log.
178
- msg_col (str, optional): List-like column containing completions. Defaults to 'followup_completions'.
179
- reward_col (str, optional): List-like column containing rewards. Defaults to 'followup_rewards'.
180
  time_col (str, optional): Column containing timestamps as pd.Datetime. Defaults to '_timestamp'.
 
181
  ntop (int, optional): Number of completions to plot. Defaults to 20.
182
  completions (List[str], optional): List of completions to plot. Defaults to None.
183
  completion_regex (str, optional): Regex to match completions. Defaults to None.
@@ -229,8 +230,8 @@ def plot_completion_rewards(
229
 
230
  def plot_leaderboard(
231
  df: pd.DataFrame,
232
- group_on: str = "answer_uids",
233
- agg_col: str = "answer_rewards",
234
  agg: str = "mean",
235
  ntop: int = 10,
236
  alias: bool = False,
@@ -239,8 +240,8 @@ def plot_leaderboard(
239
 
240
  Args:
241
  df (pd.DataFrame): Dataframe of event log.
242
- group_on (str, optional): Entities to use for grouping. Defaults to 'answer_uids'.
243
- agg_col (str, optional): Column to aggregate. Defaults to 'answer_rewards'.
244
  agg (str, optional): Aggregation function. Defaults to 'mean'.
245
  ntop (int, optional): Number of entities to plot. Defaults to 10.
246
  alias (bool, optional): Whether to use aliases for indices. Defaults to False.
@@ -269,14 +270,14 @@ def plot_leaderboard(
269
 
270
 
271
  def plot_dendrite_rates(
272
- df: pd.DataFrame, uid_col: str = "answer_uids", reward_col: str = "answer_rewards", ntop: int = 20, uids: List[int] = None
273
  ) -> go.Figure:
274
  """Makes a bar chart of the success rate of dendrite calls for a given set of uids.
275
 
276
  Args:
277
  df (pd.DataFrame): Dataframe of event log.
278
- uid_col (str, optional): Column containing uids. Defaults to 'answer_uids'.
279
- reward_col (str, optional): Column containing rewards. Defaults to 'answer_rewards'.
280
  ntop (int, optional): Number of uids to plot. Defaults to 20.
281
  uids (List[int], optional): List of uids to plot. Defaults to None.
282
 
@@ -307,30 +308,36 @@ def plot_dendrite_rates(
307
 
308
  def plot_completion_length_time(
309
  df: pd.DataFrame,
310
- uid_col: str = "answer_uids",
311
- completion_col: str = "answer_completions",
312
- time_col: str = "answer_times",
313
  uids: List[int] = None,
314
- words: bool = False,
315
  ) -> go.Figure:
316
 
 
317
  df = df[[uid_col, completion_col, time_col]].explode(column=[uid_col, completion_col, time_col])
318
  df["time"] = df[time_col].astype(float)
319
  if uids is not None:
320
  df = df.loc[df[uid_col].isin(uids)]
321
 
322
- if words:
 
 
 
323
  df["completion_length"] = df[completion_col].str.split().str.len()
 
 
324
  else:
325
- df["completion_length"] = df[completion_col].str.len()
326
 
327
  return px.scatter(
328
  df,
329
  x='completion_length',
330
  y='time',
331
  color=uid_col if uids is not None else None,
332
- labels={"completion_length": f"Completion Length, {'Words' if words else 'Characters'}", "time": "Time (s)"},
333
- title=f"Completion Length vs Time, {'Words' if words else 'Characters'}",
334
  marginal_x="histogram",
335
  marginal_y="histogram",
336
  hover_data=[uid_col, completion_col],
@@ -348,8 +355,8 @@ def plot_uid_completion_counts(
348
  normalize: bool = True,
349
  ) -> go.Figure:
350
 
351
- completion_col = f'{src}_completions'
352
- uid_col = f'{src}_uids'
353
  if rm_empty:
354
  df = df.loc[df[completion_col].str.len()>0]
355
 
@@ -378,8 +385,8 @@ def plot_uid_completion_counts(
378
 
379
  def plot_network_embedding(
380
  df: pd.DataFrame,
381
- uid_col: str = "followup_uids",
382
- completion_col: str = "followup_completions",
383
  ntop: int = 1,
384
  uids: List[int] = None,
385
  ) -> go.Figure:
@@ -388,8 +395,8 @@ def plot_network_embedding(
388
  Args:
389
  df (pd.DataFrame): Dataframe of event log.
390
 
391
- uid_col (str, optional): Column containing uids. Defaults to 'answer_uids'.
392
- completion_col (str, optional): Column containing completions. Defaults to 'followup_completions'.
393
  ntop (int, optional): Number of uids to plot. Defaults to 20.
394
  hover_data (List[str], optional): Columns to include in hover data. Defaults to None.
395
  uids (List[int], optional): List of uids to plot. Defaults to None.
 
62
  ).update_traces(opacity=0.7)
63
 
64
 
65
+ def plot_uid_diversty(df: pd.DataFrame, x: str = 'followup', y: str = 'answer', remove_unsuccessful: bool = False) -> go.Figure:
66
  """Plot uid diversity as measured by ratio of unique to total completions.
67
 
68
  Args:
69
  df (pd.DataFrame): Dataframe of event log.
70
  """
71
+ return px.scatter(x=[1,2,3],y=[1,2,3])
72
+ xrows = df.loc[df.name.str.contains(x)]
73
+ yrows = df.loc[df.name.str.contains(y)]
74
+ df = pd.merge(xrows, yrows, on='uid', suffixes=('_followup', '_answer'))
75
 
76
  df = df[list_cols].explode(column=list_cols)
77
  if remove_unsuccessful:
 
98
  x="diversity_followup",
99
  y="diversity_answer",
100
  opacity=0.35,
101
+ # size="completions_size",
102
  color="reward_mean",
103
  hover_data=["UID"] + merged.columns.tolist(),
104
  marginal_x="histogram",
 
112
 
113
  def plot_completion_rates(
114
  df: pd.DataFrame,
115
+ msg_col: str = "completions",
116
  time_interval: str = "H",
117
  time_col: str = "_timestamp",
118
  ntop: int = 20,
 
123
 
124
  Args:
125
  df (pd.DataFrame): Dataframe of event log.
126
+ msg_col (str, optional): List-like column containing completions. Defaults to 'completions'.
127
  time_interval (str, optional): Pandas time interval. Defaults to 'H'. See https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#timeseries-offset-aliases
128
  time_col (str, optional): Column containing timestamps as pd.Datetime. Defaults to '_timestamp'.
129
  ntop (int, optional): Number of completions to plot. Defaults to 20.
 
163
 
164
  def plot_completion_rewards(
165
  df: pd.DataFrame,
166
+ msg_col: str = "completions",
167
+ reward_col: str = "rewards",
168
  time_col: str = "_timestamp",
169
+ uid_col: str = "uids",
170
  ntop: int = 3,
171
  completions: List[str] = None,
172
  completion_regex: str = None,
 
175
 
176
  Args:
177
  df (pd.DataFrame): Dataframe of event log.
178
+ msg_col (str, optional): List-like column containing completions. Defaults to 'completions'.
179
+ reward_col (str, optional): List-like column containing rewards. Defaults to 'rewards'.
180
  time_col (str, optional): Column containing timestamps as pd.Datetime. Defaults to '_timestamp'.
181
+ uid_col (str, optional): Column containing UIDs. Defaults to 'uids'.
182
  ntop (int, optional): Number of completions to plot. Defaults to 20.
183
  completions (List[str], optional): List of completions to plot. Defaults to None.
184
  completion_regex (str, optional): Regex to match completions. Defaults to None.
 
230
 
231
  def plot_leaderboard(
232
  df: pd.DataFrame,
233
+ group_on: str = "uids",
234
+ agg_col: str = "rewards",
235
  agg: str = "mean",
236
  ntop: int = 10,
237
  alias: bool = False,
 
240
 
241
  Args:
242
  df (pd.DataFrame): Dataframe of event log.
243
+ group_on (str, optional): Entities to use for grouping. Defaults to 'uids'.
244
+ agg_col (str, optional): Column to aggregate. Defaults to 'rewards'.
245
  agg (str, optional): Aggregation function. Defaults to 'mean'.
246
  ntop (int, optional): Number of entities to plot. Defaults to 10.
247
  alias (bool, optional): Whether to use aliases for indices. Defaults to False.
 
270
 
271
 
272
  def plot_dendrite_rates(
273
+ df: pd.DataFrame, uid_col: str = "uids", reward_col: str = "rewards", ntop: int = 20, uids: List[int] = None
274
  ) -> go.Figure:
275
  """Makes a bar chart of the success rate of dendrite calls for a given set of uids.
276
 
277
  Args:
278
  df (pd.DataFrame): Dataframe of event log.
279
+ uid_col (str, optional): Column containing uids. Defaults to 'uids'.
280
+ reward_col (str, optional): Column containing rewards. Defaults to 'rewards'.
281
  ntop (int, optional): Number of uids to plot. Defaults to 20.
282
  uids (List[int], optional): List of uids to plot. Defaults to None.
283
 
 
308
 
309
  def plot_completion_length_time(
310
  df: pd.DataFrame,
311
+ uid_col: str = "uids",
312
+ completion_col: str = "completions",
313
+ time_col: str = "completion_times",
314
  uids: List[int] = None,
315
+ length_opt: str = 'characters',
316
  ) -> go.Figure:
317
 
318
+
319
  df = df[[uid_col, completion_col, time_col]].explode(column=[uid_col, completion_col, time_col])
320
  df["time"] = df[time_col].astype(float)
321
  if uids is not None:
322
  df = df.loc[df[uid_col].isin(uids)]
323
 
324
+
325
+ if length_opt == 'characters':
326
+ df["completion_length"] = df[completion_col].str.len()
327
+ elif length_opt == 'words':
328
  df["completion_length"] = df[completion_col].str.split().str.len()
329
+ elif length_opt == 'sentences':
330
+ df["completion_length"] = df[completion_col].str.split('.').str.len()
331
  else:
332
+ raise ValueError(f"length_opt must be one of 'words', 'characters', or 'sentences', got {length_opt}")
333
 
334
  return px.scatter(
335
  df,
336
  x='completion_length',
337
  y='time',
338
  color=uid_col if uids is not None else None,
339
+ labels={"completion_length": f"Completion Length, {length_opt.title()}", "time": "Time (s)"},
340
+ title=f"Completion Length vs Time, {length_opt.title()}",
341
  marginal_x="histogram",
342
  marginal_y="histogram",
343
  hover_data=[uid_col, completion_col],
 
355
  normalize: bool = True,
356
  ) -> go.Figure:
357
 
358
+ completion_col = f'completions'
359
+ uid_col = f'uids'
360
  if rm_empty:
361
  df = df.loc[df[completion_col].str.len()>0]
362
 
 
385
 
386
  def plot_network_embedding(
387
  df: pd.DataFrame,
388
+ uid_col: str = "uids",
389
+ completion_col: str = "completions",
390
  ntop: int = 1,
391
  uids: List[int] = None,
392
  ) -> go.Figure:
 
395
  Args:
396
  df (pd.DataFrame): Dataframe of event log.
397
 
398
+ uid_col (str, optional): Column containing uids. Defaults to 'uids'.
399
+ completion_col (str, optional): Column containing completions. Defaults to 'completions'.
400
  ntop (int, optional): Number of uids to plot. Defaults to 20.
401
  hover_data (List[str], optional): Columns to include in hover data. Defaults to None.
402
  uids (List[int], optional): List of uids to plot. Defaults to None.