Skip to content

Commit a398d4a

Browse files
committed
Adding -c flag to usage help
1 parent da07da4 commit a398d4a

File tree

1 file changed

+36
-33
lines changed

1 file changed

+36
-33
lines changed

main.c

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ set_t set;
2525

2626
static int write_output_directly_bytes = 0;
2727
static char *read_network = NULL;
28+
static char *seed = NULL;
2829

2930
void store_the_net_layers(int signo)
3031
{
@@ -66,6 +67,7 @@ void usage(char *argv[]) {
6667
printf(" -L : Number of layers, may not exceed %d\r\n", LSTM_MAX_LAYERS);
6768
printf(" -N : Number of neurons in every layer\r\n");
6869
printf(" -vr : Verbosity level. Set to zero and only the loss function after and not during training will be printed.\n");
70+
printf(" -c : Don't train, only generate output. Seed given by the value. If -r is used, datafile is not considered.\r\n");
6971
printf("\r\n");
7072
printf("Check std_conf.h to see what default values are used, these are set during compilation.\r\n");
7173
printf("\r\n");
@@ -127,6 +129,8 @@ void parse_input_args(int argc, char** argv)
127129
}
128130
} else if ( !strcmp(argv[a], "-vr") ) {
129131
params.print_progress = !!atoi(argv[a+1]);
132+
} else if ( !strcmp(argv[a], "-c") ) {
133+
seed = argv[a+1];
130134
}
131135

132136
a += 2;
@@ -243,42 +247,47 @@ int main(int argc, char *argv[])
243247

244248
lstm_load(read_network, &set, &params, &model_layers);
245249

246-
FRead = set_get_features(&set);
250+
if ( seed == NULL ) {
247251

248-
// Read from datafile, see if new features appear
252+
FRead = set_get_features(&set);
249253

250-
fp = fopen(argv[1], "r");
251-
if ( fp == NULL ) {
252-
printf("Could not open file: %s\n", argv[1]);
253-
return -1;
254-
}
254+
// Read from datafile, see if new features appear
255255

256-
while ( ( c = fgetc(fp) ) != EOF ) {
257-
set_insert_symbol(&set, (char)c );
258-
}
256+
fp = fopen(argv[1], "r");
257+
if ( fp == NULL ) {
258+
printf("Could not open file: %s\n", argv[1]);
259+
return -1;
260+
}
261+
262+
while ( ( c = fgetc(fp) ) != EOF ) {
263+
set_insert_symbol(&set, (char)c );
264+
}
259265

260-
fclose(fp);
266+
fclose(fp);
261267

262-
FReadNewAfterDataFile = set_get_features(&set);
268+
FReadNewAfterDataFile = set_get_features(&set);
263269

264-
if ( FReadNewAfterDataFile > FRead ) {
265-
// New features appeared. Must change
266-
// first and last layer.
267-
printf("New features detected in datafile.\nLoaded network worked with %d features\
270+
if ( FReadNewAfterDataFile > FRead ) {
271+
// New features appeared. Must change
272+
// first and last layer.
273+
printf("New features detected in datafile.\nLoaded network worked with %d features\
268274
, now there is %d features in total.\n\
269275
Reallocating space in network input and output layer to accommodate this new feature set.\n",
270-
FRead, FReadNewAfterDataFile);
276+
FRead, FReadNewAfterDataFile);
271277

272-
lstm_reinit_model(
273-
model_layers,
274-
params.layers,
275-
FRead,
276-
FReadNewAfterDataFile
277-
);
278+
lstm_reinit_model(
279+
model_layers,
280+
params.layers,
281+
FRead,
282+
FReadNewAfterDataFile
283+
);
284+
285+
}
278286

279287
}
280288

281-
printf("Loaded the net: %s\n", read_network);
289+
if ( seed == NULL )
290+
printf("Loaded the net: %s\n", read_network);
282291
} else {
283292
/* Allocating space for a new model */
284293
model_layers = calloc(params.layers, sizeof(lstm_model_t*));
@@ -328,15 +337,9 @@ Reallocating space in network input and output layer to accommodate this new fea
328337
usage(argv);
329338
}
330339

331-
if ( argc >= 6 && !strcmp(argv[4], "-c") ) {
332-
333-
do {
334-
clean = strchr(argv[5], '_');
335-
if ( clean != NULL )
336-
*clean = ' ';
337-
} while ( clean != NULL );
338-
339-
lstm_output_string_from_string(model_layers, &set, argv[5], params.layers, 128);
340+
if ( seed != NULL ) {
341+
// output directly
342+
lstm_output_string_from_string(model_layers, &set, seed, params.layers, 256);
340343

341344
} else {
342345
double loss;

0 commit comments

Comments
 (0)