1{
2 "$schema": "http://json-schema.org/draft-07/schema#",
3 "$id": "https://schema.omnius.com/json/narchi/1.0/schema.json",
4 "title": "Neural Network Module Architecture Schema",
5 "$ref": "#/definitions/architecture",
6 "definitions": {
7 "id": {
8 "type": "string",
9 "pattern": "^[A-Za-z_][0-9A-Za-z_]*$"
10 },
11 "description": {
12 "type": "string",
13 "minLength": 8,
14 "pattern": "^[^<>]+$"
15 },
16 "dims": {
17 "type": "array",
18 "minItems": 1,
19 "items": {
20 "oneOf": [
21 {
22 "type": "integer",
23 "minimum": 1
24 },
25 {
26 "type": "string",
27 "pattern": "^(<<variable:([-+/*0-9A-Za-z_]+)>>|<<auto>>)$"
28 }
29 ]
30 }
31 },
32 "dims_in": {
33 "type": "array",
34 "minItems": 1,
35 "items": {
36 "oneOf": [
37 {
38 "type": "integer",
39 "minimum": 1
40 },
41 {
42 "type": "string",
43 "pattern": "^(<<variable:([-+/*0-9A-Za-z_]+)>>|<<auto>>)$"
44 },
45 {
46 "type": "null"
47 }
48 ]
49 }
50 },
51 "shape": {
52 "type": "object",
53 "properties": {
54 "in": {
55 "$ref": "#/definitions/dims_in"
56 },
57 "out": {
58 "$ref": "#/definitions/dims"
59 }
60 },
61 "required": [
62 "in",
63 "out"
64 ],
65 "additionalProperties": false
66 },
67 "graph": {
68 "type": "array",
69 "minItems": 1,
70 "items": {
71 "type": "string",
72 "pattern": "^[A-Za-z_][0-9A-Za-z_]*( +-> +[A-Za-z_][0-9A-Za-z_]*)+$"
73 }
74 },
75 "block": {
76 "type": "object",
77 "properties": {
78 "_class": {
79 "$ref": "#/definitions/id"
80 },
81 "_name": {
82 "$ref": "#/definitions/id"
83 },
84 "_id": {
85 "$ref": "#/definitions/id"
86 },
87 "_id_share": {
88 "$ref": "#/definitions/id"
89 },
90 "_description": {
91 "$ref": "#/definitions/description"
92 },
93 "_shape": {
94 "$ref": "#/definitions/shape"
95 },
96 "_path": {
97 "$ref": "#/definitions/path"
98 },
99 "_ext_vars": {
100 "type": "object"
101 },
102 "blocks": {
103 "$ref": "#/definitions/blocks"
104 },
105 "input": {
106 "$ref": "#/definitions/id"
107 },
108 "output": {
109 "$ref": "#/definitions/id"
110 },
111 "graph": {
112 "$ref": "#/definitions/graph"
113 },
114 "dim": {
115 "type": "integer"
116 },
117 "reshape_spec": {
118 "$ref": "#/definitions/reshape"
119 },
120 "architecture": {
121 "$ref": "#/definitions/architecture"
122 }
123 },
124 "required": [
125 "_class"
126 ],
127 "allOf": [
128 {
129 "if": {
130 "properties": {
131 "_class": {
132 "enum": [
133 "Sequential",
134 "Group"
135 ]
136 }
137 }
138 },
139 "then": {
140 "required": [
141 "blocks"
142 ]
143 },
144 "else": {
145 "not": {
146 "required": [
147 "blocks"
148 ]
149 }
150 }
151 },
152 {
153 "if": {
154 "properties": {
155 "_class": {
156 "const": "Group"
157 }
158 }
159 },
160 "then": {
161 "required": [
162 "graph",
163 "input",
164 "output"
165 ]
166 },
167 "else": {
168 "not": {
169 "required": [
170 "graph",
171 "input",
172 "output"
173 ]
174 }
175 }
176 },
177 {
178 "if": {
179 "properties": {
180 "_class": {
181 "const": "Module"
182 }
183 }
184 },
185 "then": {
186 "required": [
187 "_path"
188 ]
189 },
190 "else": {
191 "not": {
192 "required": [
193 "_path",
194 "_ext_vars",
195 "architecture"
196 ]
197 }
198 }
199 },
200 {
201 "if": {
202 "properties": {
203 "_class": {
204 "const": "Sequential"
205 }
206 }
207 },
208 "else": {
209 "properties": {
210 "blocks": {
211 "items": {
212 "required": [
213 "_id"
214 ]
215 }
216 }
217 }
218 }
219 },
220 {
221 "if": {
222 "properties": {
223 "_class": {
224 "const": "Concatenate"
225 }
226 }
227 },
228 "then": {
229 "required": [
230 "dim"
231 ]
232 }
233 },
234 {
235 "if": {
236 "properties": {
237 "_class": {
238 "const": "Reshape"
239 }
240 }
241 },
242 "then": {
243 "required": [
244 "reshape_spec"
245 ]
246 },
247 "else": {
248 "not": {
249 "required": [
250 "reshape_spec"
251 ]
252 }
253 }
254 }
255 ]
256 },
257 "blocks": {
258 "type": "array",
259 "minItems": 1,
260 "items": {
261 "$ref": "#/definitions/block"
262 }
263 },
264 "path": {
265 "type": "string",
266 "pattern": ".+\\.jsonnet"
267 },
268 "inputs_outputs": {
269 "type": "array",
270 "minItems": 1,
271 "items": {
272 "type": "object",
273 "properties": {
274 "_id": {
275 "$ref": "#/definitions/id"
276 },
277 "_description": {
278 "$ref": "#/definitions/description"
279 },
280 "_shape": {
281 "$ref": "#/definitions/dims"
282 }
283 },
284 "required": [
285 "_id",
286 "_shape"
287 ],
288 "additionalProperties": false
289 }
290 },
291 "architecture": {
292 "type": "object",
293 "properties": {
294 "_id": {
295 "$ref": "#/definitions/id"
296 },
297 "_description": {
298 "$ref": "#/definitions/description"
299 },
300 "blocks": {
301 "$ref": "#/definitions/blocks"
302 },
303 "graph": {
304 "$ref": "#/definitions/graph"
305 },
306 "inputs": {
307 "$ref": "#/definitions/inputs_outputs"
308 },
309 "outputs": {
310 "$ref": "#/definitions/inputs_outputs"
311 }
312 },
313 "required": [
314 "_id",
315 "blocks",
316 "graph",
317 "inputs",
318 "outputs"
319 ],
320 "additionalProperties": false
321 },
322 "reshape": {
323 "oneOf": [
324 {
325 "const": "flatten"
326 },
327 {
328 "type": "array",
329 "minItems": 1,
330 "items": {
331 "oneOf": [
332 {
333 "$ref": "#/definitions/reshape_index"
334 },
335 {
336 "$ref": "#/definitions/reshape_flatten"
337 },
338 {
339 "$ref": "#/definitions/reshape_unflatten"
340 }
341 ]
342 }
343 }
344 ]
345 },
346 "reshape_index": {
347 "type": "integer",
348 "minimum": 0
349 },
350 "reshape_dims": {
351 "type": "array",
352 "minItems": 2,
353 "items": {
354 "oneOf": [
355 {
356 "type": "integer",
357 "minimum": 1
358 },
359 {
360 "type": "string",
361 "pattern": "^(<<variable:([-+/*0-9A-Za-z_]+)>>|<<auto>>)$"
362 }
363 ]
364 }
365 },
366 "reshape_flatten": {
367 "type": "array",
368 "minItems": 2,
369 "items": {
370 "$ref": "#/definitions/reshape_index"
371 }
372 },
373 "reshape_unflatten": {
374 "type": "object",
375 "minProperties": 1,
376 "maxProperties": 1,
377 "patternProperties": {
378 "^[0-9]+$": {
379 "$ref": "#/definitions/reshape_dims"
380 }
381 },
382 "additionalProperties": false
383 }
384 }
385}