Skip to content
Snippets Groups Projects
Commit 36ddf619 authored by alexis.nasr's avatar alexis.nasr
Browse files

updated maca_trans_parser/src/context.h to accomodate for options specific to maca_trans_parser_nn

parent 9fca2984
No related branches found
No related tags found
No related merge requests found
......@@ -8,6 +8,10 @@ SET(CMAKE_C_COMPILER g++)
SET(CMAKE_CXX_COMPILER g++)
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Ofast -DUSE_CBLAS")
SET( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lm -lopenblas" )
if (${CMAKE_C_COMPILER_VERSION} VERSION_LESS 5.3)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11")
# better, but needs CMake >= 3.0
......
......@@ -24,6 +24,14 @@
#define DEFAULT_VOCABS_TAGPARSER_FILENAME "maca_trans_tagparser.vocab"
#define DEFAULT_MODEL_TAGPARSER_FILENAME "maca_trans_tagparser.model"
#define DEFAULT_MULTI_COL_DESC_PARSER_NN_FILENAME "maca_trans_parser_nn.mcd"
#define DEFAULT_FEATURES_MODEL_PARSER_NN_FILENAME "maca_trans_parser_nn.fm"
#define DEFAULT_VOCABS_PARSER_NN_FILENAME "maca_trans_parser_nn.vocab"
#define DEFAULT_MODEL_PARSER_NN_FILENAME "maca_trans_parser_nn.weights"
#define DEFAULT_JSON_PARSER_NN_FILENAME "maca_trans_parser_nn.json"
#define DEFAULT_F2P_FILENAME "fP"
#define DEFAULT_FPLM_FILENAME "fplm"
......
......@@ -44,41 +44,40 @@ void maca_trans_parser_nn_check_options(context *ctx){
}
}
void set_linguistic_resources_filenames_parser(context *ctx)
{
char absolute_filename[500];
if(!ctx->perc_model_filename){
if(!ctx->dnn_model_filename){
strcpy(absolute_filename, ctx->maca_data_path);
strcat(absolute_filename, DEFAULT_MODEL_FILENAME);
ctx->perc_model_filename = strdup(absolute_filename);
strcat(absolute_filename, DEFAULT_MODEL_PARSER_NN_FILENAME);
ctx->dnn_model_filename = strdup(absolute_filename);
}
if(!ctx->vocabs_filename){
if(!ctx->json_filename){
strcpy(absolute_filename, ctx->maca_data_path);
strcat(absolute_filename, DEFAULT_VOCABS_FILENAME);
ctx->vocabs_filename = strdup(absolute_filename);
strcat(absolute_filename, DEFAULT_JSON_PARSER_NN_FILENAME);
ctx->json_filename = strdup(absolute_filename);
}
/* if(!ctx->mcd_filename){
if(!ctx->vocabs_filename){
strcpy(absolute_filename, ctx->maca_data_path);
strcat(absolute_filename, DEFAULT_MULTI_COL_DESC_FILENAME);
ctx->mcd_filename = strdup(absolute_filename);
}*/
strcat(absolute_filename, DEFAULT_VOCABS_PARSER_NN_FILENAME);
ctx->vocabs_filename = strdup(absolute_filename);
}
if(!ctx->features_model_filename){
strcpy(absolute_filename, ctx->maca_data_path);
strcat(absolute_filename, DEFAULT_FEATURES_MODEL_FILENAME);
strcat(absolute_filename, DEFAULT_FEATURES_MODEL_PARSER_NN_FILENAME);
ctx->features_model_filename = strdup(absolute_filename);
}
if(ctx->verbose){
fprintf(stderr, "perc_model_filename = %s\n", ctx->perc_model_filename);
fprintf(stderr, "vocabs_filename = %s\n", ctx->vocabs_filename);
fprintf(stderr, "mcd_filename = %s\n", ctx->mcd_filename);
fprintf(stderr, "perc_features_model_filename = %s\n", ctx->features_model_filename);
fprintf(stderr, "dnn_model = %s\n", ctx->dnn_model_filename);
fprintf(stderr, "json = %s\n", ctx->json_filename);
fprintf(stderr, "vocabs %s\n", ctx->vocabs_filename);
fprintf(stderr, "mcd = %s\n", ctx->mcd_filename);
fprintf(stderr, "features_model = %s\n", ctx->features_model_filename);
}
}
......@@ -184,16 +183,15 @@ std::vector<Matrix<float> > config2keras_vec(feat_model *fm, config *c)
void simple_decoder_parser_arc_eager_nn(context *ctx, Model &model)
{
FILE *f = (ctx->input_filename)? myfopen(ctx->input_filename, "r") : stdin;
feature_table *ft = feature_table_load(ctx->perc_model_filename, ctx->verbose);
// feature_table *ft = feature_table_load(ctx->perc_model_filename, ctx->verbose);
int root_label;
int mvt_code;
int mvt_type;
int mvt_label;
feat_vec *fv = feat_vec_new(10);
config *c = NULL;
int result;
std::vector<Matrix<float> > keras_vec;
int sentence_nb = 0;
root_label = dico_string2int(ctx->dico_labels, ctx->root_label);
if(root_label == -1) root_label = 0;
......@@ -223,11 +221,7 @@ void simple_decoder_parser_arc_eager_nn(context *ctx, Model &model)
Matrix<float> argmax = y[0].argmax();
mvt_code = argmax.at(0, 0);
// printf("mvt code = %d\n", mvt_code);
/* config2feat_vec_cff(ctx->features_model, c, ctx->d_perceptron_features, fv, LOOKUP_MODE); */
/* mvt_code = feature_table_argmax(fv, ft, &max); */
// fprintf(stderr,"mvt code = %d\n", mvt_code);
mvt_type = movement_parser_type(mvt_code);
mvt_label = movement_parser_label(mvt_code);
......@@ -247,6 +241,9 @@ void simple_decoder_parser_arc_eager_nn(context *ctx, Model &model)
break;
case MVT_PARSER_EOS:
result = movement_parser_eos(c);
sentence_nb++;
if((sentence_nb % 2) == 0)
fprintf(stderr, "\rsentence %d", sentence_nb);
break;
case MVT_PARSER_SHIFT:
result = movement_parser_shift(c);
......@@ -262,14 +259,12 @@ void simple_decoder_parser_arc_eager_nn(context *ctx, Model &model)
}
}
}
}
if(!ctx->trace_mode)
}
fprintf(stderr, "\n");
print_word_buffer(c, ctx->dico_labels, ctx->mcd_struct);
config_free(c);
feat_vec_free(fv);
feature_table_free(ft);
if(ctx->input_filename)
fclose(f);
}
......@@ -297,10 +292,9 @@ int main(int argc, char *argv[])
fprintf(stderr, "cannot find label names\n");
return 1;
}
simple_decoder_parser_arc_eager_nn(ctx, model);
context_free(ctx);
// context_free(ctx);
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment