diff --git a/python/inspectus/__init__.py b/python/inspectus/__init__.py index 8f695ef..98d90a3 100644 --- a/python/inspectus/__init__.py +++ b/python/inspectus/__init__.py @@ -95,30 +95,6 @@ def attention(attn: Union[ ) -def compress_series(series, compress_steps=1): - """ - Compresses a series to blocks of `compress_steps` - - Args: - series: series as a list of dictionaries - compress_steps: number of steps to compress - - Returns: - - """ - res = [] - for d in series: - values = d['values'] - if not isinstance(values, list): - values = [values] - if not res or d['step'] - res[-1]['step'] >= compress_steps: - res.append({'step': d['step'], 'values': [] + values}) - else: - res[-1]['values'] += values - - return res - - def series_to_distribution(series: Union[ List[Dict], List['torch.Tensor'], @@ -162,7 +138,7 @@ def series_to_distribution(series: Union[ mean = np.mean(data) step = steps[i] if steps is not None else i - histogram = [dist[i] for i in range(0, 9)] + histogram = dist.tolist() row = { 'step': step, 'histogram': histogram, @@ -201,7 +177,7 @@ def distribution(data: Dict[str, Union[ levels : int, optional An Integer between 1 and 5, the number of levels in the visualization. Default is 5. alpha : float, optional - Opacity of the first band. Reduces by powers for each level. Default is 0.6. + Opacity of the first band. Reduces by powers for each level. Default is 0.5. color_scheme : str, optional The color scheme to use for the visualization. Default is 'tableau10'. height : int, optional @@ -224,7 +200,6 @@ def distribution(data: Dict[str, Union[ levels = 1 table = [] - i = 0 for name, series in data.items(): if len(series) == 0: continue @@ -233,7 +208,6 @@ def distribution(data: Dict[str, Union[ table += _histogram_to_table(series, name) else: table += _histogram_to_table(series_to_distribution(series), name) - i += 1 return render(table, levels=levels, diff --git a/ui/src/attention_matrix_view.ts b/ui/src/attention_matrix_view.ts index 3adde1b..a6c7378 100644 --- a/ui/src/attention_matrix_view.ts +++ b/ui/src/attention_matrix_view.ts @@ -1,7 +1,6 @@ import {Weya as $} from '../lib/weya/weya' import {Tokens} from "./controller"; import {TokenLabelView} from "./token_label_view"; -import {createMatrix} from "./utils"; import {DimValue} from "./types"; import {PlotColors} from "./colors"; import {ChartType} from "./types"; @@ -44,7 +43,6 @@ class CellView { } export class AttentionMatrixView { - private attentions: number[][]; private srcTokens: Tokens; private dstTokens: Tokens; private srcTokenElems: TokenLabelView[]; @@ -62,8 +60,6 @@ export class AttentionMatrixView { this.srcTokens = srcTokens this.dstTokens = dstTokens - this.attentions = createMatrix(srcTokens.length, dstTokens.length) - this.srcTokenElems = [] for (let i = 0; i < srcTokens.length; ++i) { let v = this.srcTokens.getTokenLabelView(i) diff --git a/ui/src/charts.ts b/ui/src/charts.ts index b0e01cf..c35934a 100644 --- a/ui/src/charts.ts +++ b/ui/src/charts.ts @@ -28,27 +28,6 @@ window["chartsEmbed"] = function ( document.getElementById(elemId).appendChild(chart.render(theme)) } -window["chartsEmbedTest"] = function () { - let sample: any = {} // require('/assets/attention.json') - let chartData = new ChartData(sample) - let plotColors = new PlotColors("light") - let chart = new Controller( - chartData.dimensions, - chartData.attention, - { tokens: chartData.src_tokens }, - { tokens: chartData.tgt_tokens }, - [ - ChartType.AttentionMatrix, - ChartType.SrcTokenHeatmap, - ChartType.TokenDimHeatmap, - ChartType.DimensionHeatmap, - ChartType.LineGrid, - ], - plotColors - ) - document.body.appendChild(chart.render("auto")) -} - window["tokenViz"] = function ( elemId: string, tokens: string[], diff --git a/ui/src/controller.ts b/ui/src/controller.ts index 2fcf9fc..e291950 100644 --- a/ui/src/controller.ts +++ b/ui/src/controller.ts @@ -284,7 +284,7 @@ export class Controller { return res } - private calcGridAttentionAttention(dim1: string, dim2: string): GridAttention { + private calcGridAttention(dim1: string, dim2: string): GridAttention { let res = {} for (let dv1 of getDimValues(dim1, this.dimensionsMap)) { res[dv1] = {} @@ -376,7 +376,7 @@ export class Controller { } private onLineGridDimChange = (dim1: string, dim2: string): GridAttention => { - return this.calcGridAttentionAttention(dim1, dim2) + return this.calcGridAttention(dim1, dim2) } private onTokenHeatmapDimChange = (selDim: string): { [value: DimValue]: number }[] => { @@ -418,7 +418,7 @@ export class Controller { if (this.chartTypes.includes(ChartType.LineGrid)) { this.lineGridView.setSelection(this.selected) - this.lineGridView.setAttention(this.calcGridAttentionAttention(this.lineGridView.dim1, this.lineGridView.dim2)) + this.lineGridView.setAttention(this.calcGridAttention(this.lineGridView.dim1, this.lineGridView.dim2)) } } diff --git a/ui/src/line_grid.ts b/ui/src/line_grid.ts index a573222..ed8a5a4 100644 --- a/ui/src/line_grid.ts +++ b/ui/src/line_grid.ts @@ -95,7 +95,6 @@ class LineCellView { e.preventDefault() e.stopPropagation() - console.log('click', this.dims) for (let d of this.dims) { this.handler(d.d, d.v, false) } @@ -149,7 +148,7 @@ export class LineGridView { dim2: string; private chartElem: SVGSVGElement; private dimChangeHandler: any; - private selectHanlder: SelectCallback + private selectHandler: SelectCallback private selected: { [p: string]: { [p: DimValue]: boolean } }; private cells: LineCellView[][] private cellWidth: number; @@ -173,7 +172,7 @@ export class LineGridView { } addClickHandler(handler: SelectCallback) { - this.selectHanlder = handler + this.selectHandler = handler } render() { @@ -273,7 +272,7 @@ export class LineGridView { this.dstTokens.length, this.cellHeight, this.cellWidth)) this.cellLayers[i][j].appendChild(this.cells[i][j].render()) - this.cells[i][j].addClickHandler(this.dim1, dv1[i], this.dim2, dv2[j], this.selectHanlder) + this.cells[i][j].addClickHandler(this.dim1, dv1[i], this.dim2, dv2[j], this.selectHandler) } } diff --git a/ui/src/token_loss.ts b/ui/src/token_loss.ts index d258503..616d8dd 100644 --- a/ui/src/token_loss.ts +++ b/ui/src/token_loss.ts @@ -46,22 +46,6 @@ class TokenView { info: this.info, }) }) - // this.menu = $("div", ".menu", ($) => { - // for (let i = 0; i < this.values.length; ++i) { - // $("div", ($) => { - // $( - // "div", - // `${this.values[i].name}: ${this.values[ - // i - // ].value.toExponential()}` - // ) - // }) - // } - // $("hr") - // if (this.info != null) { - // $("pre", this.info) - // } - // }) }) }