Team Ai
Apppublic

exbert-project/exbert

sourceHugging Faceapache-2.0updated 3y agoView on Hugging Face
185likes
test.ts152 linesDownload Raw Back to ts
1// import { BertAPI } from './api/bertApi'2// import { DemoAPI } from './api/demoApi'3import {API} from './api/mainApi'4import * as d3 from 'd3'5import * as R from 'ramda'6import * as _ from 'lodash'7import * as nj from 'numjs'8import * as x_ from './etc/_Tools'9import * as tf from '@tensorflow/tfjs'10import {TokenDisplay, TokenWrapper, sideToLetter} from './data/TokenWrapper'11import {AttentionWrapper} from "./data/AttentionCapsule"12import {FaissSearchResultWrapper} from "./data/FaissSearchWrapper"13 14const api = new API()15 16 17/**18 * To learn about the behavior of the functions that I write, without writing a professional test suite19 * (cuz time constraints / I don't know how to do a testing suite well in Typescript)20 */21export class Tester {22    // static testTf() {23    //     const a = tf.randomUniform([3,3,4]);24    //     const b = a.gather([0, 1], 0);25    //     const a_out = a.arraySync();26    //     console.log(a_out);27    // }28 29    // static testAttWrapperConstructor() {30    //     api.getAttentions("Simple test one", "another test two").then(r => {31    //         const att = new AttentionWrapper(r);32    //         console.log(att.all);33    //     })34    // }35 36    // static testNjAray() {37    //     const a = nj.ones([1,7,12], 'int32')38    //     const b = a39    //     b.slice(null, 0, 11).assign(0, false)40    //     console.log(b.tolist());41    // }42 43    // static testFindIdx() {44    //     const bad_toks = ['[CLS]', '[SEP]']45    //     const left_text = ['[CLS]', 'this', 'is', 'sentence', '[SEP]', '[CLS]']46    //     // const bad_inds = _.findAllIndexes(left_text, (a) => _.includes(bad_toks, a))47    //     const bad_inds = x_.findAllIndexes(left_text, (a) => _.includes(bad_toks, a))48    //     console.log(bad_inds);49    // }50 51    // static testUpdateMaskedAttention(){52    //     const as = 'this is a long string that has some meaning'53    //     const bs = 'String part 2'54    //     const a = ['[CLS]', 'this', 'is', 'a', 'long', 'string', 'that', 'has', 'some', 'meaning', '[SEP]']55    //     const b = ['string', 'part', '2', '[SEP]']56    //     const maskA = [1, 7, 9]57    //     const maskB = [] // CAN'T BE EMPTY58 59    //     const api = new BertAPI()60 61    //     const val1 = new TokenDisplay(a, maskA)62    //     const val2 = new TokenDisplay(b, maskB)63 64    //     api.updateMaskedAttentions(val1, val2).then(65    //         (r) => {66    //             console.log(r.ab.left_text);67    //             console.log(r.ab.right_text);68    //         }69    //     )70    // }71 72    // static testOrderedInsert() {73    //     const a = [1, 3, 6, 8, 9]74    //     const a2 = [1, 6, 8, 22, 9]75    //     const a3 = []76    //     const val = 477    //     x_.orderedInsert_(a, val)78    //     console.log(a);79 80    //     x_.orderedInsert_(a2, val, true)81    //     console.log(a2);82 83    //     x_.orderedInsert_(a3, val)84    //     console.log(a3);85    // }86 87    // static testTokenDisplay() {88    //     const toksa = ['yes', 'my', 'good', 'sir']89    //     const toksb = ['hi', 'there']90    //     const masksa = []91    //     const masksb = []92    //     const td = new TokenDisplay(toksa, masksa)93    //     const td2 = new TokenDisplay(toksb, masksb)94    //     const twrap = new TokenWrapper(toksa, toksb, masksa, masksb)95 96    //     // console.log(twrap.a);97    //     // console.log(twrap.b);98    //     // console.log(twrap.all);99    //     // twrap.mask("a", 3)100 101    //     // console.log(twrap.a);102    //     // console.log(twrap.all);103    //     twrap.mask("all", 1)104    //     console.log(twrap.b);105    //     console.log(twrap.all);106    // }107 108    // static testFaissWrapper() {109    //     const q = x_.makeRandom(768);110    //     api.getNearestWozEmbeddings(q, 0, 10).then(111    //         r => {112    //             const fsw = new FaissSearchResultWrapper(r)113    //             console.log(fsw.toStringArr());114    //         }115    //     )116    // }117 118    // static testSideToLetter() {119    //     const side = "left"120    //     console.log( sideToLetter(side, "all"));121    //     console.log( sideToLetter(side, "ab"));122    //     console.log( sideToLetter(side, "ba"));123    //     console.log( sideToLetter(side, "bb"));124    //     console.log( sideToLetter(side, "aa"));125    //     console.log( sideToLetter("right", "aa"));126    //     console.log( sideToLetter("abc", "aa")); // no error thrown... But linting catches an issue127    // }128 129    // static testRandomArrayCreation() {130    //     console.log(x_.makeRandom(10));131    // }132 133    // static testFaissSearchResultsHist () {134    //     api.getNearestWozEmbeddings(x_.makeRandom(768), 0).then(val => {135    //         const fsw = new FaissSearchResultWrapper(val);136    //         console.log(fsw.getHistogram());137    //     })138 139    // }140 141    static testReadingJSON () {142        // console.log("RUNNING THE THING");143        let promise = new Promise(function(resolve, reject) {144            resolve(DemoAPI)145          })146 147        promise.then(x => console.log(x))148        // console.log(DemoAPI)149        // d3.json("demoAPI.json").then(d => console.log(Object.keys(d)))150    }151}152