MCPcopy Create free account
hub / github.com/tensorflow/tfjs-examples / dateTuplesToTensor

Function dateTuplesToTensor

date-conversion-attention/train.js:75–102  ·  view source on GitHub ↗
(dateTuples)

Source from the content-addressed store, hash-verified

73 `${dateTuples.length - numTrain - numVal}`);
74
75 function dateTuplesToTensor(dateTuples) {
76 return tf.tidy(() => {
77 const inputs =
78 dateFormat.INPUT_FNS.map(fn => dateTuples.map(tuple => fn(tuple)));
79 const inputStrings = [];
80 inputs.forEach(inputs => inputStrings.push(...inputs));
81 const encoderInput =
82 dateFormat.encodeInputDateStrings(inputStrings);
83 const trainTargetStrings = dateTuples.map(
84 tuple => dateFormat.dateTupleToYYYYDashMMDashDD(tuple));
85 let decoderInput =
86 dateFormat.encodeOutputDateStrings(trainTargetStrings)
87 .asType('float32');
88 // One-step time shift: The decoder input is shifted to the left by
89 // one time step with respect to the encoder input. This accounts for
90 // the step-by-step decoding that happens during inference time.
91 decoderInput = tf.concat([
92 tf.ones([decoderInput.shape[0], 1]).mul(dateFormat.START_CODE),
93 decoderInput.slice(
94 [0, 0], [decoderInput.shape[0], decoderInput.shape[1] - 1])
95 ], 1).tile([dateFormat.INPUT_FNS.length, 1]);
96 const decoderOutput = tf.oneHot(
97 dateFormat.encodeOutputDateStrings(trainTargetStrings),
98 dateFormat.OUTPUT_VOCAB.length).tile(
99 [dateFormat.INPUT_FNS.length, 1, 1]);
100 return {encoderInput, decoderInput, decoderOutput};
101 });
102 }
103
104 const {
105 encoderInput: trainEncoderInput,

Callers 1

generateDataForTrainingFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected