shallow_rank.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:liveqa2017 作者: codekansas 项目源码 文件源码
def __init__(self,
                 num_topics=NUM_TOPICS,
                 dictionary_file=DICTIONARY_FILE,
                 model_file=MODEL_FILE):
        """Initializes the ranker.

        Args:
            num_topics: int (default: NUM_TOPICS), number of LSI topics to use.
            dictionary_file: str, where to save / load the dictionary file
                (defaults to DICTIONARY_FILE).
            model_file: str, where to save / load the model (defaults to
                MODEL_FILE).
        """

        self.dictionary = None
        self.model = None
        self.num_topics = num_topics
        self.dictionary_file = dictionary_file
        self.model_file = model_file

        # Loads stopwords from the associated file.
        with open(STOPWORDS_FILE, 'r') as f:
            self.stoplist = set(f.read().strip().split())

        # Loads an existing dictionary file, if one exists.
        if os.path.exists(self.dictionary_file):
            with open(self.dictionary_file, 'rb') as f:
                self.dictionary = pickle.load(f)

        # Loads an existing model file, if one exists.
        if os.path.exists(self.model_file):
            self.model = models.LdaModel.load(self.model_file)
        else:
            logging.warn('No model found in "%s"', self.model_file)

        # Determines if the model needs to be trained.
        self._trained = self.dictionary and self.model
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号