Skip to content

Commit

Permalink
flush time & bi score
Browse files Browse the repository at this point in the history
  • Loading branch information
ruoshui1126 committed Nov 10, 2014
1 parent dafe1bf commit 2f6fa5c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/segmentor/customized_segmentor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ CustomizedSegmentor::calculate_scores(Instance * inst, bool use_avg) {

for (int pl = 0; pl < L; ++ pl) {
for (int l = 0; l < L; ++ l) {
int idx = model->space.index(pl, l);
int idx = baseline_model->space.index(pl, l);

if(!use_avg) {
inst->bi_scores[pl][l] = baseline_model->param.dot(idx, false);
Expand Down Expand Up @@ -278,6 +278,11 @@ CustomizedSegmentor::train_setup() {
return true;
}

int
CustomizedSegmentor::flush_time(void) {
return timestamp + baseline_model->end_time;
}

void
CustomizedSegmentor::train_passive_aggressive(int nr_errors) {
double error = nr_errors;
Expand Down
3 changes: 3 additions & 0 deletions src/segmentor/customized_segmentor.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ class CustomizedSegmentor : public Segmentor{
//!
void train_averaged_perceptron(void);

//!
int flush_time(void);

//!
void evaluate(double &p, double &r, double &f);

Expand Down
9 changes: 7 additions & 2 deletions src/segmentor/segmentor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,10 @@ Segmentor::train_setup() {
return true;
};

int
Segmentor::flush_time(void) {
return timestamp;
}
void
Segmentor::train(void) {
if (!train_setup()) {
Expand Down Expand Up @@ -736,8 +740,9 @@ Segmentor::train(void) {
}
}

model->param.flush( train_dat.size() * (iter + 1) );
model->end_time = train_dat.size() * (iter + 1);
int t = flush_time();
model->param.flush(t);
model->end_time = t;

Model * new_model = NULL;
new_model = erase_rare_features(feature_group_updated_time);
Expand Down
5 changes: 5 additions & 0 deletions src/segmentor/segmentor.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ class Segmentor {
*/
virtual void train_averaged_perceptron();

/**
* Return the flush time after each iteration.
*/
virtual int flush_time(void);

/**
* The main training process, the training scheme can be summarized as
*
Expand Down

0 comments on commit 2f6fa5c

Please sign in to comment.