Skip to content

Commit

Permalink
Merge branch 'main' into iislucas-2024-07-24-webcolab
Browse files Browse the repository at this point in the history
  • Loading branch information
iislucas committed Aug 22, 2024
2 parents a356405 + 4d656ac commit 5e76235
Show file tree
Hide file tree
Showing 9 changed files with 1,741 additions and 1,895 deletions.
3,070 changes: 1,194 additions & 1,876 deletions animated-transformer/package-lock.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion animated-transformer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
"@angular-devkit/build-angular": "^18.0.1",
"@angular/cli": "^18.0.1",
"@angular/compiler-cli": "^18.0.1",
"@tensorflow/tfjs-node": "^4.20.0",
"@tsconfig/node18": "^18.2.1",
"@types/d3": "^7.4.0",
"@types/jasmine": "~4.3.0",
"@types/underscore": "^1.11.4",
Expand All @@ -55,4 +57,4 @@
"karma-jasmine-html-reporter": "~2.0.0",
"typescript": "~5.5.0"
}
}
}
134 changes: 134 additions & 0 deletions animated-transformer/src/lib/seqtasks/generated_tiny_worlds.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/* Copyright 2023 Google LLC. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

import { getUniGramTinyWorldConfig } from './generated_tiny_worlds';
import { TinyWorldTask } from './tiny_worlds';

describe('generated_tiny_worlds', () => {
beforeEach(() => {});

it('test_getUniGramTinyWorldConfig', () => {
let seed = 0;
let nIdentity = 10;
let uniGramTinyWorldConfig = getUniGramTinyWorldConfig(nIdentity, seed);

console.log(JSON.stringify(uniGramTinyWorldConfig));
uniGramTinyWorldConfig.maxInputLen = 100;
let tinyWorld = new TinyWorldTask(uniGramTinyWorldConfig);
const [example] = tinyWorld.exampleIter.takeOutN(1);
expect(example.input).toEqual([
'is',
' ',
'_a',
':',
'i7',
', ',
'is',
' ',
'_b',
':',
'i6',
', ',
'is',
' ',
'_c',
':',
'i9',
', ',
'is',
' ',
'_d',
':',
'i7',
', ',
'is',
' ',
'_e',
':',
'i4',
', ',
'is',
' ',
'_f',
':',
'i6',
', ',
'is',
' ',
'_g',
':',
'i4',
', ',
'is',
' ',
'_h',
':',
'i7',
', ',
'is',
' ',
'_i',
':',
'i9',
', ',
'is',
' ',
'_j',
':',
'i6',
', ',
'is',
' ',
'_k',
':',
'i4',
', ',
'is',
' ',
'_l',
':',
'i9',
', ',
'is',
' ',
'_m',
':',
'i8',
', ',
'is',
' ',
'_n',
':',
'i5',
', ',
'is',
' ',
'_o',
':',
'i4',
', ',
'is',
' ',
'_p',
':',
'i6',
', ',
'is',
' ',
'_q',
':',
]);
});
});
65 changes: 65 additions & 0 deletions animated-transformer/src/lib/seqtasks/generated_tiny_worlds.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/* Copyright 2023 Google LLC. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

/* Generated Tiny Worlds */

import * as tf from '@tensorflow/tfjs';
import { TinyWorldTaskConfig, TinyWorldTask } from './tiny_worlds';
import { makeRandomStream } from '../state-iter/random';

export const defaultNGramTinyWorldConfig: TinyWorldTaskConfig = {
name: 'Generated N-Gram Tiny World',
seed: 42,
maxInputLen: 10,
maxOutputLen: 20,
typeHierarchy: {},
relationKinds: {
is: [''],
},
baseContext: [],
rules: [],
maxEntityLimit: 6,
};

export function getUniGramTinyWorldConfig(
nIdentity: number,
seed: number = 0
) {
function getIdentity(index: number) {
return 'i' + String(index);
}

let randomStream = makeRandomStream(seed);
const typeHierarchy = {
t0: [...Array(nIdentity).keys()].map(getIdentity),
};

let rules: string[] = [];

for (let indexIdentity = 0; indexIdentity < nIdentity; indexIdentity += 1) {
let value = randomStream.uniformIntInRange(0, 100);
let rule = `S(is ?x:${getIdentity(indexIdentity)}) += ${value}`;
rules.push(rule);
}

const resultConfig: TinyWorldTaskConfig = {
...defaultNGramTinyWorldConfig,
name: 'Generated Uni-Gram Tiny World',
typeHierarchy: typeHierarchy,
rules: rules,
};

return resultConfig;
}
Loading

0 comments on commit 5e76235

Please sign in to comment.