本文整理汇总了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)