Example #1
0
 def evaluate(self , gold_path , predict_path) :
     gold_ite = DatasetHandler.read_dev_data(gold_path)
     predict_ite = DatasetHandler.read_dev_data(predict_path)
     nr_processing = 0
     nr_gold = 0
     nr_processing_right = 0
     nr_line = 0
     while True :
         try :
             gold_instance = gold_ite.next()
             predict_instance = predict_ite.next()
         except StopIteration :
             break
         nr_line += 1
         gold_unigrams , gold_tags = self._processing_one_segmented_WSAtom_instance2unigrams_and_tags(gold_instance)
         predict_unigrams , predict_tags = self._processing_one_segmented_WSAtom_instance2unigrams_and_tags(predict_instance)
         gold_coor_seq = self.__innerfunc_4evaluate_generate_word_coordinate_sequence_from_tags(gold_tags)
         predict_coor_seq = self.__innerfunc_4evaluate_generate_word_coordinate_sequence_from_tags(predict_tags)
         cur_nr_gold , cur_nr_processing , cur_nr_processing_right = (
                 self.__innerfunc_4evaluate_get_nr_gold_and_processing_and_processing_right(gold_coor_seq , predict_coor_seq) )
         nr_gold += cur_nr_gold
         nr_processing += cur_nr_processing
         nr_processing_right += cur_nr_processing_right
     p , r , f = self.__innerfunc_4evaluate_calculate_prf(nr_gold , nr_processing , nr_processing_right)
     print ("Eval result :\np : %.2f%% r : %.2f%% f : %.2f%%\n"
           "line num : %d total word num : %d total predict word num : %d predict right num : %d ") %(
             p * 100 , r * 100, f * 100 , nr_line , nr_gold , nr_processing , nr_processing_right
             )
Example #2
0
 def _4training_evaluate_processing(self, dev_path):
     nr_processing_right = 0
     nr_gold = 0
     nr_processing = 0
     for instance in DatasetHandler.read_dev_data(dev_path):
         unigrams, gold_tags = Segmentor._processing_one_segmented_WSAtom_instance2unigrams_and_tags(
             instance)
         predict_tags = Decoder.decode_for_predict(self.extractor,
                                                   self.model,
                                                   self.constrain, unigrams)
         gold_coor_seq = self.__innerfunc_4evaluate_generate_word_coordinate_sequence_from_tags(
             gold_tags)
         predict_coor_seq = self.__innerfunc_4evaluate_generate_word_coordinate_sequence_from_tags(
             predict_tags)
         cur_nr_gold, cur_nr_processing, cur_nr_processing_right = (
             self.
             __innerfunc_4evaluate_get_nr_gold_and_processing_and_processing_right(
                 gold_coor_seq, predict_coor_seq))
         nr_gold += cur_nr_gold
         nr_processing += cur_nr_processing
         nr_processing_right += cur_nr_processing_right
     p, r, f = self.__innerfunc_4evaluate_calculate_prf(
         nr_gold, nr_processing, nr_processing_right)
     print >> sys.stderr, (
         "Eval result :\np : %.2f%% r : %.2f%% f : %.2f%%\n"
         "total word num : %d total predict word num : %d predict right num : %d "
     ) % (p * 100, r * 100, f * 100, nr_gold, nr_processing,
          nr_processing_right)
     return f
Example #3
0
 def evaluate(self, gold_path, predict_path):
     gold_ite = DatasetHandler.read_dev_data(gold_path)
     predict_ite = DatasetHandler.read_dev_data(predict_path)
     nr_processing = 0
     nr_gold = 0
     nr_processing_right = 0
     nr_line = 0
     while True:
         try:
             gold_instance = gold_ite.next()
             predict_instance = predict_ite.next()
         except StopIteration:
             break
         nr_line += 1
         gold_unigrams, gold_tags = self._processing_one_segmented_WSAtom_instance2unigrams_and_tags(
             gold_instance)
         predict_unigrams, predict_tags = self._processing_one_segmented_WSAtom_instance2unigrams_and_tags(
             predict_instance)
         gold_coor_seq = self.__innerfunc_4evaluate_generate_word_coordinate_sequence_from_tags(
             gold_tags)
         predict_coor_seq = self.__innerfunc_4evaluate_generate_word_coordinate_sequence_from_tags(
             predict_tags)
         cur_nr_gold, cur_nr_processing, cur_nr_processing_right = (
             self.
             __innerfunc_4evaluate_get_nr_gold_and_processing_and_processing_right(
                 gold_coor_seq, predict_coor_seq))
         nr_gold += cur_nr_gold
         nr_processing += cur_nr_processing
         nr_processing_right += cur_nr_processing_right
     p, r, f = self.__innerfunc_4evaluate_calculate_prf(
         nr_gold, nr_processing, nr_processing_right)
     print(
         "Eval result :\np : %.2f%% r : %.2f%% f : %.2f%%\n"
         "line num : %d total word num : %d total predict word num : %d predict right num : %d "
     ) % (p * 100, r * 100, f * 100, nr_line, nr_gold, nr_processing,
          nr_processing_right)
Example #4
0
 def _4training_evaluate_processing(self , dev_path) :
     nr_processing_right = 0
     nr_gold = 0
     nr_processing = 0
     for instance in DatasetHandler.read_dev_data(dev_path) :
         unigrams , gold_tags = Segmentor._processing_one_segmented_WSAtom_instance2unigrams_and_tags(instance)
         predict_tags = Decoder.decode_for_predict(self.extractor , self.model , self.constrain , unigrams)
         gold_coor_seq = self.__innerfunc_4evaluate_generate_word_coordinate_sequence_from_tags(gold_tags)
         predict_coor_seq = self.__innerfunc_4evaluate_generate_word_coordinate_sequence_from_tags(predict_tags)
         cur_nr_gold , cur_nr_processing , cur_nr_processing_right = (
                         self.__innerfunc_4evaluate_get_nr_gold_and_processing_and_processing_right(gold_coor_seq , predict_coor_seq)
                 )
         nr_gold += cur_nr_gold
         nr_processing += cur_nr_processing
         nr_processing_right += cur_nr_processing_right
     p , r , f = self.__innerfunc_4evaluate_calculate_prf(nr_gold , nr_processing , nr_processing_right)
     print >>sys.stderr , ("Eval result :\np : %.2f%% r : %.2f%% f : %.2f%%\n"
            "total word num : %d total predict word num : %d predict right num : %d ")%(
             p * 100 , r * 100, f * 100 , nr_gold , nr_processing , nr_processing_right
             )
     return f