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


Python Predictor.from_archive方法代码示例

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


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

示例1: predict_model_with_archive

# 需要导入模块: from allennlp.predictors.predictor import Predictor [as 别名]
# 或者: from allennlp.predictors.predictor.Predictor import from_archive [as 别名]
def predict_model_with_archive(predictor: str, params: Params, archive: str,
                               input_file: str, output_file: str, batch_size: int = 1):
    cuda_device = params["trainer"]["cuda_device"]

    check_for_gpu(cuda_device)
    archive = load_archive(archive,
                           cuda_device=cuda_device)

    predictor = Predictor.from_archive(archive, predictor)

    manager = _PredictManager(predictor,
                              input_file,
                              output_file,
                              batch_size,
                              print_to_console=False,
                              has_dataset_reader=True)
    manager.run() 
开发者ID:Hyperparticle,项目名称:udify,代码行数:19,代码来源:util.py

示例2: _get_predictor

# 需要导入模块: from allennlp.predictors.predictor import Predictor [as 别名]
# 或者: from allennlp.predictors.predictor.Predictor import from_archive [as 别名]
def _get_predictor(args: argparse.Namespace) -> Predictor:
    check_for_gpu(args.cuda_device)
    archive = load_archive(
        args.archive_file,
        weights_file=args.weights_file,
        cuda_device=args.cuda_device,
        overrides=args.overrides,
    )

    return Predictor.from_archive(
        archive, args.predictor, dataset_reader_to_load=args.dataset_reader_choice
    ) 
开发者ID:allenai,项目名称:allennlp,代码行数:14,代码来源:predict.py

示例3: _get_predictor

# 需要导入模块: from allennlp.predictors.predictor import Predictor [as 别名]
# 或者: from allennlp.predictors.predictor.Predictor import from_archive [as 别名]
def _get_predictor(args                    )             :
    check_for_gpu(args.cuda_device)
    archive = load_archive(args.archive_file,
                           weights_file=args.weights_file,
                           cuda_device=args.cuda_device,
                           overrides=args.overrides)

    return Predictor.from_archive(archive, args.predictor) 
开发者ID:plasticityai,项目名称:magnitude,代码行数:10,代码来源:predict.py

示例4: __init__

# 需要导入模块: from allennlp.predictors.predictor import Predictor [as 别名]
# 或者: from allennlp.predictors.predictor.Predictor import from_archive [as 别名]
def __init__(self, name: str, 
        model_path: str=None,
        model_online_path: str=None,
        description: str='',
        model_type: str=None) -> None:
        """A class specifically created for wrapping the predictors from 
        Allennlp: https://allenai.github.io/allennlp-docs/api/allennlp.predictors.html
        
        Parameters
        ----------
        name : str
        The name of the predictor.
        model_path : str, optional
            A local model path if you are using local models, by default None.
            This and ``model_online_path`` cannot both be None.
        model_online_path : str, optional
            An online model path, by default None
        description : str, optional
            A sentence describing the predictor., by default ''
        model_type : str, optional
            The model type as used in Allennlp, by default None
        
        Returns
        -------
        None
        """
        model = None
        model_path = model_path or model_online_path
        if model_path:
            if torch.cuda.is_available():
                archive = load_archive(model_path, cuda_device=0)
            else:    
                archive = load_archive(model_path)
            model = AllenPredictor.from_archive(archive, model_type)
        self.predictor = model
        Predictor.__init__(self, name, description, model, ['accuracy']) 
开发者ID:uwdata,项目名称:errudite,代码行数:38,代码来源:predictor_allennlp.py

示例5: _get_predictor

# 需要导入模块: from allennlp.predictors.predictor import Predictor [as 别名]
# 或者: from allennlp.predictors.predictor.Predictor import from_archive [as 别名]
def _get_predictor(args: argparse.Namespace) -> Predictor:
    check_for_gpu(args.cuda_device)
    archive = load_archive(args.archive_file,
                           weights_file=args.weights_file,
                           cuda_device=args.cuda_device,
                           overrides=args.overrides)

    return Predictor.from_archive(archive, args.predictor) 
开发者ID:StonyBrookNLP,项目名称:multee,代码行数:10,代码来源:predict_with_vocab_expansion.py


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