-
Notifications
You must be signed in to change notification settings - Fork 909
/
Copy pathindex_test.js
60 lines (49 loc) · 1.73 KB
/
index_test.js
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
// Copyright (c) 2018 ml5
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
const { charRNN } = ml5;
const RNN_MODEL_URL = 'https://raw.githubusercontent.com/ml5js/ml5-data-and-models/master/models/lstm/woolf';
const RNN_MODEL_DEFAULTS = {
cellsAmount: 2,
vocabSize: 223
};
const RNN_DEFAULTS = {
seed: 'a',
length: 20,
temperature: 0.5,
stateful: false
}
const RNN_OPTIONS = {
seed: 'the meaning of pizza is: ',
length: 10,
temperature: 0.7
}
describe('charRnn', () => {
let rnn;
beforeAll(async () => {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 20000; //set extra long interval due to issues with CharRNN generation time
rnn = await charRNN(RNN_MODEL_URL, undefined);
});
// it('loads the model with all the defaults', async () => {
// expect(rnn.cellsAmount).toBe(RNN_MODEL_DEFAULTS.cellsAmount);
// expect(rnn.vocabSize).toBe(RNN_MODEL_DEFAULTS.vocabSize);
// });
describe('generate', () => {
it('instantiates an rnn with all the defaults', async () => {
expect(rnn.ready).toBeTruthy();
expect(rnn.defaults.seed).toBe(RNN_DEFAULTS.seed);
expect(rnn.defaults.length).toBe(RNN_DEFAULTS.length);
expect(rnn.defaults.temperature).toBe(RNN_DEFAULTS.temperature);
expect(rnn.defaults.stateful).toBe(RNN_DEFAULTS.stateful);
});
it('Should generate content that follows default options if given an empty object', async() => {
const result = await rnn.generate({});
expect(result.sample.length).toBe(20);
});
it('generates content that follows the set options', async() => {
const result = await rnn.generate(RNN_OPTIONS);
expect(result.sample.length).toBe(RNN_OPTIONS.length);
});
});
});