Skip to content
Snippets Groups Projects
Commit 49dee1d0 authored by Alexis Nasr's avatar Alexis Nasr
Browse files

extracted perceptron from maca_trans_parser it is now completely independent

parent c3d40393
Branches perceptron
No related tags found
No related merge requests found
Showing
with 340 additions and 52 deletions
...@@ -4,8 +4,10 @@ project(macaon2) ...@@ -4,8 +4,10 @@ project(macaon2)
add_definitions("-Wall") add_definitions("-Wall")
include_directories(maca_common/include) include_directories(maca_common/include)
include_directories(perceptron/lib/include)
add_subdirectory(maca_common) add_subdirectory(maca_common)
add_subdirectory(perceptron)
add_subdirectory(maca_lemmatizer) add_subdirectory(maca_lemmatizer)
add_subdirectory(maca_trans_parser) add_subdirectory(maca_trans_parser)
add_subdirectory(maca_crf_tagger) add_subdirectory(maca_crf_tagger)
......
set(SOURCES src/context.c set(SOURCES src/context.c
src/feat_desc.c src/feat_desc.c
src/feature_table.c
src/movement_parser.c src/movement_parser.c
src/movement_tagger.c src/movement_tagger.c
src/feat_fct.c src/feat_fct.c
src/feat_vec.c
src/global_feat_vec.c src/global_feat_vec.c
src/oracle_parser.c src/oracle_parser.c
src/oracle_tagger.c src/oracle_tagger.c
src/simple_decoder_parser.c src/simple_decoder_parser.c
src/simple_decoder_forrest.c src/simple_decoder_forrest.c
src/simple_decoder_tagger.c src/simple_decoder_tagger.c
src/cf_file.c
src/feat_lib.c src/feat_lib.c
src/perceptron.c
src/stack.c src/stack.c
src/config2feat_vec.c src/config2feat_vec.c
src/depset.c src/depset.c
...@@ -27,61 +23,53 @@ set(SOURCES src/context.c ...@@ -27,61 +23,53 @@ set(SOURCES src/context.c
#compiling library #compiling library
include_directories(src) include_directories(src)
add_library(transparse STATIC ${SOURCES}) add_library(transparse STATIC ${SOURCES})
target_link_libraries(transparse perceptron)
#compiling, linking and installing executables #compiling, linking and installing executables
add_executable(maca_trans_tagger_mcf2cff ./src/maca_trans_tagger_mcf2cff.c) add_executable(maca_trans_tagger_mcf2cff ./src/maca_trans_tagger_mcf2cff.c)
target_link_libraries(maca_trans_tagger_mcf2cff perceptron)
target_link_libraries(maca_trans_tagger_mcf2cff transparse) target_link_libraries(maca_trans_tagger_mcf2cff transparse)
target_link_libraries(maca_trans_tagger_mcf2cff maca_common) target_link_libraries(maca_trans_tagger_mcf2cff maca_common)
install (TARGETS maca_trans_tagger_mcf2cff DESTINATION bin) install (TARGETS maca_trans_tagger_mcf2cff DESTINATION bin)
add_executable(maca_trans_parser_mcf2fann ./src/maca_trans_parser_mcf2fann.c) add_executable(maca_trans_parser_mcf2fann ./src/maca_trans_parser_mcf2fann.c)
target_link_libraries(maca_trans_parser_mcf2fann perceptron)
target_link_libraries(maca_trans_parser_mcf2fann transparse) target_link_libraries(maca_trans_parser_mcf2fann transparse)
target_link_libraries(maca_trans_parser_mcf2fann maca_common) target_link_libraries(maca_trans_parser_mcf2fann maca_common)
install (TARGETS maca_trans_parser_mcf2fann DESTINATION bin) install (TARGETS maca_trans_parser_mcf2fann DESTINATION bin)
add_executable(maca_trans_parser_mcf2cff ./src/maca_trans_parser_mcf2cff.c) add_executable(maca_trans_parser_mcf2cff ./src/maca_trans_parser_mcf2cff.c)
target_link_libraries(maca_trans_parser_mcf2cff perceptron)
target_link_libraries(maca_trans_parser_mcf2cff transparse) target_link_libraries(maca_trans_parser_mcf2cff transparse)
target_link_libraries(maca_trans_parser_mcf2cff maca_common) target_link_libraries(maca_trans_parser_mcf2cff maca_common)
install (TARGETS maca_trans_parser_mcf2cff DESTINATION bin) install (TARGETS maca_trans_parser_mcf2cff DESTINATION bin)
add_executable(maca_trans_parser ./src/maca_trans_parser.c) add_executable(maca_trans_parser ./src/maca_trans_parser.c)
target_link_libraries(maca_trans_parser perceptron)
target_link_libraries(maca_trans_parser transparse) target_link_libraries(maca_trans_parser transparse)
target_link_libraries(maca_trans_parser maca_common) target_link_libraries(maca_trans_parser maca_common)
install (TARGETS maca_trans_parser DESTINATION bin) install (TARGETS maca_trans_parser DESTINATION bin)
add_executable(maca_trans_parser_forrest ./src/decode_forrest.c) add_executable(maca_trans_parser_forrest ./src/decode_forrest.c)
target_link_libraries(maca_trans_parser_forrest perceptron)
target_link_libraries(maca_trans_parser_forrest transparse) target_link_libraries(maca_trans_parser_forrest transparse)
target_link_libraries(maca_trans_parser_forrest maca_common) target_link_libraries(maca_trans_parser_forrest maca_common)
install (TARGETS maca_trans_parser_forrest DESTINATION bin) install (TARGETS maca_trans_parser_forrest DESTINATION bin)
add_executable(maca_trans_tagger ./src/maca_trans_tagger.c) add_executable(maca_trans_tagger ./src/maca_trans_tagger.c)
target_link_libraries(maca_trans_tagger perceptron)
target_link_libraries(maca_trans_tagger transparse) target_link_libraries(maca_trans_tagger transparse)
target_link_libraries(maca_trans_tagger maca_common) target_link_libraries(maca_trans_tagger maca_common)
install (TARGETS maca_trans_tagger DESTINATION bin) install (TARGETS maca_trans_tagger DESTINATION bin)
add_executable(maca_trans_parser_train ./src/train_perceptron.c) add_executable(maca_trans_parser_train ./src/train_perceptron.c)
target_compile_options(maca_trans_parser_train INTERFACE -Wall) target_compile_options(maca_trans_parser_train INTERFACE -Wall)
target_link_libraries(maca_trans_parser_train perceptron)
target_link_libraries(maca_trans_parser_train transparse) target_link_libraries(maca_trans_parser_train transparse)
target_link_libraries(maca_trans_parser_train maca_common) target_link_libraries(maca_trans_parser_train maca_common)
install (TARGETS maca_trans_parser_train DESTINATION bin) install (TARGETS maca_trans_parser_train DESTINATION bin)
add_executable(maca_trans_parser_train_from_cff ./src/train.c)
target_link_libraries(maca_trans_parser_train_from_cff transparse)
target_link_libraries(maca_trans_parser_train_from_cff maca_common)
install (TARGETS maca_trans_parser_train_from_cff DESTINATION bin)
add_executable(maca_trans_parser_cff_cutoff ./src/cff_cutoff.c)
target_link_libraries(maca_trans_parser_cff_cutoff transparse)
target_link_libraries(maca_trans_parser_cff_cutoff maca_common)
install (TARGETS maca_trans_parser_cff_cutoff DESTINATION bin)
add_executable(eval_classifier ./src/eval_classifier.c)
target_link_libraries(eval_classifier transparse)
target_link_libraries(eval_classifier maca_common)
install (TARGETS eval_classifier DESTINATION bin)
#add_executable(test_w2v ./src/test_w2v.c) #add_executable(test_w2v ./src/test_w2v.c)
#target_link_libraries(test_w2v transparse) #target_link_libraries(test_w2v transparse)
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include"oracle_parser.h" #include"oracle_parser.h"
#include"feat_fct.h" #include"feat_fct.h"
#include"context.h" #include"context.h"
#include"feat_types.h"
#include"feat_vec.h" #include"feat_vec.h"
#include"dico_vec.h" #include"dico_vec.h"
#include"word_emb.h" #include"word_emb.h"
...@@ -169,3 +170,94 @@ int main(int argc, char *argv[]) ...@@ -169,3 +170,94 @@ int main(int argc, char *argv[])
return 0; return 0;
} }
void feat_vec_print_dnn(FILE *f, feat_vec *fv, feat_model *fm, mcd *m)
{
int i,j;
feat_desc *fd;
simple_feat_desc *sfd;
int mcd_representation;
int column;
for(i=0; i < fm->nbelem; i++){
fd = fm->array[i];
sfd = fd->array[0];
if((sfd->type <= FEAT_TYPE_INT_16) && (sfd->type >= FEAT_TYPE_INT_1)){
int range = sfd->type - FEAT_TYPE_INT_0;
for(j=0; j < range; j++){
/* if(i + j != 0) fprintf(f, " "); */
if(j == fv->t[i])
fprintf(f, "1 ");
else
fprintf(f, "0 ");
}
}
else{
column = m->wf2col[sfd->type];
mcd_representation = m->representation[column];
if(mcd_representation == MCD_REPRESENTATION_EMB){
/* if(i != 0) fprintf(f, " "); */
word_emb_print(f, m->word_emb_array[column], fv->t[i]);
}
else if(mcd_representation == MCD_REPRESENTATION_VOCAB){
for(j=0; j < m->dico_array[column]->nbelem; j++){
/* if(i + j != 0) fprintf(f, " "); */
if(j == fv->t[i])
fprintf(f, "1 ");
else
fprintf(f, "0 ");
}
}
}
fprintf(f, "\n");
}
fprintf(f, "\n");
}
/* void feat_vec_fill_input_array_dnn(fann_type *input_array, feat_vec *fv, feat_model *fm, mcd *m) */
void feat_vec_fill_input_array_dnn(float *input_array, feat_vec *fv, feat_model *fm, mcd *m)
{
int i,j;
feat_desc *fd;
simple_feat_desc *sfd;
int mcd_representation;
int current_index = 0;
int column;
for(i=0; i < fm->nbelem; i++){
fd = fm->array[i];
sfd = fd->array[0];
if((sfd->type <= FEAT_TYPE_INT_16) && (sfd->type >= FEAT_TYPE_INT_1)){
int range = sfd->type - FEAT_TYPE_INT_0;
for(j=0; j < range; j++){
if(j == fv->t[i])
input_array[current_index++] = 1;
else
input_array[current_index++] = 0;
}
}
else{
column = m->wf2col[sfd->type];
mcd_representation = m->representation[column];
if(mcd_representation == MCD_REPRESENTATION_EMB){
current_index = word_emb_fill_input_array_dnn(input_array, m->word_emb_array[column], fv->t[i], current_index);
}
else if(mcd_representation == MCD_REPRESENTATION_VOCAB){
for(j=0; j < m->dico_array[column]->nbelem; j++){
if(j == fv->t[i])
input_array[current_index++] = 1;
else
input_array[current_index++] = 0;
}
}
}
}
}
add_subdirectory(lib)
add_subdirectory(exec)
#compiling, linking and installing executables
add_executable(perceptron_train perceptron_train.c)
target_link_libraries(perceptron_train perceptron)
target_link_libraries(perceptron_train maca_common)
install (TARGETS perceptron_train DESTINATION bin)
#add_executable(maca_trans_parser_cff_cutoff cff_cutoff.c)
#target_link_libraries(maca_trans_parser_cff_cutoff perceptron)
#target_link_libraries(maca_trans_parser_cff_cutoff maca_common)
#install (TARGETS maca_trans_parser_cff_cutoff DESTINATION bin)
add_executable(perceptron_eval perceptron_eval.c)
target_link_libraries(perceptron_eval perceptron)
target_link_libraries(perceptron_eval maca_common)
install (TARGETS perceptron_eval DESTINATION bin)
...@@ -3,21 +3,18 @@ ...@@ -3,21 +3,18 @@
#include<string.h> #include<string.h>
#include<unistd.h> #include<unistd.h>
#include<getopt.h> #include<getopt.h>
#include"movement_parser.h"
#include"oracle_parser.h"
#include"feature_table.h" #include"feature_table.h"
#include"dico.h" #include"dico.h"
#include"perceptron.h" #include"perceptron.h"
#include"context.h" #include"perceptron_context.h"
#include"cf_file.h" #include"cf_file.h"
void cff_cutoff_help_message(context *ctx) void cff_cutoff_help_message(perceptron_context *ctx)
{ {
context_general_help_message(ctx); perceptron_context_help_message(ctx);
fprintf(stderr, "INPUT\n"); fprintf(stderr, "INPUT\n");
context_cutoff_help_message(ctx); perceptron_context_cutoff_help_message(ctx);
context_cff_help_message(ctx);
fprintf(stderr, "INPUT/OUTPUT\n");
} }
void cff_cutoff_check_options(context *ctx) void cff_cutoff_check_options(context *ctx)
......
...@@ -3,19 +3,20 @@ ...@@ -3,19 +3,20 @@
#include<string.h> #include<string.h>
#include<unistd.h> #include<unistd.h>
#include<getopt.h> #include<getopt.h>
#include"util.h"
#include"feature_table.h" #include"feature_table.h"
#include"perceptron.h" #include"perceptron.h"
#include"context.h" #include"perceptron_context.h"
void eval_classifier_help_message(context *ctx) void eval_classifier_help_message(perceptron_context *ctx)
{ {
context_general_help_message(ctx); perceptron_context_help_message(ctx);
fprintf(stderr, "INPUT\n"); /* fprintf(stderr, "INPUT\n"); */
context_model_help_message(ctx); /* perceptron_context_model_help_message(ctx); */
context_cff_help_message(ctx); /* perceptron_context_cff_help_message(ctx); */
} }
void eval_classifier_check_options(context *ctx) void eval_classifier_check_options(perceptron_context *ctx)
{ {
if(!ctx->cff_filename if(!ctx->cff_filename
|| !ctx->perc_model_filename || !ctx->perc_model_filename
...@@ -37,10 +38,10 @@ int main(int argc, char *argv[]) ...@@ -37,10 +38,10 @@ int main(int argc, char *argv[])
feat_vec *fv = feat_vec_new(2); feat_vec *fv = feat_vec_new(2);
char *token; char *token;
float accuracy; float accuracy;
context *ctx; perceptron_context *ctx;
float score; float score;
ctx = context_read_options(argc, argv); ctx = perceptron_context_read_options(argc, argv);
eval_classifier_check_options(ctx); eval_classifier_check_options(ctx);
ft = feature_table_load(ctx->perc_model_filename, ctx->verbose); ft = feature_table_load(ctx->perc_model_filename, ctx->verbose);
......
...@@ -3,26 +3,18 @@ ...@@ -3,26 +3,18 @@
#include<string.h> #include<string.h>
#include<unistd.h> #include<unistd.h>
#include<getopt.h> #include<getopt.h>
#include"movement_parser.h"
#include"oracle_parser.h"
#include"feat_fct.h"
#include"feature_table.h" #include"feature_table.h"
#include"dico.h" #include"dico.h"
#include"perceptron.h" #include"perceptron.h"
#include"context.h" #include"perceptron_context.h"
#include"cf_file.h" #include"cf_file.h"
void train_help_message(context *ctx) void train_help_message(perceptron_context *ctx)
{ {
context_general_help_message(ctx); perceptron_context_help_message(ctx);
context_iterations_help_message(ctx);
fprintf(stderr, "INPUT\n");
context_cff_help_message(ctx);
fprintf(stderr, "OUTPUT\n");
context_model_help_message(ctx);
} }
void train_check_options(context *ctx) void train_check_options(perceptron_context *ctx)
{ {
if(!ctx->cff_filename if(!ctx->cff_filename
|| !ctx->perc_model_filename || !ctx->perc_model_filename
...@@ -37,9 +29,9 @@ int main(int argc, char *argv[]) ...@@ -37,9 +29,9 @@ int main(int argc, char *argv[])
{ {
int nb_feat, nb_class; int nb_feat, nb_class;
feature_table *ft; feature_table *ft;
context *ctx; perceptron_context *ctx;
ctx = context_read_options(argc, argv); ctx = perceptron_context_read_options(argc, argv);
train_check_options(ctx); train_check_options(ctx);
look_for_number_of_features_and_classes(ctx->cff_filename, &nb_feat, &nb_class); look_for_number_of_features_and_classes(ctx->cff_filename, &nb_feat, &nb_class);
...@@ -49,7 +41,7 @@ int main(int argc, char *argv[]) ...@@ -49,7 +41,7 @@ int main(int argc, char *argv[])
perceptron_avg(ctx->cff_filename, ft, ctx->iteration_nb); perceptron_avg(ctx->cff_filename, ft, ctx->iteration_nb);
feature_table_dump(ctx->perc_model_filename, ft); feature_table_dump(ctx->perc_model_filename, ft);
context_free(ctx); perceptron_context_free(ctx);
return 0; return 0;
} }
File moved
set(SOURCES src/cf_file.c
src/feature_table.c
src/perceptron.c
src/feat_vec.c
src/perceptron_context.c
)
#compiling library
include_directories(src)
add_library(perceptron STATIC ${SOURCES})
File moved
#ifndef __PERCEPTRON_CONTEXT__
#define __PERCEPTRON_CONTEXT__
#include "dico_vec.h"
#include<stdlib.h>
typedef struct {
int help;
int verbose;
char *program_name;
char *cff_filename;
char *perc_model_filename;
int iteration_nb;
} perceptron_context;
perceptron_context *perceptron_context_new(void);
void perceptron_context_free(perceptron_context *ctx);
perceptron_context *perceptron_context_read_options(int argc, char *argv[]);
void perceptron_context_help_message(perceptron_context *ctx);
#endif
File moved
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
#include<stdlib.h> #include<stdlib.h>
#include"feat_vec.h" #include"feat_vec.h"
#include"util.h" #include"util.h"
#include "feat_types.h" /* #include "feat_types.h" */
#include "feat_model.h" /* #include "feat_model.h" */
void feat_vec_concat(feat_vec *fv1, feat_vec *fv2) void feat_vec_concat(feat_vec *fv1, feat_vec *fv2)
{ {
...@@ -78,90 +78,3 @@ void feat_vec_print(FILE *f, feat_vec *fv) ...@@ -78,90 +78,3 @@ void feat_vec_print(FILE *f, feat_vec *fv)
fprintf(f, "\n"); fprintf(f, "\n");
} }
void feat_vec_print_dnn(FILE *f, feat_vec *fv, feat_model *fm, mcd *m)
{
int i,j;
feat_desc *fd;
simple_feat_desc *sfd;
int mcd_representation;
int column;
for(i=0; i < fm->nbelem; i++){
fd = fm->array[i];
sfd = fd->array[0];
if((sfd->type <= FEAT_TYPE_INT_16) && (sfd->type >= FEAT_TYPE_INT_1)){
int range = sfd->type - FEAT_TYPE_INT_0;
for(j=0; j < range; j++){
/* if(i + j != 0) fprintf(f, " "); */
if(j == fv->t[i])
fprintf(f, "1 ");
else
fprintf(f, "0 ");
}
}
else{
column = m->wf2col[sfd->type];
mcd_representation = m->representation[column];
if(mcd_representation == MCD_REPRESENTATION_EMB){
/* if(i != 0) fprintf(f, " "); */
word_emb_print(f, m->word_emb_array[column], fv->t[i]);
}
else if(mcd_representation == MCD_REPRESENTATION_VOCAB){
for(j=0; j < m->dico_array[column]->nbelem; j++){
/* if(i + j != 0) fprintf(f, " "); */
if(j == fv->t[i])
fprintf(f, "1 ");
else
fprintf(f, "0 ");
}
}
}
fprintf(f, "\n");
}
fprintf(f, "\n");
}
/* void feat_vec_fill_input_array_dnn(fann_type *input_array, feat_vec *fv, feat_model *fm, mcd *m) */
void feat_vec_fill_input_array_dnn(float *input_array, feat_vec *fv, feat_model *fm, mcd *m)
{
int i,j;
feat_desc *fd;
simple_feat_desc *sfd;
int mcd_representation;
int current_index = 0;
int column;
for(i=0; i < fm->nbelem; i++){
fd = fm->array[i];
sfd = fd->array[0];
if((sfd->type <= FEAT_TYPE_INT_16) && (sfd->type >= FEAT_TYPE_INT_1)){
int range = sfd->type - FEAT_TYPE_INT_0;
for(j=0; j < range; j++){
if(j == fv->t[i])
input_array[current_index++] = 1;
else
input_array[current_index++] = 0;
}
}
else{
column = m->wf2col[sfd->type];
mcd_representation = m->representation[column];
if(mcd_representation == MCD_REPRESENTATION_EMB){
current_index = word_emb_fill_input_array_dnn(input_array, m->word_emb_array[column], fv->t[i], current_index);
}
else if(mcd_representation == MCD_REPRESENTATION_VOCAB){
for(j=0; j < m->dico_array[column]->nbelem; j++){
if(j == fv->t[i])
input_array[current_index++] = 1;
else
input_array[current_index++] = 0;
}
}
}
}
}
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<unistd.h>
#include<getopt.h>
#include "perceptron_context.h"
#include "util.h"
void perceptron_context_free(perceptron_context *ctx)
{
if(ctx->program_name) free(ctx->program_name);
if(ctx->cff_filename) free(ctx->cff_filename);
if(ctx->perc_model_filename) free(ctx->perc_model_filename);
free(ctx);
}
perceptron_context *perceptron_context_new(void)
{
perceptron_context *ctx = (perceptron_context *)memalloc(sizeof(perceptron_context));
ctx->verbose = 0;
ctx->program_name = NULL;
ctx->perc_model_filename = NULL;
ctx->cff_filename = NULL;
ctx->iteration_nb = 4;
return ctx;
}
void perceptron_context_help_message(perceptron_context *ctx)
{
fprintf(stderr, "usage: %s [options]\n", ctx->program_name);
fprintf(stderr, "Options:\n");
fprintf(stderr, "\t-h --help : print this message\n");
fprintf(stderr, "\t-v --verbose : activate verbose mode\n");
fprintf(stderr, "\t-n --iter <int> : number of iterations (default is 4)\n");
fprintf(stderr, "\t-c --cff <file> : CFF format file name\n");
fprintf(stderr, "\t-m --model <file> : model file name\n");
}
perceptron_context *perceptron_context_read_options(int argc, char *argv[])
{
int c;
int option_index = 0;
perceptron_context *ctx = perceptron_context_new();
ctx->program_name = strdup(argv[0]);
static struct option long_options[5] =
{
{"help", no_argument, 0, 'h'},
{"verbose", no_argument, 0, 'v'},
{"model", required_argument, 0, 'm'},
{"iter", required_argument, 0, 'n'},
{"cff", required_argument, 0, 'c'}
};
optind = 0;
opterr = 0;
while ((c = getopt_long (argc, argv, "hvm:n:c:", long_options, &option_index)) != -1){
switch (c)
{
case 'h':
ctx->help = 1;
break;
case 'v':
ctx->verbose = 1;
break;
case 'm':
ctx->perc_model_filename = strdup(optarg);
break;
case 'n':
ctx->iteration_nb = atoi(optarg);
break;
case 'c':
ctx->cff_filename = strdup(optarg);
break;
}
}
return ctx;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment