示例#1
0
    def load_reranker_model(self,
                            features_filename,
                            weights_filename,
                            feature_class=None):
        """Load the reranker model from its feature and weights files. A
        feature class may optionally be specified."""
        try:
            features_filename = str(features_filename)
        except UnicodeEncodeError:
            raise ValueError('Reranker features filename %r must be an ASCII '
                             'string.' % features_filename)
        try:
            weights_filename = str(weights_filename)
        except UnicodeEncodeError:
            raise ValueError('Reranker weights filename %r must be an ASCII '
                             'string.' % weights_filename)

        if not exists(features_filename):
            raise ValueError('Reranker features filename %r does not exist.' %
                             features_filename)
        if not exists(weights_filename):
            raise ValueError('Reranker weights filename %r does not exist.' %
                             weights_filename)
        self.reranker_model = reranker.RerankerModel(feature_class,
                                                     features_filename,
                                                     weights_filename)
示例#2
0
 def load_reranker_model(self,
                         features_filename,
                         weights_filename,
                         feature_class=None):
     """Load the reranker model from its feature and weights files. A feature
     class may optionally be specified."""
     if not os.path.exists(features_filename):
         raise ValueError('Reranker features filename %r does not exist.' % \
             features_filename)
     if not os.path.exists(weights_filename):
         raise ValueError('Reranker weights filename %r does not exist.' % \
             weights_filename)
     self.reranker_model = reranker.RerankerModel(feature_class,
                                                  features_filename,
                                                  weights_filename)
示例#3
0
 def rerank(self, reranker, lowercase=True):
     """Rerank this n-best list according to a reranker model. reranker
     can be a RerankingParser or RerankerModel."""
     assert reranker
     if not self.parses:
         self._reranked = True
         return
     if isinstance(reranker, RerankingParser):
         reranker = reranker.reranker_model
     reranker_input = self.as_reranker_input()
     scores = reranker.scoreNBestList(reranker_input)
     # this could be more efficient if needed
     for (score, nbest_list_item) in zip(scores, self.parses):
         nbest_list_item.reranker_score = score
     self.sort_by_reranker_scores()
     for index, nbest_list_item in enumerate(self.parses):
         nbest_list_item.reranker_rank = index
     self._reranked = True
示例#4
0
 def rerank(self, reranker, lowercase=True):
     """Rerank this n-best list according to a reranker model. reranker
     can be a RerankingParser or RerankerModel."""
     assert reranker
     if not self.parses:
         self._reranked = True
         return
     if isinstance(reranker, RerankingParser):
         reranker = reranker.reranker_model
     reranker_input = self.as_reranker_input()
     scores = reranker.scoreNBestList(reranker_input)
     # this could be more efficient if needed
     for (score, nbest_list_item) in zip(scores, self.parses):
         nbest_list_item.reranker_score = score
     self.sort_by_reranker_scores()
     for index, nbest_list_item in enumerate(self.parses):
         nbest_list_item.reranker_rank = index
     self._reranked = True
示例#5
0
 def as_reranker_input(self, lowercase=True):
     """Convert the n-best list to an internal structure used as input
     to the reranker.  You shouldn't typically need to call this."""
     return reranker.readNBestList(str(self), lowercase)
示例#6
0
 def as_reranker_input(self, lowercase=True):
     """Convert the n-best list to an internal structure used as input
     to the reranker. You shouldn't typically need to call this."""
     return reranker.readNBestList(str(self), lowercase)