diff --git a/maca_trans_parser/src/simple_decoder_parser_arc_eager.c b/maca_trans_parser/src/simple_decoder_parser_arc_eager.c index bd7eb7062aea36c8da7f3d56ac9c0cb9fc4f8fc9..23a92b3b39a2e2dc4f58756657e3791da7762fce 100644 --- a/maca_trans_parser/src/simple_decoder_parser_arc_eager.c +++ b/maca_trans_parser/src/simple_decoder_parser_arc_eager.c @@ -3,8 +3,10 @@ #include<string.h> #include<unistd.h> #include<getopt.h> -#include"context.h" #include<math.h> +#include<time.h> +#include<random.h> +#include"context.h" #include"movement_parser_arc_eager.h" #include"feat_fct.h" #include"config2feat_vec.h" @@ -155,7 +157,11 @@ void simple_decoder_parser_arc_eager(context *ctx) double currentSumExp; double ScoreTranslation; int FlagNotInitExp; - double ProbaDivider = 10; // TO SETUP + double ProbaDivider = 100; // TO SETUP + double randomFloat; + + srand(mix(clock(), time(NULL), getpid());); + word* word_scored; @@ -250,33 +256,42 @@ void simple_decoder_parser_arc_eager(context *ctx) printf("%f\n", max1 - max2); } - if(ctx->partial_mode){ - vcode *vcode_array = feature_table_get_vcode_array(fv, ft); + currentSumExp = 0.; + randomFloat = (double) rand()/(double)RAND_MAX; + + printf("< %f > is our random number. \n",randomFloat); + + // if(ctx->partial_mode){ // NOT YET COMPATIBLE + vcode *vcode_array = feature_table_get_vcode_array(fv, ft); mvt_code = 0; - for(int i=0; i < ft->classes_nb; i++){ - int b1 = respect_standard_constraint(c, movement_parser_type(vcode_array[i].class_code), movement_parser_label(vcode_array[i].class_code)); - int b2 = respect_stack_constraint(ctx->partial_mode, c, movement_parser_type(vcode_array[i].class_code), movement_parser_label(vcode_array[i].class_code)); - int b3 = respect_buffer_constraint(ctx->partial_mode, c, movement_parser_type(vcode_array[i].class_code), movement_parser_label(vcode_array[i].class_code)); + for(int i=0; i < ft->classes_nb; i++){ + int b1 = respect_standard_constraint(c, movement_parser_type(vcode_array[i].class_code), movement_parser_label(vcode_array[i].class_code)); + int b2 = respect_stack_constraint(ctx->partial_mode, c, movement_parser_type(vcode_array[i].class_code), movement_parser_label(vcode_array[i].class_code)); + int b3 = respect_buffer_constraint(ctx->partial_mode, c, movement_parser_type(vcode_array[i].class_code), movement_parser_label(vcode_array[i].class_code)); - if(b1 && b2 && b3){ - mvt_code = vcode_array[i].class_code; - break; - } - } - free(vcode_array); - } + if(b1 && b2 && b3){ + currentSumExp += exp(vcode_array[i].score/ProbaDivider - ScoreTranslation); + if(currentSumExp/sumExp >= randomFloat){ + printf("The %d th move has been selected by the probabilistic parser.\n",i); + mvt_code = vcode_array[i].class_code; + break; + } + } + } + free(vcode_array); + // } mvt_type = movement_parser_type(mvt_code); mvt_label = movement_parser_label(mvt_code); if((mvt_type == MVT_PARSER_EOS) && (word_get_sent_seg(stack_top(config_get_stack(c))) == 0)){ - if(ctx->verbose) - fprintf(stderr, "the classifier did predict EOS but this is not the case\n"); - feature_table_argmax_1_2(fv, ft, &argmax1, &max1, &argmax2, &max2); - mvt_code = argmax2; - mvt_type = movement_parser_type(mvt_code); - mvt_label = movement_parser_label(mvt_code); + if(ctx->verbose) + fprintf(stderr, "the classifier did predict EOS but this is not the case\n"); + feature_table_argmax_1_2(fv, ft, &argmax1, &max1, &argmax2, &max2); + mvt_code = argmax2; + mvt_type = movement_parser_type(mvt_code); + mvt_label = movement_parser_label(mvt_code); }