<s> import math <EOL> from srilm import LM <EOL> from decoder_config import LM_ARPA_FILE , LM_ORDER <EOL> from prep_text import preproc_transcript , preproc_utts <EOL> '''<STR_LIT>''' <EOL> def compute_pp ( text , lm , order ) : <EOL> pp = <NUM_LIT:0.0> <EOL> n = <NUM_LIT:0> <EOL> for utt in text : <EOL> for k in range ( <NUM_LIT:1> , len ( utt ) ) : <EOL> c = utt [ k ] <EOL> seq = utt [ max ( <NUM_LIT:0> , k - order + <NUM_LIT:1> ) : k ] <EOL> seq = seq [ : : - <NUM_LIT:1> ] <EOL> pp = pp + - <NUM_LIT:1> * lm . logprob_strings ( c , seq ) <EOL> n += <NUM_LIT:1> <EOL> pp = pp / n <EOL> pp = <NUM_LIT:10> ** pp <EOL> return pp <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> NUM_LINES = float ( '<STR_LIT>' ) <EOL> print '<STR_LIT>' % LM_ARPA_FILE <EOL> lm = LM ( LM_ARPA_FILE ) <EOL> print '<STR_LIT>' <EOL> with open ( '<STR_LIT>' , '<STR_LIT:r>' ) as fin : <EOL> transcript = fin . read ( ) <EOL> utts = preproc_transcript ( transcript , num_lines = NUM_LINES ) <EOL> text = preproc_utts ( utts ) <EOL> pp = compute_pp ( text , lm , LM_ORDER ) <EOL> print '<STR_LIT>' % pp <EOL> print '<STR_LIT>' % math . log ( pp , <NUM_LIT:2> ) </s>
