| 85 | } |
| 86 | |
| 87 | function parseArguments() { |
| 88 | const parser = new ArgumentParser( |
| 89 | {description: 'Train a model for IMDB sentiment analysis'}); |
| 90 | parser.addArgument('modelType', { |
| 91 | type: 'string', |
| 92 | optionStrings: [ |
| 93 | 'multihot', 'flatten', 'cnn', 'simpleRNN', 'lstm', 'bidirectionalLSTM'], |
| 94 | help: 'Model type' |
| 95 | }); |
| 96 | parser.addArgument('--numWords', { |
| 97 | type: 'int', |
| 98 | defaultValue: 10000, |
| 99 | help: 'Number of words in the vocabulary' |
| 100 | }); |
| 101 | parser.addArgument('--maxLen', { |
| 102 | type: 'int', |
| 103 | defaultValue: 100, |
| 104 | help: 'Maximum sentence length in number of words. ' + |
| 105 | 'Shorter sentences will be padded; longers ones will be truncated.' |
| 106 | }); |
| 107 | parser.addArgument('--embeddingSize', { |
| 108 | type: 'int', |
| 109 | defaultValue: 128, |
| 110 | help: 'Number of word embedding dimensions' |
| 111 | }); |
| 112 | parser.addArgument( |
| 113 | '--gpu', {action: 'storeTrue', help: 'Use GPU for training'}); |
| 114 | parser.addArgument('--optimizer', { |
| 115 | type: 'string', |
| 116 | defaultValue: 'adam', |
| 117 | help: 'Optimizer to be used for model training' |
| 118 | }); |
| 119 | parser.addArgument( |
| 120 | '--epochs', |
| 121 | {type: 'int', defaultValue: 10, help: 'Number of training epochs'}); |
| 122 | parser.addArgument( |
| 123 | '--batchSize', |
| 124 | {type: 'int', defaultValue: 128, help: 'Batch size for training'}); |
| 125 | parser.addArgument('--validationSplit', { |
| 126 | type: 'float', |
| 127 | defaultValue: 0.2, |
| 128 | help: 'Validation split for training' |
| 129 | }); |
| 130 | parser.addArgument('--modelSaveDir', { |
| 131 | type: 'string', |
| 132 | defaultValue: 'dist/resources', |
| 133 | help: 'Optional path for model saving.' |
| 134 | }); |
| 135 | parser.addArgument('--embeddingFilesPrefix', { |
| 136 | type: 'string', |
| 137 | defaultValue: '', |
| 138 | help: 'Optional path prefix for saving embedding files that ' + |
| 139 | 'can be loaded in the Embedding Projector ' + |
| 140 | '(https://projector.tensorflow.org/). For example, if this flag ' + |
| 141 | 'is configured to the value /tmp/embed, then the embedding vectors ' + |
| 142 | 'file will be written to /tmp/embed_vectors.tsv and the labels ' + |
| 143 | 'file will be written to /tmp/embed_label.tsv' |
| 144 | }); |