Spaces:
Sleeping
Sleeping
Jac-Zac commited on
Commit ·
be9cdae
1
Parent(s): 2bf3d21
Fixing bugs with the UI and adding colors to remote hugginface
Browse files- Dockerfile +1 -0
- tabs/compare.py +10 -4
- tabs/extract.py +32 -18
Dockerfile
CHANGED
|
@@ -13,6 +13,7 @@ RUN uv sync --frozen --no-dev
|
|
| 13 |
|
| 14 |
COPY app.py ./
|
| 15 |
COPY state.py ./
|
|
|
|
| 16 |
COPY tabs/ ./tabs/
|
| 17 |
COPY utils/ ./utils/
|
| 18 |
|
|
|
|
| 13 |
|
| 14 |
COPY app.py ./
|
| 15 |
COPY state.py ./
|
| 16 |
+
COPY .streamlit/ ./.streamlit/
|
| 17 |
COPY tabs/ ./tabs/
|
| 18 |
COPY utils/ ./utils/
|
| 19 |
|
tabs/compare.py
CHANGED
|
@@ -147,7 +147,9 @@ def _load_persona_options(
|
|
| 147 |
),
|
| 148 |
assistant_ids[0] if assistant_ids else None,
|
| 149 |
)
|
| 150 |
-
regular_ids = [
|
|
|
|
|
|
|
| 151 |
if not regular_ids and assistant_id is None:
|
| 152 |
st.info("No personas found for this model and variant.")
|
| 153 |
return None
|
|
@@ -173,7 +175,9 @@ def _seed_persona_memory(
|
|
| 173 |
options.assistant_id in legacy_ids,
|
| 174 |
)
|
| 175 |
|
| 176 |
-
default_count =
|
|
|
|
|
|
|
| 177 |
remembered_count = int(st.session_state.get(remembered_count_key, default_count))
|
| 178 |
persona_count = min(max(remembered_count, 0), len(options.regular_ids))
|
| 179 |
include_assistant = bool(
|
|
@@ -285,7 +289,9 @@ def _select_artifact_personas(
|
|
| 285 |
return []
|
| 286 |
|
| 287 |
regular_label = f"{persona_count} persona{'s' if persona_count != 1 else ''}"
|
| 288 |
-
assistant_label =
|
|
|
|
|
|
|
| 289 |
st.caption(f"Using {regular_label}{assistant_label}.")
|
| 290 |
return persona_ids
|
| 291 |
|
|
@@ -308,7 +314,7 @@ def _render_mask_strategy_select(scope: str) -> MaskStrategy:
|
|
| 308 |
return render_mask_strategy_select(
|
| 309 |
key=widget_key("load", "mask_strategy", scope),
|
| 310 |
last_key=_LAST_MASK_STRATEGY_KEY,
|
| 311 |
-
|
| 312 |
)
|
| 313 |
|
| 314 |
|
|
|
|
| 147 |
),
|
| 148 |
assistant_ids[0] if assistant_ids else None,
|
| 149 |
)
|
| 150 |
+
regular_ids = [
|
| 151 |
+
persona_id for persona_id in persona_ids if persona_id not in assistant_ids
|
| 152 |
+
]
|
| 153 |
if not regular_ids and assistant_id is None:
|
| 154 |
st.info("No personas found for this model and variant.")
|
| 155 |
return None
|
|
|
|
| 175 |
options.assistant_id in legacy_ids,
|
| 176 |
)
|
| 177 |
|
| 178 |
+
default_count = (
|
| 179 |
+
len(options.regular_ids) if default_all else min(1, len(options.regular_ids))
|
| 180 |
+
)
|
| 181 |
remembered_count = int(st.session_state.get(remembered_count_key, default_count))
|
| 182 |
persona_count = min(max(remembered_count, 0), len(options.regular_ids))
|
| 183 |
include_assistant = bool(
|
|
|
|
| 289 |
return []
|
| 290 |
|
| 291 |
regular_label = f"{persona_count} persona{'s' if persona_count != 1 else ''}"
|
| 292 |
+
assistant_label = (
|
| 293 |
+
" plus Assistant" if include_assistant and options.assistant_id else ""
|
| 294 |
+
)
|
| 295 |
st.caption(f"Using {regular_label}{assistant_label}.")
|
| 296 |
return persona_ids
|
| 297 |
|
|
|
|
| 314 |
return render_mask_strategy_select(
|
| 315 |
key=widget_key("load", "mask_strategy", scope),
|
| 316 |
last_key=_LAST_MASK_STRATEGY_KEY,
|
| 317 |
+
help_text="Which extracted activation set to load.",
|
| 318 |
)
|
| 319 |
|
| 320 |
|
tabs/extract.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import html
|
| 2 |
from dataclasses import dataclass
|
| 3 |
|
|
|
|
| 4 |
import streamlit as st
|
| 5 |
from persona_data.prompts import format_prompt
|
| 6 |
from persona_data.synth_persona import BASELINE_PERSONA_ID, PersonaData, QAPair
|
|
@@ -12,8 +13,8 @@ from persona_vectors.extraction import (
|
|
| 12 |
)
|
| 13 |
from persona_vectors.preview import TokenSegment, preview_token_segments
|
| 14 |
|
| 15 |
-
from utils.datasets import load_dataset, load_persona_list
|
| 16 |
from utils.controls import render_mask_strategy_select
|
|
|
|
| 17 |
from utils.helpers import (
|
| 18 |
NDIF_STATUS_ICONS,
|
| 19 |
persona_label,
|
|
@@ -164,29 +165,42 @@ def _render_persona_select(
|
|
| 164 |
return selected_personas
|
| 165 |
|
| 166 |
|
| 167 |
-
_TOKEN_LEGEND = (
|
| 168 |
-
'<div style="display:flex;gap:12px;flex-wrap:wrap;font-size:0.8em;margin-bottom:8px">'
|
| 169 |
-
'<span style="background:#86efac;color:black;padding:1px 6px;border-radius:3px">masked</span>'
|
| 170 |
-
'<span style="color:#fde047;padding:1px 6px">question</span>'
|
| 171 |
-
'<span style="color:#22d3ee;padding:1px 6px">response</span>'
|
| 172 |
-
'<span style="color:#d946ef;font-weight:bold;padding:1px 6px">special</span>'
|
| 173 |
-
'<span style="color:#9ca3af;padding:1px 6px">template</span>'
|
| 174 |
-
"</div>"
|
| 175 |
-
)
|
| 176 |
-
|
| 177 |
_MAX_PREVIEW_SAMPLES = 3
|
| 178 |
|
| 179 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
def _token_style(segment: TokenSegment) -> str:
|
|
|
|
| 181 |
style = {
|
| 182 |
-
"response": "color:
|
| 183 |
-
"question": "color:
|
| 184 |
-
}.get(segment.role, "color:
|
| 185 |
|
| 186 |
if segment.is_special:
|
| 187 |
-
style = "color:
|
| 188 |
if segment.is_masked:
|
| 189 |
-
style =
|
|
|
|
|
|
|
|
|
|
| 190 |
return style
|
| 191 |
|
| 192 |
|
|
@@ -215,7 +229,7 @@ def _render_mask_strategy_select(
|
|
| 215 |
return render_mask_strategy_select(
|
| 216 |
key=_extract_widget_key(model_name, remote, dataset_source, "mask_strategy"),
|
| 217 |
last_key=_LAST_MASK_STRATEGY_KEY,
|
| 218 |
-
|
| 219 |
)
|
| 220 |
|
| 221 |
|
|
@@ -290,7 +304,7 @@ def _render_token_preview(
|
|
| 290 |
) -> None:
|
| 291 |
with st.spinner("Loading tokenizer..."):
|
| 292 |
model = cached_model(model_name=model_name)
|
| 293 |
-
st.markdown(
|
| 294 |
for persona, qa_pairs, variant in run_plan:
|
| 295 |
system_prompt = format_prompt(persona, variant) # type: ignore[arg-type]
|
| 296 |
prepared = prepare_inputs_for_strategy(
|
|
|
|
| 1 |
import html
|
| 2 |
from dataclasses import dataclass
|
| 3 |
|
| 4 |
+
from catppuccin import PALETTE
|
| 5 |
import streamlit as st
|
| 6 |
from persona_data.prompts import format_prompt
|
| 7 |
from persona_data.synth_persona import BASELINE_PERSONA_ID, PersonaData, QAPair
|
|
|
|
| 13 |
)
|
| 14 |
from persona_vectors.preview import TokenSegment, preview_token_segments
|
| 15 |
|
|
|
|
| 16 |
from utils.controls import render_mask_strategy_select
|
| 17 |
+
from utils.datasets import load_dataset, load_persona_list
|
| 18 |
from utils.helpers import (
|
| 19 |
NDIF_STATUS_ICONS,
|
| 20 |
persona_label,
|
|
|
|
| 165 |
return selected_personas
|
| 166 |
|
| 167 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
_MAX_PREVIEW_SAMPLES = 3
|
| 169 |
|
| 170 |
|
| 171 |
+
def _preview_palette():
|
| 172 |
+
flavor = PALETTE.latte if st.get_option("theme.base") == "light" else PALETTE.mocha
|
| 173 |
+
return flavor.colors
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
def _render_token_legend_html() -> str:
|
| 177 |
+
c = _preview_palette()
|
| 178 |
+
return (
|
| 179 |
+
'<div style="display:flex;gap:12px;flex-wrap:wrap;font-size:0.8em;margin-bottom:8px">'
|
| 180 |
+
f'<span style="background:{c.green.hex};color:{c.base.hex};'
|
| 181 |
+
'padding:1px 6px;border-radius:3px">masked</span>'
|
| 182 |
+
f'<span style="color:{c.yellow.hex};padding:1px 6px">question</span>'
|
| 183 |
+
f'<span style="color:{c.sky.hex};padding:1px 6px">response</span>'
|
| 184 |
+
f'<span style="color:{c.mauve.hex};font-weight:bold;padding:1px 6px">special</span>'
|
| 185 |
+
f'<span style="color:{c.subtext1.hex};padding:1px 6px">template</span>'
|
| 186 |
+
"</div>"
|
| 187 |
+
)
|
| 188 |
+
|
| 189 |
+
|
| 190 |
def _token_style(segment: TokenSegment) -> str:
|
| 191 |
+
c = _preview_palette()
|
| 192 |
style = {
|
| 193 |
+
"response": f"color:{c.sky.hex}",
|
| 194 |
+
"question": f"color:{c.yellow.hex}",
|
| 195 |
+
}.get(segment.role, f"color:{c.subtext1.hex}")
|
| 196 |
|
| 197 |
if segment.is_special:
|
| 198 |
+
style = f"color:{c.mauve.hex};font-weight:bold"
|
| 199 |
if segment.is_masked:
|
| 200 |
+
style = (
|
| 201 |
+
f"{style};background:{c.green.hex};color:{c.base.hex};"
|
| 202 |
+
"border-radius:2px;padding:0 1px"
|
| 203 |
+
)
|
| 204 |
return style
|
| 205 |
|
| 206 |
|
|
|
|
| 229 |
return render_mask_strategy_select(
|
| 230 |
key=_extract_widget_key(model_name, remote, dataset_source, "mask_strategy"),
|
| 231 |
last_key=_LAST_MASK_STRATEGY_KEY,
|
| 232 |
+
help_text="Which tokens contribute to the averaged hidden state.",
|
| 233 |
)
|
| 234 |
|
| 235 |
|
|
|
|
| 304 |
) -> None:
|
| 305 |
with st.spinner("Loading tokenizer..."):
|
| 306 |
model = cached_model(model_name=model_name)
|
| 307 |
+
st.markdown(_render_token_legend_html(), unsafe_allow_html=True)
|
| 308 |
for persona, qa_pairs, variant in run_plan:
|
| 309 |
system_prompt = format_prompt(persona, variant) # type: ignore[arg-type]
|
| 310 |
prepared = prepare_inputs_for_strategy(
|