Repository navigation
Expand file tree
/
Copy pathtest.js
More file actions
127 lines (90 loc) · 2.42 KB
/
Copy pathtest.js
File metadata and controls
127 lines (90 loc) · 2.42 KB
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
const { dirname } = require('path');
const __root = dirname(require.main.filename);
const {
Language: LanguageModel,
Image: ImageModel
} = require('./models');
const DefaultDataset = require(`${__root}/training/datasets/Default`);
const DefaultImageDataset = require(`${__root}/training/datasets/images/Default`);
/**
* Language model tests
*/
const withDataset = async (dataset, query) => {
const agent = await LanguageModel({
dataset
});
console.log(`query: ${query}`);
// Log next token prediction
console.log(
'getTokenPrediction >>',
`query: ${query}`,
agent.getTokenPrediction(query)
);
};
const withBootstrap = async query => {
// Bootstrap with a default dataset
const agent = await LanguageModel({
bootstrap: true
});
// Log completions
console.log(
'getCompletions >>',
`query: ${query}`,
agent.getCompletions(query)
);
};
const withFiles = async (files, query) => {
const agent = await LanguageModel({
files
});
// Log completion
console.log(
'complete >>',
`query: ${query}`,
agent.complete(query)
);
};
const runTests = async () => {
// Unit: Run different queries in isolation
// with different datasets
await withDataset(DefaultDataset, 'luckily');
await withDataset(DefaultDataset, 'with all');
await withDataset(DefaultDataset, 'grass');
await withDataset(DefaultDataset, 'unless');
// e2e: Run training on user provided files
await withFiles(['the-phantom-of-the-opera'], 'eloquence');
// e2e: Run training from bootstrap then query
await withBootstrap('people');
};
/**
* Image model tests
*/
const withImageDataset = async (dataset, seedPixel) => {
const agent = await ImageModel({
dataset
});
console.log(`pixel: ${seedPixel}`)
// Log next pixel prediction
console.log(
'getPixelPrediction >>',
`pixel: ${seedPixel}`,
agent.getPixelPrediction(seedPixel)
);
// Log sequence generation
console.log(
'getGradientCompletion >>',
`pixel: ${seedPixel}`,
agent.render(agent.generate(seedPixel))
);
};
const runImageTests = async () => {
// Unit: Predict a gradient from common starter colors
await withImageDataset(DefaultImageDataset, '#000000');
await withImageDataset(DefaultImageDataset, '#ffffff');
await withImageDataset(DefaultImageDataset, '#c6e3ff');
console.log('Done.');
};
(async () => {
await runTests();
await runImageTests();
})();