diff options
author | Patrick Simianer <p@simianer.de> | 2011-09-09 15:33:35 +0200 |
---|---|---|
committer | Patrick Simianer <p@simianer.de> | 2011-09-23 19:13:58 +0200 |
commit | edb0cc0cbae1e75e4aeedb6360eab325effe6573 (patch) | |
tree | a2fed4614b88f177f91e88fef3b269fa75e80188 /dtrain | |
parent | 2e6ef7cbec77b22ce3d64416a5ada3a6c081f9e2 (diff) |
partial merge, ruleid feature
Diffstat (limited to 'dtrain')
-rw-r--r-- | dtrain/dtrain.cc | 50 | ||||
-rwxr-xr-x | dtrain/run.sh | 5 | ||||
-rw-r--r-- | dtrain/sample.h | 18 | ||||
-rw-r--r-- | dtrain/test/EXAMPLE/dtrain.ini | 2 |
4 files changed, 36 insertions, 39 deletions
diff --git a/dtrain/dtrain.cc b/dtrain/dtrain.cc index d58478a8..35996d6d 100644 --- a/dtrain/dtrain.cc +++ b/dtrain/dtrain.cc @@ -215,7 +215,7 @@ main( int argc, char** argv ) // for the perceptron/SVM; TODO as params double eta = 0.0005; - double gamma = 0.01; // -> SVM + double gamma = 0.;//01; // -> SVM lambdas.add_value( FD::Convert("__bias"), 0 ); // for random sampling @@ -388,10 +388,8 @@ main( int argc, char** argv ) if ( !noup ) { TrainingInstances pairs; - - sample_all_rand(kb, pairs); - cout << pairs.size() << endl; - + sample_all( kb, pairs ); + for ( TrainingInstances::iterator ti = pairs.begin(); ti != pairs.end(); ti++ ) { @@ -401,31 +399,29 @@ main( int argc, char** argv ) //} else { //dv = ti->first - ti->second; //} - dv.add_value( FD::Convert("__bias"), -1 ); + dv.add_value( FD::Convert("__bias"), -1 ); - SparseVector<double> reg; - reg = lambdas * ( 2 * gamma ); - dv -= reg; - lambdas += dv * eta; - - if ( verbose ) { - cout << "{{ f("<< ti->first_rank <<") > f(" << ti->second_rank << ") but g(i)="<< ti->first_score <<" < g(j)="<< ti->second_score << " so update" << endl; - cout << " i " << TD::GetString(kb->sents[ti->first_rank]) << endl; - cout << " " << kb->feats[ti->first_rank] << endl; - cout << " j " << TD::GetString(kb->sents[ti->second_rank]) << endl; - cout << " " << kb->feats[ti->second_rank] << endl; - cout << " diff vec: " << dv << endl; - cout << " lambdas after update: " << lambdas << endl; - cout << "}}" << endl; - } - + //SparseVector<double> reg; + //reg = lambdas * ( 2 * gamma ); + //dv -= reg; + lambdas += dv * eta; + + if ( verbose ) { + cout << "{{ f("<< ti->first_rank <<") > f(" << ti->second_rank << ") but g(i)="<< ti->first_score <<" < g(j)="<< ti->second_score << " so update" << endl; + cout << " i " << TD::GetString(kb->sents[ti->first_rank]) << endl; + cout << " " << kb->feats[ti->first_rank] << endl; + cout << " j " << TD::GetString(kb->sents[ti->second_rank]) << endl; + cout << " " << kb->feats[ti->second_rank] << endl; + cout << " diff vec: " << dv << endl; + cout << " lambdas after update: " << lambdas << endl; + cout << "}}" << endl; + } } else { - //if ( 0 ) { - SparseVector<double> reg; - reg = lambdas * ( gamma * 2 ); - lambdas += reg * ( -eta ); - //} + //SparseVector<double> reg; + //reg = lambdas * ( 2 * gamma ); + //lambdas += reg * ( -eta ); } + } //double l2 = lambdas.l2norm(); diff --git a/dtrain/run.sh b/dtrain/run.sh index 16575c25..97123dfa 100755 --- a/dtrain/run.sh +++ b/dtrain/run.sh @@ -2,9 +2,10 @@ #INI=test/blunsom08.dtrain.ini #INI=test/nc-wmt11/dtrain.ini -#INI=test/EXAMPLE/dtrain.ini -INI=test/EXAMPLE/dtrain.ruleids.ini +INI=test/EXAMPLE/dtrain.ini +#INI=test/EXAMPLE/dtrain.ruleids.ini #INI=test/toy.dtrain.ini +#INI=test/EXAMPLE/dtrain.cdecrid.ini rm /tmp/dtrain-* ./dtrain -c $INI $1 $2 $3 $4 diff --git a/dtrain/sample.h b/dtrain/sample.h index b6aa9abd..502901af 100644 --- a/dtrain/sample.h +++ b/dtrain/sample.h @@ -37,20 +37,20 @@ sample_all( KBestList* kb, TrainingInstances &training ) } void -sample_all_rand( KBestList* kb, TrainingInstances &training ) +sample_rand( KBestList* kb, TrainingInstances &training ) { srand( time(NULL) ); for ( size_t i = 0; i < kb->GetSize()-1; i++ ) { for ( size_t j = i+1; j < kb->GetSize(); j++ ) { if ( rand() % 2 ) { - TPair p; - p.first = kb->feats[i]; - p.second = kb->feats[j]; - p.first_rank = i; - p.second_rank = j; - p.first_score = kb->scores[i]; - p.second_score = kb->scores[j]; - training.push_back( p ); + TPair p; + p.first = kb->feats[i]; + p.second = kb->feats[j]; + p.first_rank = i; + p.second_rank = j; + p.first_score = kb->scores[i]; + p.second_score = kb->scores[j]; + training.push_back( p ); } } } diff --git a/dtrain/test/EXAMPLE/dtrain.ini b/dtrain/test/EXAMPLE/dtrain.ini index 7645921a..7221ba3f 100644 --- a/dtrain/test/EXAMPLE/dtrain.ini +++ b/dtrain/test/EXAMPLE/dtrain.ini @@ -5,6 +5,6 @@ epochs=3 input=test/EXAMPLE/dtrain.nc-1k scorer=stupid_bleu output=test/EXAMPLE/weights.gz -stop_after=100 +stop_after=1000 wprint=Glue WordPenalty LanguageModel LanguageModel_OOV PhraseModel_0 PhraseModel_1 PhraseModel_2 PhraseModel_3 PhraseModel_4 PassThrough |