Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 2 additions & 28 deletions python/inspectus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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,
Expand Down
4 changes: 0 additions & 4 deletions ui/src/attention_matrix_view.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -44,7 +43,6 @@ class CellView {
}

export class AttentionMatrixView {
private attentions: number[][];
private srcTokens: Tokens;
private dstTokens: Tokens;
private srcTokenElems: TokenLabelView[];
Expand All @@ -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)
Expand Down
21 changes: 0 additions & 21 deletions ui/src/charts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[],
Expand Down
6 changes: 3 additions & 3 deletions ui/src/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {}
Expand Down Expand Up @@ -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 }[] => {
Expand Down Expand Up @@ -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))
}
}

Expand Down
7 changes: 3 additions & 4 deletions ui/src/line_grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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;
Expand All @@ -173,7 +172,7 @@ export class LineGridView {
}

addClickHandler(handler: SelectCallback) {
this.selectHanlder = handler
this.selectHandler = handler
}

render() {
Expand Down Expand Up @@ -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)
}
}

Expand Down
16 changes: 0 additions & 16 deletions ui/src/token_loss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
// }
// })
})
}

Expand Down