<s> import numpy as np <EOL> import lxmls . sequences . sequence_classifier as sc <EOL> import pdb <EOL> class DiscriminativeSequenceClassifier ( sc . SequenceClassifier ) : <EOL> def __init__ ( self , observation_labels , state_labels , feature_mapper ) : <EOL> sc . SequenceClassifier . __init__ ( self , observation_labels , state_labels ) <EOL> self . feature_mapper = feature_mapper <EOL> self . parameters = np . zeros ( self . feature_mapper . get_num_features ( ) ) <EOL> def compute_scores ( self , sequence ) : <EOL> num_states = self . get_num_states ( ) <EOL> length = len ( sequence . x ) <EOL> emission_scores = np . zeros ( [ length , num_states ] ) <EOL> initial_scores = np . zeros ( num_states ) <EOL> transition_scores = np . zeros ( [ length - <NUM_LIT:1> , num_states , num_states ] ) <EOL> final_scores = np . zeros ( num_states ) <EOL> for tag_id in xrange ( num_states ) : <EOL> initial_features = self . feature_mapper . get_initial_features ( sequence , tag_id ) <EOL> score = <NUM_LIT:0.0> <EOL> for feat_id in initial_features : <EOL> score += self . parameters [ feat_id ] <EOL> initial_scores [ tag_id ] = score <EOL> for pos in xrange ( length ) : <EOL> for tag_id in xrange ( num_states ) : <EOL> emission_features = self . feature_mapper . get_emission_features ( sequence , pos , tag_id ) <EOL> score = <NUM_LIT:0.0> <EOL> for feat_id in emission_features : <EOL> score += self . parameters [ feat_id ] <EOL> emission_scores [ pos , tag_id ] = score <EOL> if pos > <NUM_LIT:0> : <EOL> for tag_id in xrange ( num_states ) : <EOL> for prev_tag_id in xrange ( num_states ) : <EOL> transition_features = self . feature_mapper . get_transition_features ( sequence , pos , tag_id , prev_tag_id ) <EOL> score = <NUM_LIT:0.0> <EOL> for feat_id in transition_features : <EOL> score += self . parameters [ feat_id ] <EOL> transition_scores [ pos - <NUM_LIT:1> , tag_id , prev_tag_id ] = score <EOL> for prev_tag_id in xrange ( num_states ) : <EOL> final_features = self . feature_mapper . get_final_features ( sequence , prev_tag_id ) <EOL> score = <NUM_LIT:0.0> <EOL> for feat_id in final_features : <EOL> score += self . parameters [ feat_id ] <EOL> final_scores [ prev_tag_id ] = score <EOL> return initial_scores , transition_scores , final_scores , emission_scores </s>
