File size: 5,074 Bytes
63858e7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
// import { BertAPI } from './api/bertApi'
// import { DemoAPI } from './api/demoApi'
import {API} from './api/mainApi'
import * as d3 from 'd3'
import * as R from 'ramda'
import * as _ from 'lodash'
import * as nj from 'numjs'
import * as x_ from './etc/_Tools'
import * as tf from '@tensorflow/tfjs'
import {TokenDisplay, TokenWrapper, sideToLetter} from './data/TokenWrapper'
import {AttentionWrapper} from "./data/AttentionCapsule"
import {FaissSearchResultWrapper} from "./data/FaissSearchWrapper"

const api = new API()


/**
 * To learn about the behavior of the functions that I write, without writing a professional test suite
 * (cuz time constraints / I don't know how to do a testing suite well in Typescript)
 */
export class Tester {
    // static testTf() {
    //     const a = tf.randomUniform([3,3,4]);
    //     const b = a.gather([0, 1], 0);
    //     const a_out = a.arraySync();
    //     console.log(a_out);
    // }

    // static testAttWrapperConstructor() {
    //     api.getAttentions("Simple test one", "another test two").then(r => {
    //         const att = new AttentionWrapper(r);
    //         console.log(att.all);
    //     })
    // }

    // static testNjAray() {
    //     const a = nj.ones([1,7,12], 'int32')
    //     const b = a
    //     b.slice(null, 0, 11).assign(0, false)
    //     console.log(b.tolist());
    // }

    // static testFindIdx() {
    //     const bad_toks = ['[CLS]', '[SEP]']
    //     const left_text = ['[CLS]', 'this', 'is', 'sentence', '[SEP]', '[CLS]']
    //     // const bad_inds = _.findAllIndexes(left_text, (a) => _.includes(bad_toks, a))
    //     const bad_inds = x_.findAllIndexes(left_text, (a) => _.includes(bad_toks, a))
    //     console.log(bad_inds);
    // }

    // static testUpdateMaskedAttention(){
    //     const as = 'this is a long string that has some meaning'
    //     const bs = 'String part 2'
    //     const a = ['[CLS]', 'this', 'is', 'a', 'long', 'string', 'that', 'has', 'some', 'meaning', '[SEP]']
    //     const b = ['string', 'part', '2', '[SEP]']
    //     const maskA = [1, 7, 9]
    //     const maskB = [] // CAN'T BE EMPTY

    //     const api = new BertAPI()

    //     const val1 = new TokenDisplay(a, maskA)
    //     const val2 = new TokenDisplay(b, maskB)

    //     api.updateMaskedAttentions(val1, val2).then(
    //         (r) => {
    //             console.log(r.ab.left_text);
    //             console.log(r.ab.right_text);
    //         }
    //     )
    // }

    // static testOrderedInsert() {
    //     const a = [1, 3, 6, 8, 9]
    //     const a2 = [1, 6, 8, 22, 9]
    //     const a3 = []
    //     const val = 4
    //     x_.orderedInsert_(a, val)
    //     console.log(a);

    //     x_.orderedInsert_(a2, val, true)
    //     console.log(a2);

    //     x_.orderedInsert_(a3, val)
    //     console.log(a3);
    // }

    // static testTokenDisplay() {
    //     const toksa = ['yes', 'my', 'good', 'sir']
    //     const toksb = ['hi', 'there']
    //     const masksa = []
    //     const masksb = []
    //     const td = new TokenDisplay(toksa, masksa)
    //     const td2 = new TokenDisplay(toksb, masksb)
    //     const twrap = new TokenWrapper(toksa, toksb, masksa, masksb)

    //     // console.log(twrap.a);
    //     // console.log(twrap.b);
    //     // console.log(twrap.all);
    //     // twrap.mask("a", 3)

    //     // console.log(twrap.a);
    //     // console.log(twrap.all);
    //     twrap.mask("all", 1)
    //     console.log(twrap.b);
    //     console.log(twrap.all);
    // }

    // static testFaissWrapper() {
    //     const q = x_.makeRandom(768);
    //     api.getNearestWozEmbeddings(q, 0, 10).then(
    //         r => {
    //             const fsw = new FaissSearchResultWrapper(r)
    //             console.log(fsw.toStringArr());
    //         }
    //     )
    // }

    // static testSideToLetter() {
    //     const side = "left"
    //     console.log( sideToLetter(side, "all"));
    //     console.log( sideToLetter(side, "ab"));
    //     console.log( sideToLetter(side, "ba"));
    //     console.log( sideToLetter(side, "bb"));
    //     console.log( sideToLetter(side, "aa"));
    //     console.log( sideToLetter("right", "aa"));
    //     console.log( sideToLetter("abc", "aa")); // no error thrown... But linting catches an issue
    // }

    // static testRandomArrayCreation() {
    //     console.log(x_.makeRandom(10));
    // }

    // static testFaissSearchResultsHist () {
    //     api.getNearestWozEmbeddings(x_.makeRandom(768), 0).then(val => {
    //         const fsw = new FaissSearchResultWrapper(val);
    //         console.log(fsw.getHistogram());
    //     })

    // }

    static testReadingJSON () {
        // console.log("RUNNING THE THING");
        let promise = new Promise(function(resolve, reject) {
            resolve(DemoAPI)
          })

        promise.then(x => console.log(x))
        // console.log(DemoAPI)
        // d3.json("demoAPI.json").then(d => console.log(Object.keys(d)))
    }
}