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


Python _jsonnet.evaluate_file方法代码示例

本文整理汇总了Python中_jsonnet.evaluate_file方法的典型用法代码示例。如果您正苦于以下问题:Python _jsonnet.evaluate_file方法的具体用法?Python _jsonnet.evaluate_file怎么用?Python _jsonnet.evaluate_file使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在_jsonnet的用法示例。


在下文中一共展示了_jsonnet.evaluate_file方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_dump_best_config

# 需要导入模块: import _jsonnet [as 别名]
# 或者: from _jsonnet import evaluate_file [as 别名]
def test_dump_best_config() -> None:
    with tempfile.TemporaryDirectory() as tmp_dir:

        def objective(trial: optuna.Trial) -> float:
            trial.suggest_uniform("DROPOUT", dropout, dropout)
            executor = optuna.integration.AllenNLPExecutor(trial, input_config_file, tmp_dir)
            return executor.run()

        dropout = 0.5
        input_config_file = os.path.join(
            os.path.dirname(os.path.realpath(__file__)), "example.jsonnet"
        )
        output_config_file = os.path.join(tmp_dir, "result.json")

        study = optuna.create_study(direction="maximize")
        study.optimize(objective, n_trials=1)

        optuna.integration.allennlp.dump_best_config(input_config_file, output_config_file, study)
        best_config = json.loads(_jsonnet.evaluate_file(output_config_file))
        model_config = best_config["model"]
        target_config = model_config["text_field_embedder"]["token_embedders"]["token_characters"]
        assert target_config["dropout"] == dropout 
开发者ID:optuna,项目名称:optuna,代码行数:24,代码来源:test_allennlp.py

示例2: dump_best_config

# 需要导入模块: import _jsonnet [as 别名]
# 或者: from _jsonnet import evaluate_file [as 别名]
def dump_best_config(input_config_file: str, output_config_file: str, study: optuna.Study) -> None:
    """Save JSON config file after updating with parameters from the best trial in the study.

    Args:
        input_config_file:
            Input Jsonnet config file used with
            :class:`~optuna.integration.AllenNLPExecutor`.
        output_config_file:
            Output JSON config file.
        study:
            Instance of :class:`~optuna.study.Study`.
            Note that :func:`~optuna.study.Study.optimize` must have been called.

    """
    _imports.check()

    best_params = study.best_params
    for key, value in best_params.items():
        best_params[key] = str(value)
    best_config = json.loads(_jsonnet.evaluate_file(input_config_file, ext_vars=best_params))
    best_config = allennlp.common.params.infer_and_cast(best_config)

    with open(output_config_file, "w") as f:
        json.dump(best_config, f, indent=4) 
开发者ID:optuna,项目名称:optuna,代码行数:26,代码来源:allennlp.py

示例3: _build_params

# 需要导入模块: import _jsonnet [as 别名]
# 或者: from _jsonnet import evaluate_file [as 别名]
def _build_params(self) -> Dict[str, Any]:
        """Create a dict of params for AllenNLP.

        _build_params is based on allentune's train_func.
        For more detail, please refer to
        https://github.com/allenai/allentune/blob/master/allentune/modules/allennlp_runner.py#L34-L65

        """
        params = self._environment_variables()
        params.update({key: str(value) for key, value in self._params.items()})

        allennlp_params = json.loads(_jsonnet.evaluate_file(self._config_file, ext_vars=params))
        # allennlp_params contains a list of string or string as value values.
        # Some params couldn't be casted correctly and
        # infer_and_cast converts them into desired values.
        return allennlp.common.params.infer_and_cast(allennlp_params) 
开发者ID:optuna,项目名称:optuna,代码行数:18,代码来源:allennlp.py

示例4: jsonnet_load_file

# 需要导入模块: import _jsonnet [as 别名]
# 或者: from _jsonnet import evaluate_file [as 别名]
def jsonnet_load_file(file_name):
    """
    Parses jsonnet file into jsonnet
    :param file_name: Jsonnet file
    :return:
    """
    json_parse = json.loads(_jsonnet.evaluate_file(file_name))

    return json_parse 
