tools.lossWeights

Help Info

Read in a model history json and calculate theprofile/counts loss ratio.

usage: lossWeights [-h] [--json JSON]
                   [--target-ratio TARGETRATIO]
                   [--prev-weight PREVWEIGHT]

Named Arguments

--json

The name of the history json file

--target-ratio

(optional) What counts loss weight do you want to have? A float from [0,∞), with 0 meaning no counts weight, 1 meaning equal weight between counts and profile. A normal setting would be 0.1. Use the output to set counts-loss-weight in your training configuration files.

Default: 0.0

--prev-weight

The counts-loss-weight you used to train your model. If provided, the printed ratios will be scaled by this number to reflect their actual contribution in your model.

Default: 1.0

Usage

Extract loss weights that should be used to train a model.

This is a little utility to read in the training history json and calculate an appropriate counts loss weight parameter to get the loss balance you want. Since we only know how large the losses for profile and counts will be after we’ve trained a model, you have to use this script after training a burner model in order to find appropriate settings, then use those to re-train your model. How to use: First, pick a counts-loss-weight that sounds reasonable, like 10. Train a model. Run this script on the history json from that training, giving it a desired ratio of counts to profile loss.

Note that this script is not necessary if you’re using the adaptive counts loss algorithm.

bpreveal.tools.lossWeights.loadLosses(lossStats)

Read in the losses from the history file.

Parameters:

lossStats (dict)

Return type:

dict[str, dict[str, float]]

bpreveal.tools.lossWeights.addLossRatios(lossByHead, targetRatio)

Adds in ratio information to the loss dict.

Parameters:
  • lossByHead (dict) – The loss dict for a given head.

  • targetRatio (float) – The fraction of the loss that you’d like to be due to

Return type:

None

bpreveal.tools.lossWeights.main(jsonFname, targetRatio, prevWeight)

Read in the loss history and estimate an appropriate new weight.

Parameters:
  • jsonFname (str) – The name of the history file.

  • targetRatio (float) – The fraction of the loss that you’d like to be due to counts.

  • prevWeight (float) – The counts-loss-weight used to train the model.

Return type:

None

bpreveal.tools.lossWeights.getParser()

Load (but don’t parse_args()) the argument parser.

Return type:

ArgumentParser