Skip to content

JSON export of model weights

Jack Gerrits edited this page Mar 14, 2022 · 4 revisions

This feature is experimental.

--dump_json_weights_experimental arg    Experimental: Output json representation of model parameters.
                                        (type: str)
--dump_json_weights_include_feature_names_experimental
                                        Experimental: Whether to include feature names in json output
                                        (type: bool)
--dump_json_weights_include_extra_online_state_experimental
                                        Experimental: Whether to include extra online state in json output
                                        (type: bool)

You can supply the option --dump_json_weights_experimental <file> to produce a JSON formatted representation of the contents of the model file.

  • Default output only contains values and indices
  • To enable feature names use --dump_json_weights_include_feature_names_experimental
    • Adds terms and offset properties
    • For scalar features terms is a single value
    • For interactions (-q ::), terms describes each component of the interaction
    • string_value is null unless --chain_hash is used
    • If there is no available inverse hash information for a given feature terms and offset will be null
    • Enabling dump_json_weights_include_feature_names_experimental will implicitly enable recording hash the lookup table like in --invert_hash. So the cost is similar to using --audit or --invert_hash
  • To enable online state use --dump_json_weights_include_extra_online_state_experimental
    • Adds gd_extra_online_state property
  • Currently can only be used when GD is the base learner

An example of a produced default JSON file:

{
    "weights": [
        {
            "index": 1924,
            "value": -0.14526426792144776
        },
        {
            "index": 1976,
            "value": 0.15885187685489655
        },
        {
            "index": 116060,
            "value": 0.07498351484537125
        },
        {
            "index": 162853,
            "value": 0.11804789304733277
        },
        {
            "index": 165201,
            "value": 0.037461891770362857
        },
        {
            "index": 229902,
            "value": 0.05265675485134125
        }
    ]
}

An example of a produced default JSON file with both --dump_json_weights_include_feature_names_experimental and --dump_json_weights_include_extra_online_state_experimental enabled:

{
    "weights": [
        {
            "terms": [
                {
                    "name": "1924",
                    "namespace": " ",
                    "string_value": null
                }
            ],
            "offset": 0,
            "index": 1924,
            "value": -0.14526426792144776,
            "gd_extra_online_state": {
                "adaptive": 4.0,
                "normalized": 1.0
            }
        },
        {
            "terms": [
                {
                    "name": "1976",
                    "namespace": " ",
                    "string_value": null
                }
            ],
            "offset": 0,
            "index": 1976,
            "value": 0.15885187685489655,
            "gd_extra_online_state": {
                "adaptive": 8.0,
                "normalized": 1.0
            }
        },
        {
            "terms": [
                {
                    "name": "Constant",
                    "namespace": "",
                    "string_value": null
                }
            ],
            "offset": 0,
            "index": 116060,
            "value": 0.07498351484537125,
            "gd_extra_online_state": {
                "adaptive": 12.0,
                "normalized": 1.0
            }
        },
        {
            "terms": [
                {
                    "name": "sqft",
                    "namespace": " ",
                    "string_value": null
                }
            ],
            "offset": 0,
            "index": 162853,
            "value": 0.11804789304733277,
            "gd_extra_online_state": {
                "adaptive": 0.5895999670028687,
                "normalized": 0.3199999928474426
            }
        },
        {
            "terms": [
                {
                    "name": "age",
                    "namespace": " ",
                    "string_value": null
                }
            ],
            "offset": 0,
            "index": 165201,
            "value": 0.037461891770362857,
            "gd_extra_online_state": {
                "adaptive": 4.007599830627441,
                "normalized": 0.8700000047683716
            }
        },
        {
            "terms": [
                {
                    "name": "price",
                    "namespace": " ",
                    "string_value": null
                }
            ],
            "offset": 0,
            "index": 229902,
            "value": 0.05265675485134125,
            "gd_extra_online_state": {
                "adaptive": 1.3827998638153077,
                "normalized": 0.5299999713897705
            }
        }
    ]
}

Potential future changes:

  • Support more base learners than GD
Clone this wiki locally