/* EGYPT Toolkit for Statistical Machine Translation Written by Yaser Al-Onaizan, Jan Curin, Michael Jahr, Kevin Knight, John Lafferty, Dan Melamed, David Purdy, Franz Och, Noah Smith, and David Yarowsky. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /*-- transpair_model3: representation of a translation pair for model3 training allowing for fast access (esp. to t table). Franz Josef Och (30/07/99) --*/ #include "transpair_model3.h" #include transpair_model3::transpair_model3(const Vector&es, const Vector&fs, tmodel&tTable, amodel&aTable, amodel&dTable, nmodel&nTable, double _p1, double _p0, void*) : transpair_model2(es,fs,tTable,aTable),d(es.size(), fs.size()),n(es.size(), MAX_FERTILITY+1), p0(_p0), p1(_p1) { WordIndex l=es.size()-1,m=fs.size()-1; for(WordIndex i=0;i<=l;i++) { for(WordIndex j=1;j<=m;j++) d(i, j)=dTable.getValue(j, i, l, m); if( i>0 ) { for(WordIndex f=0;f0 ) out << "(fert:"< " << total << '\n'; } for (WordIndex j = 1 ; j <= m ; j++) { total*= get_t(al(j), j) ; massert( get_t(al(j), j)>=PROB_SMOOTH ); if( verb) cerr << "IBM-3: t of " << j << " " << al(j) << ": " << get_t(al(j), j) << " -> " << total << '\n'; if (al(j)) { total *= get_d(al(j), j); if( verb) cerr << "IBM-3: d of " << j << ": " << get_d(al(j), j) << " -> " << total << '\n'; } } return total?total:zero; } void transpair_model3::computeScores(const alignment&al,vector&d)const { LogProb total1 = 1.0,total2=1.0,total3=1.0,total4=1.0 ; total1 *= pow(double(1-p1), m-2.0 * al.fert(0)) * pow(double(p1), double(al.fert(0))); for (WordIndex i = 1 ; i <= al.fert(0) ; i++) total1 *= double(m - al.fert(0) - i + 1) / (double(DeficientDistortionForEmptyWord?(max(2,int(m))/DeficientDistortionForEmptyWord):i)) ; for (WordIndex i = 1 ; i <= l ; i++) { total2 *= get_fertility(i, al.fert(i)) * (LogProb) factorial(al.fert(i)); } for (WordIndex j = 1 ; j <= m ; j++) { total3*= get_t(al(j), j) ; massert( get_t(al(j), j)>=PROB_SMOOTH ); if (al(j)) { total4 *= get_d(al(j), j); } } d.push_back(total1);//5 d.push_back(total2);//6 d.push_back(total3);//7 d.push_back(total4);//8 }