本文整理汇总了Python中allennlp.common.params.Params.as_dict方法的典型用法代码示例。如果您正苦于以下问题:Python Params.as_dict方法的具体用法?Python Params.as_dict怎么用?Python Params.as_dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类allennlp.common.params.Params
的用法示例。
在下文中一共展示了Params.as_dict方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: from_params
# 需要导入模块: from allennlp.common.params import Params [as 别名]
# 或者: from allennlp.common.params.Params import as_dict [as 别名]
def from_params(cls, optimizer: torch.optim.Optimizer, params: Params): # type: ignore
# pylint: disable=arguments-differ
scheduler = params.pop_choice("type", LearningRateScheduler.list_available())
schedulers = LearningRateScheduler.by_name(scheduler)(optimizer, **params.as_dict()) # type: ignore
if isinstance(schedulers, torch.optim.lr_scheduler.ReduceLROnPlateau):
return LearningRateWithMetricsWrapper(schedulers)
else:
return LearningRateWithoutMetricsWrapper(schedulers)
示例2: test_infer_and_cast
# 需要导入模块: from allennlp.common.params import Params [as 别名]
# 或者: from allennlp.common.params.Params import as_dict [as 别名]
def test_infer_and_cast(self):
lots_of_strings = {
"a": ["10", "1.3", "true"],
"b": {"x": 10, "y": "20.1", "z": "other things"},
"c": "just a string"
}
casted = {
"a": [10, 1.3, True],
"b": {"x": 10, "y": 20.1, "z": "other things"},
"c": "just a string"
}
assert infer_and_cast(lots_of_strings) == casted
contains_bad_data = {"x": 10, "y": int}
with pytest.raises(ValueError, match="cannot infer type"):
infer_and_cast(contains_bad_data)
params = Params(lots_of_strings)
assert params.as_dict() == lots_of_strings
assert params.as_dict(infer_type_and_cast=True) == casted
示例3: from_params
# 需要导入模块: from allennlp.common.params import Params [as 别名]
# 或者: from allennlp.common.params.Params import as_dict [as 别名]
def from_params(cls, params: Params): # type: ignore
return cls(**params.as_dict())
示例4: from_params
# 需要导入模块: from allennlp.common.params import Params [as 别名]
# 或者: from allennlp.common.params.Params import as_dict [as 别名]
def from_params(cls, params: Params, vocab: Optional[Vocabulary] = None):
metric_type = params.pop_choice("type", cls.list_available())
if vocab:
params["vocabulary"] = vocab
return cls.by_name(metric_type)(**params.as_dict()) # type: ignore
示例5: from_params
# 需要导入模块: from allennlp.common.params import Params [as 别名]
# 或者: from allennlp.common.params.Params import as_dict [as 别名]
def from_params(cls, optimizer: torch.optim.Optimizer, params: Params):
scheduler = params.pop_choice("type", LearningRateScheduler.list_available())
return LearningRateScheduler.by_name(scheduler)(optimizer, **params.as_dict()) # type: ignore