commandline

package
v0.28.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 16, 2026 License: Apache-2.0 Imports: 20 Imported by: 1 module, 21 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package commandline contains convenience UI training tools for the command line.

Index

Constants

View Source
const ProgressBarName = "gomlx.ml.train.commandline.progressBar"

Variables

View Source
var ProgressbarStyle = progressbar.ThemeASCII

ProgressbarStyle to use. Defaults to the ASCII version. Consider "progressbar.ThemeUnicode" for a prettier version. But it requires some of the graphical symbols to be supported.

View Source
var RefreshPeriod = time.Second * 3

RefreshPeriod is the time between terminal updates.

Functions

func AttachProgressBar

func AttachProgressBar(loop *train.Loop, extraMetrics ...ExtraMetricFn)

AttachProgressBar creates a commandline progress bar and attaches it to the Loop, so that everytime Loop is run, it will display a progress bar with progression and metrics.

The associated data will be attached to the train.Loop, so nothing is returned.

Optionally, one can provide extraMetrics: functions that are called at every update of the progress bar and should return a name (title) and a value to be included in the updated print-out.

func CreateSettingsFlag added in v0.28.0

func CreateSettingsFlag(store *model.Store, flagName string) *string

CreateSettingsFlag create a string flag with the given flagName (if empty it will be named "set") and with a description of the current defined parameters in the context `scope`.

The flag should be created before the call to `flags.Parse()`.

Example usage:

func main() {
	store := createModelStore()
	settings := commandline.CreateSettingsFlag(store, "")
	flag.Parse()
	err := commandline.ParseSettings(store, *settings)
	if err != nil { panic(err) }
	fmt.Println(commandline.SprintSettings(scope))
	...
}

func FormatDuration added in v0.21.0

func FormatDuration(d time.Duration) string

FormatDuration pretty prints a duration (without a long list of decimal points).

func ParseSettings added in v0.28.0

func ParseSettings(store *model.Store, settings string) (modifiedParams []string, err error)

ParseScopeSettings from settings -- typically the contents of a flag set by the user. The settings are a list separated by ";": e.g.: "param1=value1;param2=value2;...".

All the parameters "param1", "param2", etc. must be already set with default values in the context `scope`. The default values are also used to set the type to which the string values will be parsed to.

It updates `scope` parameters accordingly and returns an error in case a parameter is unknown or the parsing failed.

Note, one can also provide a scope for the parameters: "layer_1/l2_regularization=0.1" will work, as long as a default "l2_regularization" is defined in `scope`.

For integer types, "_" is removed: it allows one to enter large numbers using it as a separator, like in Go. E.g.: 1_000_000 = 1000000.

See the example in CreateScopeSettingsFlag, which will create a flag for the settings.

Example usage:

func main() {
	store := createDefaultModelStore()
	settings := commandline.CreateScopeSettingsFlag(store.RootScope(), "")
	flag.Parse()
	err := commandline.ParseScopeSettings(store.RootScope(), *settings)
	if err != nil { panic(err) }
	fmt.Println(commandline.SprintScopeSettings(scope))
	...
}

func ReportEval

func ReportEval(trainer *train.Trainer, datasets ...train.Dataset) error

ReportEval reports on the command line the results of evaluating the datasets using trainer.Eval.

func SprintModifiedSettings added in v0.28.0

func SprintModifiedSettings(storeOrScope model.StoreProvider, modifiedParams []string) string

SprintModifiedSettings pretty-print values of the modified settings into a string.

func SprintSettings added in v0.28.0

func SprintSettings(storeOrScope model.StoreProvider) string

SprintSettings pretty-print values for the current hyperparameters settings into a string.

Types

type ExtraMetricFn added in v0.21.0

type ExtraMetricFn func() (name, value string)

ExtraMetricFn is any function that will give extra values to display along the progress bar. It is called at each time the progress bar is updated, and it should return a name and the current value when it is called.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL