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

Function encodeInputDateStrings

date-conversion-attention/date_format.js:249–265  ·  view source on GitHub ↗
(dateStrings)

Source from the content-addressed store, hash-verified

247 * is the maximum possible input length of all valid input date-string formats.
248 */
249export function encodeInputDateStrings(dateStrings) {
250 const n = dateStrings.length;
251 const x = tf.buffer([n, INPUT_LENGTH], 'float32');
252 for (let i = 0; i < n; ++i) {
253 for (let j = 0; j < INPUT_LENGTH; ++j) {
254 if (j < dateStrings[i].length) {
255 const char = dateStrings[i][j];
256 const index = INPUT_VOCAB.indexOf(char);
257 if (index === -1) {
258 throw new Error(`Unknown char: ${char}`);
259 }
260 x.set(index, i, j);
261 }
262 }
263 }
264 return x.toTensor();
265}
266
267/**
268 * Encode a number of output date strings as a `tf.Tensor`.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected