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

Class TextData

lstm-text-generation/data.js:53–237  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

51 * models and obtaining the seed text for model-based text generation.
52 */
53export class TextData {
54 /**
55 * Constructor of TextData.
56 *
57 * @param {string} dataIdentifier An identifier for this instance of TextData.
58 * @param {string} textString The training text data.
59 * @param {number} sampleLen Length of each training example, i.e., the input
60 * sequence length expected by the LSTM model.
61 * @param {number} sampleStep How many characters to skip when going from one
62 * example of the training data (in `textString`) to the next.
63 */
64 constructor(dataIdentifier, textString, sampleLen, sampleStep) {
65 tf.util.assert(
66 sampleLen > 0,
67 `Expected sampleLen to be a positive integer, but got ${sampleLen}`);
68 tf.util.assert(
69 sampleStep > 0,
70 `Expected sampleStep to be a positive integer, but got ${sampleStep}`);
71
72 if (!dataIdentifier) {
73 throw new Error('Model identifier is not provided.');
74 }
75
76 this.dataIdentifier_ = dataIdentifier;
77
78 this.textString_ = textString;
79 this.textLen_ = textString.length;
80 this.sampleLen_ = sampleLen;
81 this.sampleStep_ = sampleStep;
82
83 this.getCharSet_();
84 this.convertAllTextToIndices_();
85 }
86
87 /**
88 * Get data identifier.
89 *
90 * @returns {string} The data identifier.
91 */
92 dataIdentifier() {
93 return this.dataIdentifier_;
94 }
95
96 /**
97 * Get length of the training text data.
98 *
99 * @returns {number} Length of training text data.
100 */
101 textLen() {
102 return this.textLen_;
103 }
104
105 /**
106 * Get the length of each training example.
107 */
108 sampleLen() {
109 return this.sampleLen_;
110 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected