From 98375cb10ebccba973ef2db22a4bdf5fca341544 Mon Sep 17 00:00:00 2001 From: "robin.perrotin" <robin.perrotin@lif.univ-mrs.fr> Date: Mon, 13 Nov 2017 05:03:55 +0100 Subject: [PATCH] probabilistic parser --- .../src/simple_decoder_parser_arc_eager.c | 40 +++++++++++++++---- 1 file changed, 33 insertions(+), 7 deletions(-) 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 dc53362..83ba2b9 100644 --- a/maca_trans_parser/src/simple_decoder_parser_arc_eager.c +++ b/maca_trans_parser/src/simple_decoder_parser_arc_eager.c @@ -150,7 +150,11 @@ void simple_decoder_parser_arc_eager(context *ctx) float max1, max2; int index; float score; - + + double sumExp = 0.; + double currentSumExp = 0.; + double ScoreTranslation = -150.; + word* word_scored; root_label = dico_string2int(ctx->dico_labels, ctx->root_label); @@ -182,7 +186,25 @@ void simple_decoder_parser_arc_eager(context *ctx) if(ctx->debug_mode){ vcode *vcode_array = feature_table_get_vcode_array(fv, ft); - for(int i=0; i < ctx->mvt_nb && i < 1000; i++){ + + /* Get the probabilistic parameters */ + 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){ + if(sumExp == 0.){ + sumExp += vcode_array[i].score; + } + if(vcode_array[i].score - sumExp >= 0){ + sumExp += exp(vcode_array[i].score - sumExp); + } + } + } + + currentSumExp = 0.; + for(int i=0; i < ft->classes_nb && i < 1000; i++){ printf("%d\t", i); movement_parser_print(stdout, vcode_array[i].class_code, ctx->dico_labels); printf("\t%.4f", vcode_array[i].score); @@ -190,13 +212,17 @@ void simple_decoder_parser_arc_eager(context *ctx) 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)); - printf(" %f ",exp(vcode_array[i].score)); - if(b1 && b2 && b3) - printf("\t<----"); - else + if(b1 && b2 && b3){ + if(vcode_array[i].score - sumExp >= 0){ + printf(" [%f-",currentSumExp/sumExp)); + currentSumExp += exp(vcode_array[i].score - sumExp); + printf("%f[", currentSumExp/sumExp)); + } + printf("\t<----"); + }else printf("\t<%d,%d,%d>",b1,b2,b3); // printf("\t%d", respect_standard_constraint(c, movement_parser_type(vcode_array[i].class_code), movement_parser_label(vcode_array[i].class_code))); - printf("AAAAAAA\n"); + //printf("AAAAAAA\n"); printf("\n"); } free(vcode_array); -- GitLab