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

Method constructor

addition-rnn/index.js:34–47  ·  view source on GitHub ↗

* Constructor of CharacterTable. * @param chars A string that contains the characters that can appear * in the input.

(chars)

Source from the content-addressed store, hash-verified

32 * in the input.
33 */
34 constructor(chars) {
35 this.chars = chars;
36 this.charIndices = {};
37 this.indicesChar = {};
38 this.size = this.chars.length;
39 for (let i = 0; i < this.size; ++i) {
40 const char = this.chars[i];
41 if (this.charIndices[char] != null) {
42 throw new Error(`Duplicate character '${char}'`);
43 }
44 this.charIndices[this.chars[i]] = i;
45 this.indicesChar[i] = this.chars[i];
46 }
47 }
48
49 /**
50 * Convert a string into a one-hot encoded tensor.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected