Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function genBasic(args) {
const tpClient = new Tp.FileClient({
locale: args.locale,
thingpedia: './thingpedia.tt',
entities: './entities.json',
dataset: './dataset.tt'
});
const schemas = new ThingTalk.SchemaRetriever(tpClient, null, true);
const rng = seedrandom.alea('almond is awesome');
const options = {
thingpediaClient: tpClient,
schemaRetriever: schemas,
templateFile: 'index.genie',
rng: rng,
locale: args.locale,
flags: args.flags || {},
maxDepth: args.maxdepth,
targetPruningSize: args.target_pruning_size,
debug: false, // no debugging, ever, because debugging also goes to stdout
};
const generator = new Genie.BasicSentenceGenerator(options);
function randomUniform (shape, dtype, seed) {
// This is how randomNormal handles the seed input
// SEE: https://github.com/tensorflow/tfjs-core/blob/v0.12.0/src/ops/rand.ts
const seedValue = seed || Math.random();
const random = seedrandom.alea(seedValue.toString());
return tf.rand(shape, random, dtype);
}
});
parser.addArgument('--maxdepth', {
type: Number,
defaultValue: 6,
help: 'Maximum depth of synthetic sentence generation',
});
parser.addArgument('--turking', {
nargs: 0,
action: 'storeTrue',
help: 'Restrict grammar rules to MTurk-friendly ones.',
defaultValue: false
});
const args = parser.parseArgs();
const options = {
rng: seedrandom.alea('almond is awesome'),
language: 'en',
targetLanguage: 'thingtalk',
thingpediaClient: _tpClient,
turkingMode: args.turking,
maxDepth: args.maxdepth,
debug: true
};
const generator = new SentenceGenerator(options);
const transform = new stream.Transform({
writableObjectMode: true,
transform(ex, encoding, callback) {
callback(null, ex.id + '\t' + ex.utterance + '\t' + ex.target_code + '\n');
},
async function main() {
const options = {
rng: seedrandom.alea('almond is awesome'),
language: 'en',
targetLanguage: 'thingtalk',
thingpediaClient: _tpClient,
turkingMode: false,
maxDepth: 7,
debug: true
};
const generator = new SentenceGenerator(options);
const writer = new stream.Writable({
objectMode: true,
write(ex, encoding, callback) {
Promise.resolve().then(() => {
return processOne(ex.id, ex.utterance, ex.target_code);
}).then(() => {
async function main() {
const options = {
rng: seedrandom.alea('almond is awesome'),
locale: 'en-US',
templateFile: path.resolve(path.dirname(module.filename), '../languages/en/thingtalk.genie'),
thingpediaClient: _tpClient,
flags: {
turking: false,
remote_commands: true,
policies: true,
aggregation: true,
bookkeeping: true,
triple_commands: true,
undefined_filter: true,
timer: true,
projection: true,
projection_with_filter: true
},
targetPruningSize: 10000,
export function restoreRng(state: any): GeneratorInterface {
return new SeedrandomGenerator(
seedrandom.alea('', {
state
})
);
}
constructor(
mean: number, stdDeviation: number, dtype?: keyof RandNormalDataTypes,
truncated?: boolean, seed?: number) {
this.mean = mean;
this.stdDev = stdDeviation;
this.dtype = dtype;
this.nextVal = NaN;
this.truncated = truncated;
if (this.truncated) {
this.upper = this.mean + this.stdDev * 2;
this.lower = this.mean - this.stdDev * 2;
}
const seedValue = seed ? seed : Math.random();
this.random = seedrandom.alea(seedValue.toString());
}
contexts = await readAllLines([fs.createReadStream(args.context_source)])
.pipe(new DatasetParser({ preserveId: true }))
.pipe(new ContextSourceLoader())
.read();
}
const constants = await parseConstantFile(args.locale, args.constants);
const [functionBlackList, deviceBlackList, functionHighValueList, functionWhiteList, deviceWhiteList] =
await parseSamplingControlFile(args.sampling_control);
const tpClient = new Tp.FileClient(args.locale, args.thingpedia, null);
const schemaRetriever = new ThingTalk.SchemaRetriever(tpClient, null, !args.debug);
const options = {
rng: seedrandom.alea(args.random_seed),
locale: args.locale,
samplingStrategy: args.sampling_strategy,
functionBlackList,
deviceBlackList,
functionHighValueList,
functionWhiteList,
deviceWhiteList,
contexts,
compoundOnly: !!args.compound_only,
debug: args.debug
};
readAllLines(args.input_file)
.pipe(new DatasetParser({ contextual: args.contextual, preserveId: true }))
const promises = [];
const train = new DatasetStringifier();
const eval_ = new DatasetStringifier();
promises.push(StreamUtils.waitFinish(train.pipe(args.train)));
promises.push(StreamUtils.waitFinish(eval_.pipe(args.eval)));
let test = null;
if (args.test) {
test = new DatasetStringifier();
promises.push(StreamUtils.waitFinish(test.pipe(args.test)));
}
readAllLines(args.input_file)
.pipe(new DatasetParser())
.pipe(new DatasetSplitter({
rng: seedrandom.alea(args.random_seed),
locale: args.locale,
debug: args.debug,
train,
eval: eval_,
test,
evalProbability: args.eval_probability,
forDevices: args.forDevices,
splitStrategy: args.split_strategy,
}));
return Promise.all(promises);
}
};
module.exports = function worker(args, shard) {
const tpClient = new Tp.FileClient(args);
const options = {
rng: seedrandom.alea(args.random_seed + ':' + shard),
idPrefix: shard + ':',
locale: args.locale,
flags: args.flags || {},
templateFile: args.template,
thingpediaClient: tpClient,
maxDepth: args.maxdepth,
targetPruningSize: args.target_pruning_size,
debug: args.debug,
};
return new ContextualSentenceGenerator(options);
};