當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。