How to use the @tensorflow/tfjs-node.squeeze function in @tensorflow/tfjs-node

To help you get started, we’ve selected a few @tensorflow/tfjs-node examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github loretoparisi / tensorflow-node-examples / lstm-text-generator / index.js View on Github external
// Encode the current input sequence as a one-hot Tensor.
        const inputBuffer =
            new tf.TensorBuffer([1, sampleLen, charSetSize]);

        // Make the one-hot encoding of the seeding sentence.
        for (let i = 0; i < sampleLen; ++i) {
            inputBuffer.set(1, 0, i, sentenceIndices[i]);
        }
        const input = inputBuffer.toTensor();

        // Call model.predict() to get the probability values of the next
        // character.
        const output = model.predict(input);

        // Sample randomly based on the probability values.
        const winnerIndex = sample(tf.squeeze(output), temperature);
        const winnerChar = textData.getFromCharSet(winnerIndex);
        if (onTextGenerationChar != null) {
            onTextGenerationChar(winnerChar);
        }

        generated += winnerChar;
        sentenceIndices = sentenceIndices.slice(1);
        sentenceIndices.push(winnerIndex);

        // Memory cleanups.
        input.dispose();
        output.dispose();
    }
    return generated;
}
github bobiblazeski / js-gym / dist / agents.node.js View on Github external
const action = tf.tidy(() => {
      let action = tf.squeeze(this.actor.predict(tf.tensor([state])));
      if (train) {
        const noise = softmax(this.noise.sample());        
        action = action.mul(1-this.epsilon).add(tf.mul(noise, this.epsilon));
      }
      return action;
    });
    const data = await action.data();