Spaces:
Runtime error
Runtime error
File size: 16,478 Bytes
32f0b26 70ab0be 32f0b26 4adf2d3 32f0b26 4adf2d3 32f0b26 4adf2d3 32f0b26 4adf2d3 32f0b26 c55019b 32f0b26 c55019b 32f0b26 c55019b 32f0b26 c55019b 32f0b26 c55019b 32f0b26 4adf2d3 c55019b 32f0b26 b04690b 32f0b26 b04690b 32f0b26 b04690b 32f0b26 b04690b 32f0b26 70ab0be 32f0b26 c302134 32f0b26 4adf2d3 32f0b26 b04690b 32f0b26 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 |
<script lang="ts">
import { onMount } from "svelte";
import Section from "./Section.svelte";
import KeywordSearch from "./KeywordSearch.svelte";
import OverallResults from "./OverallResults.svelte";
import ClusterResults from "./ClusterResults.svelte";
import HelpTooltip from "./HelpTooltip.svelte";
import TopicTraining from "./TopicTraining.svelte";
import { error_type } from './stores/error_type_store.js';
import { topic_chosen } from './stores/cur_topic_store.js';
import { model_chosen } from './stores/cur_model_store.js';
import Button, { Label } from "@smui/button";
import LinearProgress from "@smui/linear-progress";
import LayoutGrid, { Cell } from "@smui/layout-grid";
import Radio from '@smui/radio';
import FormField from '@smui/form-field';
import{ Wrapper } from '@smui/tooltip';
import IconButton from '@smui/icon-button';
import Svelecte from '../node_modules/svelecte/src/Svelecte.svelte';
export let personalized_model;
export let cur_error_type = "Both";
export let cur_user;
let evidence = [];
let show_audit_settings = false;
let error_type_options = [
{
"opt": 'Both',
"descr": '(System is under- or over-sensitive)',
"help": "View both types of potential system errors"
},
{
"opt": 'System is under-sensitive',
"descr": '(Incorrectly rates as non-toxic)',
"help": "Focus on system errors where the system labeled content as Non-toxic when it should have been labeled as Toxic."
},
{
"opt": 'System is over-sensitive',
"descr": '(Incorrectly rates as toxic)',
"help": "Focus on system errors where the system labeled content as Toxic when it should have been labeled as Non-toxic."
},
{
"opt": 'Show errors and non-errors',
"descr": '',
"help": "Also show cases that are not likely to be potential errors"
},
]
let personalized_models = [];
let systems = ["YouSocial comment toxicity classifier"]; // Only one system for now
let clusters = [];
let clusters_for_tuning = []
let promise = Promise.resolve(null);
// Handle routing
let searchParams = new URLSearchParams(window.location.search);
let scaffold_method = searchParams.get("scaffold");
let mode = searchParams.get("mode");
let topic_vis_method = searchParams.get("topic_vis_method");
// Set audit type
let audit_types = [
"All topic exploration",
"Single topic exploration"
];
let audit_type;
if (scaffold_method == "fixed" || scaffold_method == "personal" || scaffold_method == "personal_group" || scaffold_method == "personal_test" || scaffold_method == "personal_cluster" || scaffold_method == "topic_train" || scaffold_method == "prompts") {
audit_type = audit_types[1];
} else {
// No scaffolding mode or tutorial
audit_type = audit_types[0];
}
let show_topic_training = false;
if (scaffold_method == "topic_train") {
show_topic_training = true;
}
// Handle non-model mode
let use_model = true;
if (mode == "no_model") {
use_model = false;
cur_error_type = "Show errors and non-errors";
}
// Handle group model
let use_group_model = false;
if (scaffold_method == "personal_group") {
use_group_model = true;
}
let promise_cluster = Promise.resolve(null);
// Get current topic from store
let topic;
topic_chosen.subscribe(value => {
topic = value;
handleClusterButton(); // re-render cluster results
});
// Get current model from store
model_chosen.subscribe(value => {
personalized_model = value;
// Add to personalized_models if not there
if (!personalized_models.includes(personalized_model)) {
personalized_models.push(personalized_model);
}
getAuditResults();
});
// Save current error type
async function updateErrorType() {
error_type.update((value) => cur_error_type);
handleAuditButton();
handleClusterButton();
}
async function updateTopicChosen() {
if (topic != null) {
topic_chosen.update((value) => topic);
}
}
function getAuditResults() {
let req_params = {
user: cur_user,
scaffold_method: scaffold_method,
};
let params = new URLSearchParams(req_params).toString();
fetch("./audit_settings?" + params)
.then((r) => r.text())
.then(function (r_orig) {
let r = JSON.parse(r_orig);
personalized_models = r["personalized_models"];
if (use_group_model) {
let personalized_model_grp = r["personalized_model_grp"];
personalized_model = personalized_model_grp[0];
} else {
personalized_model = personalized_models[0]; // TEMP
}
model_chosen.update((value) => personalized_model);
clusters = r["clusters"];
clusters_for_tuning = r["clusters_for_tuning"];
topic = clusters[0]["options"][0]["text"];
topic_chosen.update((value) => topic);
handleAuditButton();
handleClusterButton();
});
}
onMount(async () => {
getAuditResults();
});
function handleAuditButton() {
model_chosen.update((value) => personalized_model);
if (personalized_model == "" || personalized_model == undefined) {
return;
}
promise = getAudit(personalized_model);
}
async function getAudit(pers_model) {
let req_params = {
pers_model: pers_model,
perf_metric: "avg_diff",
breakdown_sort: "difference",
n_topics: 10,
error_type: "Both", // Only allow both error types
cur_user: cur_user,
topic_vis_method: topic_vis_method,
};
let params = new URLSearchParams(req_params).toString();
const response = await fetch("./get_audit?" + params);
const text = await response.text();
const data = JSON.parse(text);
return data;
}
function handleClusterButton() {
promise_cluster = getCluster(personalized_model);
}
async function getCluster(pers_model) {
if (pers_model == "" || pers_model == undefined) {
return null;
}
let req_params = {
cluster: topic,
topic_df_ids: [],
cur_user: cur_user,
pers_model: pers_model,
example_sort: "descending", // TEMP
comparison_group: "status_quo", // TEMP
search_type: "cluster",
keyword: "",
error_type: cur_error_type,
use_model: use_model,
scaffold_method: scaffold_method,
};
let params = new URLSearchParams(req_params).toString();
const response = await fetch("./get_cluster_results?" + params);
const text = await response.text();
const data = JSON.parse(text);
return data;
}
</script>
<div>
<!-- 0: Audit settings -->
<div>
<div style="margin-top: 30px">
<span class="head_3">Auditing</span>
</div>
<div style="width: 80%">
{#if personalized_model}
<p>In this section, we'll be auditing the content moderation system. Here, you’ll be aided by a personalized model that will help direct your attention towards potential problem areas in the model’s performance. This model isn’t meant to be perfect, but is designed to help you better focus on areas that need human review.</p>
{:else}
<p>Please first train your personalized model by following the steps in the "Labeling" tab (click the top left tab above).</p>
{/if}
</div>
{#if show_audit_settings}
<div class="audit_section">
<div class="head_5">Audit settings</div>
<div style="width: 50%">
<p>Choose your audit settings here. These settings will affect all of the visualizations that follow, so you can return back here to make changes.</p>
</div>
<div class="section_indent">
<Section
section_id="systems"
section_title="What status-quo system would you like to audit?"
section_opts={systems}
bind:value={systems[0]}
width_pct={40}
/>
{#key personalized_model}
<Section
section_id="personalized_model"
section_title="What model would you like to use to represent your views?"
section_opts={personalized_models}
bind:value={personalized_model}
width_pct={40}
on:change
/>
{/key}
<Section
section_id="audit_type"
section_title="What type of audit are you conducting?"
section_opts={audit_types}
bind:value={audit_type}
width_pct={40}
on:change
/>
<LayoutGrid>
<Cell span={7}>
<Button
on:click={handleAuditButton}
variant="outlined"
class="button_float_right"
>
<Label>Start your audit</Label>
</Button>
</Cell>
</LayoutGrid>
</div>
</div>
{/if}
{#if personalized_model}
<p>Current model: {personalized_model}</p>
{/if}
</div>
<!-- 1: All topics overview -->
{#if personalized_model}
{#if audit_type == audit_types[0]}
<div class="audit_section">
<div class="head_5">Overview of all topics</div>
<p>First, browse the system performance by different auto-generated comment topic areas.</p>
<div class="section_indent">
{#await promise}
<div class="app_loading">
<LinearProgress indeterminate />
</div>
{:then audit_results}
{#if audit_results}
<OverallResults
data={audit_results}
clusters={clusters}
personalized_model={personalized_model}
cluster={topic}
/>
{/if}
{:catch error}
<p style="color: red">{error.message}</p>
{/await}
</div>
</div>
{/if}
<!-- 2a: Topic training -->
{#if show_topic_training}
<div class="audit_section">
<div class="head_5">Topic model training</div>
<p></p>
<div class="section_indent">
<div>
<p>In what topic area would you like to tune your model?</p>
<Svelecte
options={clusters_for_tuning}
labelAsValue={true}
bind:value={topic}
placeholder="Select topic"
on:change={null}
style="width: 50%"
>
</Svelecte>
</div>
<div style="padding-top: 30px">
<!-- Labeling -->
<h6>Comments to label</h6>
<ul>
<li>
Comments with scores <b>0</b> and <b>1</b> will be allowed to <b>remain</b> on the platform.
</li>
<li>
Comments with scores <b>2</b>, <b>3</b>, or <b>4</b> will be <b>deleted</b> from the platform.
</li>
<li>
Given that some comments may lack context, if you're not sure, feel free to mark the <b>unsure</b> option to skip a comment.
</li>
</ul>
{#key topic}
<TopicTraining topic={topic} cur_user={cur_user}/>
{/key}
</div>
</div>
</div>
{/if}
<!-- 2: Topic overview -->
<div class="audit_section">
<div class="head_5">Topic exploration</div>
<p></p>
<div class="section_indent">
<div>
<div>
<p><b>What topic would you like to explore further?</b></p>
<Svelecte
options={clusters}
labelAsValue={true}
bind:value={topic}
placeholder="Select topic"
on:change={updateTopicChosen}
style="width: 50%"
>
</Svelecte>
</div>
{#if use_model}
<div style="padding-top: 30px">
<p><b>What kind of system errors do you want to focus on?</b></p>
{#each error_type_options as e}
<div style="display: flex; align-items: center;">
<Wrapper rich>
<FormField>
<Radio bind:group={cur_error_type} value={e.opt} on:change={updateErrorType} color="secondary" />
<span slot="label">
<b>{e.opt}</b> {e.descr}
<IconButton class="material-icons" size="button" disabled>help_outline</IconButton>
</span>
</FormField>
<HelpTooltip text={e.help} />
</Wrapper>
</div>
{/each}
</div>
{/if}
</div>
<div style="padding-top: 30px">
{#await promise_cluster}
<div class="app_loading">
<LinearProgress indeterminate />
</div>
{:then cluster_results}
{#if cluster_results}
{#if topic}
<ClusterResults
cluster={topic}
clusters={clusters}
model={personalized_model}
data={cluster_results}
table_width_pct={100}
table_id={"main"}
use_model={use_model}
bind:evidence={evidence}
on:change
/>
{/if}
{/if}
{:catch error}
<p style="color: red">{error.message}</p>
{/await}
</div>
</div>
</div>
<!-- 3: Gather evidence -->
<div class="audit_section">
<div class="head_5">Gather additional evidence</div>
<p>Next, you can optionally search for more comments to serve as evidence through manual keyword search (for individual words or phrases).</p>
<div class="section_indent">
{#key error_type}
<KeywordSearch clusters={clusters} personalized_model={personalized_model} cur_user={cur_user} bind:evidence={evidence} use_model={use_model} on:change/>
{/key}
</div>
</div>
<!-- 4: Test hunch -->
<div class="audit_section">
<div class="head_5">Finalize your current report</div>
<p>Finally, review the report you've generated on the side panel and provide a brief summary of the problem you see. You may also list suggestions or insights into addressing this problem if you have ideas. This report will be directly used by the model developers to address the issue you've raised</p>
</div>
{/if}
</div>
<style>
</style> |