File size: 1,673 Bytes
63858e7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fe4a287
 
 
 
63858e7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fe4a287
 
 
63858e7
 
 
 
 
fe4a287
 
 
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
import { D3Sel } from "./Util"

/**
 * ATTENTION RESPONSES FROM BACKEND
 *
 * Contain the attentions and embeddings for all combinations of returns from the backend
 */

export type ModelInfo = {
    nlayers: number
    nheads: number
}


/**
 * ATTENTION RESULTS FROM BACKEND
 *
 * These are the results that are encased in the 'aa' and 'ab' keys returned
 */
type AbstractAttentionResponse<T> = {
    aa: T
}

export type AttentionResponse = AbstractAttentionResponse<AttentionMetaResult>
export type AttentionMetaResult = AbstractAttentionResult<FullSingleTokenInfo[]>

export type FullSingleTokenInfo = {
    text: string,
    topk_words: string[],
    topk_probs: number[]
}

interface AbstractAttentionResult<T> {
    att: number[][][],
    left: T,
    right: T,
}

/**
 * SEARCH RESULT TYPES
 */

interface MatchedTokAtt {
    att: number[]
    offset_to_max: number
    loc_of_max: number
}


interface MatchedAttentions {
    in: MatchedTokAtt,
    out: MatchedTokAtt,
}

/**
 * EVENT TYPES
 */
export interface TokenEvent {
    sel?: D3Sel,
    side: SideOptions,
    ind: number | "null",
}

export interface TokenEmbeddingEvent extends TokenEvent {
    embeddings: number[]
}

export type HeadBoxEvent = {
    side: SideOptions,
    ind: number,
    head: number,
}

/**
 * MISCELLANEOUS TYPES
 */

export type SideOptions = "left" | "right"

export enum Toggled {
    ADDED = 0,
    REMOVED,
}

export enum NormBy {
    ROW = 0,
    COL,
    ALL
}

export enum ModelKind {
    Bidirectional = "bidirectional",
    Autoregressive = "autoregressive"
}
export type TokenOptions = "a" | "b" | "all"
export type SentenceOptions = "ab" | "ba" | "aa" | "bb" | "all";