Redhanuman's picture
Pocket Storyteller: 4.6 MB story model, browser demo, weights and training code
ebf8f81 verified
Raw History Blame Contribute Delete
876 Bytes
// Tell a story in the terminal.
// node tell.js "Once upon a time, there was a little fox named Pip"
// node tell.js "Lily found a tiny door" 1.0 (second number = imagination, default 0.8)
const fs = require("fs"), path = require("path");
const Storyteller = require(path.resolve(__dirname, "web/storyteller.js"));
const b = fs.readFileSync(path.resolve(__dirname, "web/storyteller.bin"));
const st = new Storyteller(b.buffer.slice(b.byteOffset, b.byteOffset + b.length));
const prompt = process.argv[2] || "Once upon a time", temperature = +process.argv[3] || 0.8;
st.reset(st.encode(prompt));
process.stdout.write(prompt);
const t0 = Date.now(); let n = 0;
for (; n < 600; n++) { const s = st.next({ temperature, topK: 40 }); if (s.done) break; process.stdout.write(s.text); }
console.log(`\n\n[${n} word-pieces in ${((Date.now() - t0) / 1000).toFixed(1)} s]`);