开发者ID:allenai,项目名称:OpenBookQA,代码行数:11,代码来源:jsonnet.py

示例5: evaluate_file

# 需要导入模块: import _jsonnet [as 别名]
# 或者: from _jsonnet import evaluate_file [as 别名]
def evaluate_file(filename: str, **_kwargs) -> str:
        logger.warning(
            f"error loading _jsonnet (this is expected on Windows), treating {filename} as plain json"
        )
        with open(filename, "r") as evaluation_file:
            return evaluation_file.read() 
开发者ID:allenai,项目名称:allennlp,代码行数:8,代码来源:params.py

示例6: from_file

# 需要导入模块: import _jsonnet [as 别名]
# 或者: from _jsonnet import evaluate_file [as 别名]
def from_file(
        cls, params_file: str, params_overrides: str = "", ext_vars: dict = None
    ) -> "Params":
        """
        Load a `Params` object from a configuration file.

        # Parameters

        params_file: `str`

            The path to the configuration file to load.

        params_overrides: `str`, optional

            A dict of overrides that can be applied to final object.
            e.g. {"model.embedding_dim": 10}

        ext_vars: `dict`, optional

            Our config files are Jsonnet, which allows specifying external variables
            for later substitution. Typically we substitute these using environment
            variables; however, you can also specify them here, in which case they
            take priority over environment variables.
            e.g. {"HOME_DIR": "/Users/allennlp/home"}
        """
        if ext_vars is None:
            ext_vars = {}

        # redirect to cache, if necessary
        params_file = cached_path(params_file)
        ext_vars = {**_environment_variables(), **ext_vars}

        file_dict = json.loads(evaluate_file(params_file, ext_vars=ext_vars))

        overrides_dict = parse_overrides(params_overrides)
        param_dict = with_fallback(preferred=overrides_dict, fallback=file_dict)

        return cls(param_dict) 
开发者ID:allenai,项目名称:allennlp,代码行数:40,代码来源:params.py

示例7: evaluate

# 需要导入模块: import _jsonnet [as 别名]
# 或者: from _jsonnet import evaluate_file [as 别名]
def evaluate(self, *args, **kwargs):
    kwargs['import_callback'] = self._import_callback
    kwargs['native_callbacks'] = self._native_callbacks
    return json.loads(_jsonnet.evaluate_file(*args, **kwargs)) 
开发者ID:google,项目名称:kasane,代码行数:6,代码来源:jsonnet.py

示例8: evaluate_file

# 需要导入模块: import _jsonnet [as 别名]
# 或者: from _jsonnet import evaluate_file [as 别名]
def evaluate_file(filename     , **_kwargs)       :
        logger.warning("_jsonnet not loaded, treating {filename} as json")
        with open(filename, u'r') as evaluation_file:
            return evaluation_file.read() 
开发者ID:plasticityai,项目名称:magnitude,代码行数:6,代码来源:params.py

示例9: from_file

# 需要导入模块: import _jsonnet [as 别名]
# 或者: from _jsonnet import evaluate_file [as 别名]
def from_file(params_file     , params_overrides      = u"")            :
        u"""
        Load a `Params` object from a configuration file.
        """
        # redirect to cache, if necessary
        params_file = cached_path(params_file)
        ext_vars = dict(os.environ)

        file_dict = json.loads(evaluate_file(params_file, ext_vars=ext_vars))

        overrides_dict = parse_overrides(params_overrides)
        param_dict = with_fallback(preferred=overrides_dict, fallback=file_dict)

        return Params(param_dict) 
开发者ID:plasticityai,项目名称:magnitude,代码行数:16,代码来源:params.py

示例10: evaluate_file

# 需要导入模块: import _jsonnet [as 别名]
# 或者: from _jsonnet import evaluate_file [as 别名]
def evaluate_file(filename: str, **_kwargs) -> str:
        logger.warning(f"_jsonnet not loaded, treating {filename} as json")
        with open(filename, 'r') as evaluation_file:
            return evaluation_file.read() 
开发者ID:uwdata,项目名称:errudite,代码行数:6,代码来源:params.py


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