本文整理匯總了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()
示例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
)
示例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)
示例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'])
示例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)