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


Python fastText.load_model方法代码示例

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


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

示例1: __init__

# 需要导入模块: import fastText [as 别名]
# 或者: from fastText import load_model [as 别名]
def __init__(self, path=data_path):
        self._clf = [
            fastText.load_model(os.path.join(path, 'clf0.bin')),
            fastText.load_model(os.path.join(path, 'clf1.bin')),
            fastText.load_model(os.path.join(path, 'clf2.bin')),
        ]
        self._zh_chars = re.compile(r'[^\u4e00-\u9fff]+')
        self._id2name = dict()
        with open(os.path.join(data_path, 'nsfc_subject.csv'), encoding='utf-8') as f:
            for line in f:
                _id, _name = line[:-1].split(',') # encode csv
                self._id2name[_id] = _name 
开发者ID:AMinerOpen,项目名称:prediction_api,代码行数:14,代码来源:classifier.py

示例2: __init__

# 需要导入模块: import fastText [as 别名]
# 或者: from fastText import load_model [as 别名]
def __init__(self):
        self._model = fastText.load_model(os.path.join(data_path, 'model_aminer'))
        self._words = self._model.get_labels()
        self._index_mat = joblib.load(os.path.join(data_path, 'index_mat.pkl'))
        self._id2person = json.load(open(os.path.join(data_path, 'pid_list.json'), encoding='utf-8'))
        self.ac = ACAutomaton(self._words)
        self.base_url = 'http://www.aminer.cn/profile/{}' 
开发者ID:AMinerOpen,项目名称:prediction_api,代码行数:9,代码来源:expertrec.py

示例3: load_fasttext_model

# 需要导入模块: import fastText [as 别名]
# 或者: from fastText import load_model [as 别名]
def load_fasttext_model(path):
    """
    Load a binarized fastText model.
    """
    try:
        import fastText
    except ImportError:
        raise Exception("Unable to import fastText. Please install fastText for Python: "
                        "https://github.com/facebookresearch/fastText")
    return fastText.load_model(path) 
开发者ID:violet-zct,项目名称:DeMa-BWE,代码行数:12,代码来源:eval.py

示例4: make_embeddings_simple_in_memory

# 需要导入模块: import fastText [as 别名]
# 或者: from fastText import load_model [as 别名]
def make_embeddings_simple_in_memory(self, name="fasttext-crawl"):
        nbWords = 0
        print('loading embeddings...')
        begin = True
        description = self._get_description(name)
        if description is not None:
            embeddings_path = description["path"]
            embeddings_type = description["type"]
            self.lang = description["lang"]
            print("path:", embeddings_path)
            if self.extension == 'bin':
                self.model = fastText.load_model(embeddings_path)
                nbWords = len(self.model.get_words())
                self.embed_size = self.model.get_dimension()
            else:
                with open(embeddings_path, encoding='utf8') as f:
                    for line in f:
                        line = line.strip()
                        line = line.split(' ')
                        if begin:
                            begin = False
                            nb_words, embed_size = fetch_header_if_available(line)

                            # we parse the header
                            if nb_words > 0 and embed_size > 0:
                                nbWords = nb_words
                                self.embed_size = embed_size
                                continue

                        word = line[0]
                        #if embeddings_type == 'glove':
                        vector = np.array([float(val) for val in line[1:len(line)]], dtype='float32')
                        #else:
                        #    vector = np.array([float(val) for val in line[1:len(line)-1]], dtype='float32')
                        if self.embed_size == 0:
                            self.embed_size = len(vector)
                        self.model[word] = vector
                if nbWords == 0:
                    nbWords = len(self.model)
            print('embeddings loaded for', nbWords, "words and", self.embed_size, "dimensions") 
开发者ID:kermitt2,项目名称:delft,代码行数:42,代码来源:Embeddings.py

示例5: before_request

# 需要导入模块: import fastText [as 别名]
# 或者: from fastText import load_model [as 别名]
def before_request():
    g.ft_model = fastText.load_model(app.config["FT_SERVER_MODEL_PATH"]) 
开发者ID:dfederschmidt,项目名称:fasttext-server,代码行数:4,代码来源:server.py

示例6: load

# 需要导入模块: import fastText [as 别名]
# 或者: from fastText import load_model [as 别名]
def load(self, embedding_fname, embedding_url=None, *args, **kwargs):
        """
        Method initializes dict of embeddings from file
        Args:
            fname: file name

        Returns:
            Nothing
        """

        if not embedding_fname:
            raise RuntimeError('Please, provide path to model')
        fasttext_model_file = embedding_fname

        if not Path(fasttext_model_file).is_file():
            emb_path = embedding_url
            if not emb_path:
                raise RuntimeError('Fasttext model file does not exist locally. URL does not contain  fasttext model file')
            embedding_fname = Path(fasttext_model_file).name
            try:
                download(dest_file_path=fasttext_model_file, source_url=embedding_url)
            except Exception as e:
                raise RuntimeError('Looks like the `EMBEDDINGS_URL` variable is set incorrectly', e)

        if self.module == "fastText":
            import fastText
            self.fasttext_model = fastText.load_model(fasttext_model_file)
        if self.module == "fasttext":
            import fasttext
            self.fasttext_model = fasttext.load_model(fasttext_model_file)
        return 
开发者ID:deepmipt,项目名称:intent_classifier,代码行数:33,代码来源:embedding_inferable.py


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