当前位置: 首页>>代码示例>>Python>>正文


Python Corpus.get_feature_name方法代码示例

本文整理汇总了Python中corpus.Corpus.get_feature_name方法的典型用法代码示例。如果您正苦于以下问题:Python Corpus.get_feature_name方法的具体用法?Python Corpus.get_feature_name怎么用?Python Corpus.get_feature_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在corpus.Corpus的用法示例。


在下文中一共展示了Corpus.get_feature_name方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ActivePipeline

# 需要导入模块: from corpus import Corpus [as 别名]
# 或者: from corpus.Corpus import get_feature_name [as 别名]

#.........这里部分代码省略.........
            get_labeled_features: A function that receives a class and a list
            of features. It must return a list of features associated with the
            class. Can return None in case of error.
            max_iterations: Optional. An interger. The cicle will execute at
            most max_iterations times if the user does not enter stop before.

        Returns:
            The number of features the user has labeled.
        """
        result = 0
        while not max_iterations or result < max_iterations:
            class_name = get_class(self.get_class_options())
            if not class_name:
                continue
            if class_name == 'stop':
                break
            if class_name == 'train':
                self._train()
                self._expectation_maximization()
                continue
            class_number = self.classes.index(class_name)
            feature_numbers = self.get_next_features(class_number)
            e_prediction = []
            prediction = []
            if self.emulate:
                e_prediction = [f for f in feature_numbers
                                if self.feature_corpus[class_number][f] == 1]
                feature_numbers = [f for f in feature_numbers
                                   if f not in e_prediction]
                print "Adding {0} features from corpus for class {1}".format(
                    len(e_prediction), class_name
                )
            if feature_numbers:
                feature_names = [self.training_corpus.get_feature_name(pos)
                                 for pos in feature_numbers]
                prediction = get_labeled_features(class_name, feature_names)
                if prediction == None and not e_prediction:
                    continue
                if prediction == 'stop':
                    break
                if prediction == 'train':
                    self._train()
                    self._expectation_maximization()
                    continue
                prediction = [feature_numbers[feature_names.index(f)]
                              for f in prediction]
            self.handle_feature_prediction(class_number,
                                           feature_numbers + e_prediction,
                                           prediction + e_prediction)
            result += len(prediction + e_prediction)
        return result

    def handle_feature_prediction(self, class_number, full_set, prediction):
        """Adds the new information from prediction to user_features.

        Args:
            class_number: an interger. The position of the class in self.classes
            full_set: a list of positions of features that was given to the
            user.
            prediction: a list of positions of features selected for the class.
            The features not present in this class are considered as negative
            examples.
        """
        for feature in full_set:
            if feature in prediction:
                self.user_features[class_number][feature] += \
开发者ID:mit0110,项目名称:tesis,代码行数:70,代码来源:activepipe.py


注:本文中的corpus.Corpus.get_feature_name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。