tensorflow_decision_forests/keras/wrapper/wrapper.cc
// Generates the python documentation and python object for the pre-defined
// hyper-parameters.
Generates the python documentation and python object for the pre-defined
hyper-parameters.
Generates the python documentation and python object for the pre - defined hyper - parameters .
ydf::utils::StatusOr<std::pair<std::string, std::string>>
BuildPredefinedHyperParameter(const ydf::model::AbstractLearner* learner) {
  std::string predefined_hp_doc;
  std::string predefined_hp_list = "[";
  const auto predefined_hyper_parameter_sets =
      learner->PredefinedHyperParameters();
  for (const auto& predefined : predefined_hyper_parameter_sets) {
    absl::SubstituteAndAppend(
        &predefined_hp_doc,
        "        - $0@v$1: $2 The parameters are: ", predefined.name(),
        predefined.version(), predefined.description());
    absl::SubstituteAndAppend(
        &predefined_hp_list,
        "core.HyperParameterTemplate(name=\"$0\", "
        "version=$1, description=\"$2\", parameters={",
        predefined.name(), predefined.version(),
        absl::StrReplaceAll(predefined.description(), {{"\"", "\\\""}}));
    bool first_field = true;
    for (const auto& field : predefined.parameters().fields()) {
      if (first_field) {
        first_field = false;
      } else {
        absl::StrAppend(&predefined_hp_doc, ", ");
        absl::StrAppend(&predefined_hp_list, ", ");
      }
      absl::StrAppend(&predefined_hp_doc, field.name(), "=");
      absl::StrAppend(&predefined_hp_list, "\"", field.name(), "\" :");
      switch (field.value().Type_case()) {
        case ydf::model::proto::GenericHyperParameters_Value::TYPE_NOT_SET:
          return absl::InternalError("Non configured value");
          break;
        case ydf::model::proto::GenericHyperParameters_Value::kCategorical: {
          std::string value = field.value().categorical();
          if (value == "true" || value == "false") {
            value = (value == "true") ? "True" : "False";
          } else {
            value = absl::StrCat("\"", value, "\"");
          }
          absl::StrAppend(&predefined_hp_doc, value);
          absl::StrAppend(&predefined_hp_list, value);
        } break;
        case ydf::model::proto::GenericHyperParameters_Value::kInteger:
          absl::StrAppend(&predefined_hp_doc, field.value().integer());
          absl::StrAppend(&predefined_hp_list, field.value().integer());
          break;
        case ydf::model::proto::GenericHyperParameters_Value::kReal:
          absl::StrAppend(&predefined_hp_doc,
                          PythonFloat(field.value().real()));
          absl::StrAppend(&predefined_hp_list,
                          PythonFloat(field.value().real()));
          break;
        case ydf::model::proto::GenericHyperParameters_Value::kCategoricalList:
          absl::StrAppend(
              &predefined_hp_doc, "[",
              absl::StrJoin(field.value().categorical_list().values(), ","),
              "]");
          absl::StrAppend(
              &predefined_hp_list, "[",
              absl::StrJoin(field.value().categorical_list().values(), ","),
              "]");
          break;
      }
    }
    absl::SubstituteAndAppend(&predefined_hp_doc, ".\n");
    absl::SubstituteAndAppend(&predefined_hp_list, "}),");
  }
  absl::StrAppend(&predefined_hp_list, "]");
  return std::pair<std::string, std::string>(predefined_hp_doc,
                                             predefined_hp_list);
}
ydf :: utils :: StatusOr < std :: pair < std :: string , std :: string > > BuildPredefinedHyperParameter ( const ydf :: model :: AbstractLearner * learner ) { std :: string predefined_hp_doc ; std :: string predefined_hp_list = " " ; const auto predefined_hyper_parameter_sets = learner -> PredefinedHyperParameters ( ) ; for ( const auto & predefined : predefined_hyper_parameter_sets ) { absl :: SubstituteAndAppend ( & predefined_hp_doc , " " , predefined . name ( ) , predefined . version ( ) , predefined . description ( ) ) ; absl :: SubstituteAndAppend ( & predefined_hp_list , " \" \" " " \" \" " , predefined . name ( ) , predefined . version ( ) , absl :: StrReplaceAll ( predefined . description ( ) , { { " \" " , " \\ \" " } } ) ) ; bool first_field = true ; for ( const auto & field : predefined . parameters ( ) . fields ( ) ) { if ( first_field ) { first_field = false ; } else { absl :: StrAppend ( & predefined_hp_doc , " " ) ; absl :: StrAppend ( & predefined_hp_list , " " ) ; } absl :: StrAppend ( & predefined_hp_doc , field . name ( ) , " " ) ; absl :: StrAppend ( & predefined_hp_list , " \" " , field . name ( ) , " \" " ) ; switch ( field . value ( ) . Type_case ( ) ) { case ydf :: model :: proto :: GenericHyperParameters_Value :: TYPE_NOT_SET : return absl :: InternalError ( " " ) ; break ; case ydf :: model :: proto :: GenericHyperParameters_Value :: kCategorical : { std :: string value = field . value ( ) . categorical ( ) ; if ( value == " " || value == " " ) { value = ( value == " " ) ? " " : " " ; } else { value = absl :: StrCat ( " \" " , value , " \" " ) ; } absl :: StrAppend ( & predefined_hp_doc , value ) ; absl :: StrAppend ( & predefined_hp_list , value ) ; } break ; case ydf :: model :: proto :: GenericHyperParameters_Value :: kInteger : absl :: StrAppend ( & predefined_hp_doc , field . value ( ) . integer ( ) ) ; absl :: StrAppend ( & predefined_hp_list , field . value ( ) . integer ( ) ) ; break ; case ydf :: model :: proto :: GenericHyperParameters_Value :: kReal : absl :: StrAppend ( & predefined_hp_doc , PythonFloat ( field . value ( ) . real ( ) ) ) ; absl :: StrAppend ( & predefined_hp_list , PythonFloat ( field . value ( ) . real ( ) ) ) ; break ; case ydf :: model :: proto :: GenericHyperParameters_Value :: kCategoricalList : absl :: StrAppend ( & predefined_hp_doc , " " , absl :: StrJoin ( field . value ( ) . categorical_list ( ) . values ( ) , " " ) , " " ) ; absl :: StrAppend ( & predefined_hp_list , " " , absl :: StrJoin ( field . value ( ) . categorical_list ( ) . values ( ) , " " ) , " " ) ; break ; } } absl :: SubstituteAndAppend ( & predefined_hp_doc , " \n " ) ; absl :: SubstituteAndAppend ( & predefined_hp_list , " " ) ; } absl :: StrAppend ( & predefined_hp_list , " " ) ; return std :: pair < std :: string , std :: string > ( predefined_hp_doc , predefined_hp_list ) ; }
Generates the python documentation and python object for the pre-defined
hyper-parameters.
Generates the python documentation and python object for the pre - defined hyper - parameters .
// Documentation about the list of template hyper-parameters. // Python list of template hyper-parameters. // Iterate over the individual parameters.