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


Python Params.as_dict方法代码示例

本文整理汇总了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)
开发者ID:apmoore1,项目名称:allennlp,代码行数:11,代码来源:learning_rate_schedulers.py

示例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
开发者ID:apmoore1,项目名称:allennlp,代码行数:25,代码来源:params_test.py

示例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())
开发者ID:pyknife,项目名称:allennlp,代码行数:4,代码来源:initializers.py

示例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
开发者ID:Jordan-Sauchuk,项目名称:allennlp,代码行数:7,代码来源:metric.py

示例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
开发者ID:Jordan-Sauchuk,项目名称:allennlp,代码行数:5,代码来源:learning_rate_schedulers.py


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