worker

package
v1.18.6 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package worker is Hermod's client for its hermod-ml worker: the Python process that holds datasets, trains models on them, exports each one to ONNX and serves it over the Open Inference Protocol.

Hermod stays the source of truth for which model a vhost calls and which version is live; the worker holds the data and the model files. Predictions do not go through this package: a trained model is called like any other Open Inference Protocol server, through pkg/ml/inference, at ServingURL.

Index

Constants

View Source
const (
	StatsNumeric     = "numeric"
	StatsCategorical = "categorical"
)

The kinds of FeatureStats.

View Source
const (
	EngineBuiltin = "builtin"
	EngineWorker  = "worker"

	// BuiltinVersionPrefix starts every version the built-in engine trains.
	BuiltinVersionPrefix = "b"
)

The engines that train Hermod's models: its built-in one, in Hermod's own process, and the hermod-ml worker. A version says which (Version.Engine), and so does its id: the worker numbers its versions 1, 2, …, and the built-in engine b1, b2, …, so two versions of one model never share an id whichever engine trained them, and a model's live version alone says which engine scores it.

View Source
const (
	DefaultTrainTimeout = 30 * time.Minute
)

Timeouts. A training is synchronous and can take minutes; everything else is a quick call. HERMOD_ML_TRAIN_TIMEOUT overrides the first.

View Source
const LocalURL = "http://hermod-ml.local"

LocalURL is the base URL of a Client built with NewLocal. Its calls never leave the process, so it names no host on any network.

View Source
const TaskRecommendation = "recommendation"

TaskRecommendation is the task of a model that recommends items to people (ml/worker/hermod_ml/recommend.py) rather than predicting a column.

Variables

View Source
var (
	// ErrNotFound is returned when the worker has no such dataset, model or
	// version.
	ErrNotFound = errors.New("not found on the ML worker")
	// ErrBusy is returned when the worker is already running as many
	// trainings as it allows.
	ErrBusy = errors.New("the ML worker is busy training")
	// ErrUnauthorized is returned when the worker refuses Hermod's token:
	// it is not the worker's HERMOD_ML_TOKEN.
	ErrUnauthorized = errors.New("the ML worker refused the token")
)

Default is the process's provider. Every caller that needs the worker asks it, so a worker saved from the console reaches training, datasets and the Collect Dataset sink at once.

Functions

func BuiltinVersion added in v1.18.2

func BuiltinVersion(n int) string

BuiltinVersion is the built-in engine's version id for number n.

func EngineOf added in v1.18.2

func EngineOf(v string) string

EngineOf is the engine that holds version v.

func IsBuiltinVersion added in v1.18.2

func IsBuiltinVersion(v string) bool

IsBuiltinVersion reports whether the built-in engine trained version v.

func ParseBuiltinVersion added in v1.18.2

func ParseBuiltinVersion(v string) (int, bool)

ParseBuiltinVersion is the number of a built-in version id ("b3" is 3), and false for anything else, the worker's ids included.

func ValidateURL added in v1.18.1

func ValidateURL(raw string) (string, error)

ValidateURL checks a worker address and returns it without surrounding space or a trailing slash. It must be an absolute http or https URL with a host, and carry no credentials, query or fragment: the token goes in its own field, never in a URL that ends up in logs.

Types

type Capabilities

type Capabilities struct {
	Tasks       []string          `json:"tasks"`
	Algorithms  []string          `json:"algorithms"`
	Unavailable map[string]string `json:"unavailable"`
}

Capabilities is what a worker can train. The slim image cannot train the deep-learning algorithms; Unavailable says why, per algorithm.

type Catalog

type Catalog struct {
	Users int `json:"users"`
	Items int `json:"items"`
}

Catalog is how many people and items a recommendation model knows.

type CategoryShare

type CategoryShare struct {
	Value    string  `json:"value"`
	Fraction float64 `json:"fraction"`
}

CategoryShare is one value of a categorical feature and its share.

type CheckWarning

type CheckWarning struct {
	Code    string `json:"code"`
	Message string `json:"message"`
	Column  string `json:"column,omitempty"`
}

CheckWarning is one pre-flight note. Code is few_rows, imbalanced, id_like, constant, mostly_empty, leak_suspect or many_classes.

type Client

type Client struct {
	// URL is the worker's base URL, without a trailing slash.
	URL string
	// Token, when set, is sent as a bearer token on every call.
	Token string
	// TrainTimeout bounds one training call.
	TrainTimeout time.Duration
	// contains filtered or unexported fields
}

Client calls one hermod-ml worker.

func Configure added in v1.18.1

func Configure(baseURL, token string) *Client

Configure returns a client for the worker at baseURL, with HERMOD_ML_TRAIN_TIMEOUT applied when set, on Hermod's data client.

func FromEnv

func FromEnv() *Client

FromEnv returns the worker named by HERMOD_ML_WORKER_URL and HERMOD_ML_WORKER_TOKEN, or nil when no worker is configured.

func New

func New(baseURL, token string, hc *http.Client) *Client

New returns a client for the worker at baseURL. hc may be nil for Hermod's data client, which reaches private addresses: the worker runs beside Hermod.

func NewLocal added in v1.18.2

func NewLocal(l Local) *Client

NewLocal returns a client whose calls l answers in-process, with HERMOD_ML_TRAIN_TIMEOUT applied when set.

func PoolFromEnv

func PoolFromEnv(prefix string) *Client

PoolFromEnv returns the worker named by PREFIX_URL and PREFIX_TOKEN (for example HERMOD_ML_CUSTOM_WORKER_URL), or nil when PREFIX_URL is empty. The training timeout is HERMOD_ML_TRAIN_TIMEOUT, as for the main worker.

func (*Client) AppendRows

func (c *Client) AppendRows(ctx context.Context, vhost, dataset string, rows []map[string]any, replace bool) (int, error)

AppendRows adds rows to a dataset, first emptying it when replace is set, and returns how many rows the dataset holds now.

func (*Client) Capabilities

func (c *Client) Capabilities(ctx context.Context) (Capabilities, error)

Capabilities asks the worker what it can train. A worker older than this call answers ErrNotFound.

func (*Client) Dataset

func (c *Client) Dataset(ctx context.Context, vhost, dataset string) (DatasetInfo, error)

Dataset describes one dataset, with a sample of its rows.

func (*Client) Datasets

func (c *Client) Datasets(ctx context.Context, vhost string) ([]DatasetInfo, error)

Datasets lists a vhost's datasets.

func (*Client) DeleteDataset

func (c *Client) DeleteDataset(ctx context.Context, vhost, dataset string) error

DeleteDataset removes a dataset.

func (*Client) DeleteModel

func (c *Client) DeleteModel(ctx context.Context, vhost, model string) error

DeleteModel removes every version of a model.

func (*Client) ExportDataset

func (c *Client) ExportDataset(ctx context.Context, vhost, dataset string) (io.ReadCloser, error)

ExportDataset streams the whole dataset as one parquet file. The caller closes the reader.

func (*Client) ExportVersion

func (c *Client) ExportVersion(ctx context.Context, vhost, model, version string) (io.ReadCloser, error)

ExportVersion streams one version, its meta and its ONNX file, as JSON. The caller closes the reader.

func (*Client) Forward added in v1.18.2

func (c *Client) Forward(w http.ResponseWriter, r *http.Request)

Forward sends a request for one of the worker's routes on to the worker, with the worker's token in place of any the request carried, and writes the worker's reply to w as it came. The request's context bounds the call. A worker that does not answer is a 502.

func (*Client) ImportDataset

func (c *Client) ImportDataset(ctx context.Context, vhost, dataset string, body io.Reader) (DatasetInfo, error)

ImportDataset replaces a dataset with a parquet file from ExportDataset.

func (*Client) ImportVersion

func (c *Client) ImportVersion(ctx context.Context, vhost, model, dataset string, body io.Reader) (Version, error)

ImportVersion adds a version from ExportVersion to the model, as its next version. dataset, when set, replaces the dataset name the version records: a pool trains on a copy under a name of its own. The worker checks the version as if it had never seen it, because it has not.

func (*Client) Local added in v1.18.2

func (c *Client) Local() Local

Local returns the in-process engine the client calls, or nil for a worker reached over HTTP.

func (*Client) ModelFile

func (c *Client) ModelFile(ctx context.Context, vhost, model, version string) ([]byte, error)

ModelFile returns the ONNX graph a version of a model serves, for scoring it in-process.

func (*Client) Ready

func (c *Client) Ready(ctx context.Context) error

Ready reports whether the worker answers its readiness check.

func (*Client) RecommendCheck

func (c *Client) RecommendCheck(ctx context.Context, vhost string, spec TrainSpec) (RecommendHealth, error)

RecommendCheck runs a recommendation scenario's data health check on a vhost's datasets: spec names the scenario and its data roles. It trains nothing and takes no training slot.

func (*Client) RecommenderFile

func (c *Client) RecommenderFile(ctx context.Context, vhost, model, version string) ([]byte, error)

RecommenderFile returns the artifact a recommendation version serves, for serving it in-process (pkg/ml/recommend).

func (*Client) Remote added in v1.18.2

func (c *Client) Remote() *Client

Remote is the hermod-ml worker the client reaches over HTTP: the client itself for a worker, the worker an in-process engine routes to when it routes to one (it has a Remote method, as the built-in engine's router does), else nil.

func (*Client) ServingURL

func (c *Client) ServingURL(vhost string) string

ServingURL is the Open Inference Protocol base URL of a vhost's models.

func (*Client) Train

func (c *Client) Train(ctx context.Context, vhost, model string, spec TrainSpec) (Version, error)

Train trains a new version of the model and returns it. The call waits for the training to finish.

func (*Client) TrainCheck

func (c *Client) TrainCheck(ctx context.Context, vhost string, spec TrainSpec) (TrainCheck, error)

TrainCheck runs the pre-flight check of a training spec on a vhost's dataset. It trains nothing and takes no training slot.

func (*Client) TrainCustom

func (c *Client) TrainCustom(ctx context.Context, vhost, model string, spec TrainSpec, script Script) (Version, error)

TrainCustom trains a new version of the model with a custom script. Only a worker started with HERMOD_ML_CUSTOM_SCRIPTS=true runs one.

func (*Client) UploadFile

func (c *Client) UploadFile(ctx context.Context, vhost, dataset, format string, body io.Reader) (DatasetInfo, error)

UploadFile replaces a dataset with a CSV or Excel (.xlsx) file.

func (*Client) Versions

func (c *Client) Versions(ctx context.Context, vhost, model string) ([]Version, error)

Versions lists a model's versions, newest first.

type Column

type Column struct {
	Name string `json:"name"`
	Type string `json:"type"`
}

Column is one column of a dataset; Type is number, string or bool.

type ColumnCheck

type ColumnCheck struct {
	Name string `json:"name"`
	Type string `json:"type"`
	Role string `json:"role"`
	Note string `json:"note"`
}

ColumnCheck is one column's role: use, id_like, constant, mostly_empty, leak_suspect or target, with the reason in words (empty for use).

type DatasetInfo

type DatasetInfo struct {
	Name      string           `json:"name"`
	Rows      int              `json:"rows"`
	Columns   []Column         `json:"columns"`
	UpdatedAt time.Time        `json:"updated_at"`
	Sample    []map[string]any `json:"sample,omitempty"`
	// Engine holds the dataset: EngineBuiltin (Hermod's metadata store) or
	// EngineWorker, for one only a connected hermod-ml worker has.
	Engine string `json:"engine,omitempty"`
}

DatasetInfo describes a dataset. Sample holds its first rows when one dataset is asked for, and is empty in a list.

type FeatureStats

type FeatureStats struct {
	Kind string `json:"kind"`
	// Count is the rows measured; NullFraction the share with no usable value.
	Count        int     `json:"count"`
	NullFraction float64 `json:"null_fraction"`

	// Numeric: summary values, absent when every value was missing, and the
	// decile bins. Bin i holds Edges[i-1] < v <= Edges[i]; Fractions has one
	// more entry than Edges, each bin's share of the non-missing values.
	Mean      *float64  `json:"mean,omitempty"`
	Std       *float64  `json:"std,omitempty"`
	Min       *float64  `json:"min,omitempty"`
	Max       *float64  `json:"max,omitempty"`
	Edges     []float64 `json:"edges,omitempty"`
	Fractions []float64 `json:"fractions,omitempty"`

	// Categorical: the most frequent values, and the share of all the others.
	Top           []CategoryShare `json:"top,omitempty"`
	OtherFraction float64         `json:"other_fraction,omitempty"`
}

FeatureStats is one feature of a training split, as the worker measured it (ml/worker/hermod_ml/stats.py, which documents the binning).

type FeatureWeight

type FeatureWeight struct {
	Feature string  `json:"feature"`
	Weight  float64 `json:"weight"`
}

FeatureWeight is one feature's share of what the model relies on.

type HealthCheck

type HealthCheck struct {
	Code    string `json:"code"`
	Status  string `json:"status"`
	Message string `json:"message"`
	Fix     string `json:"fix,omitempty"`
}

HealthCheck is one check of the data health check: its code, green, amber or red, what it found and, when not green, how to fix it.

type LeaderboardEntry

type LeaderboardEntry struct {
	Algorithm string  `json:"algorithm"`
	Score     float64 `json:"score"`
	Metric    string  `json:"metric"`
	Folds     int     `json:"folds"`
	Seconds   float64 `json:"seconds"`
	Chosen    bool    `json:"chosen"`
}

LeaderboardEntry is one algorithm auto scored by cross-validation on the training rows. Metric is balanced_accuracy for a classifier and r2 for a regression; Folds is 1 for a single validation split.

type Local added in v1.18.2

type Local interface {
	http.Handler
	// Predict scores rows with a version of a model, one prediction per row:
	// {"label", "probability"} for a classifier, {"value"} for a regression,
	// as the worker's serving answers.
	Predict(ctx context.Context, vhost, model, version string, rows []map[string]any) ([]map[string]any, error)
}

Local is an ML engine in Hermod's own process, such as the built-in engine (pkg/ml/builtin). It answers the worker's routes as an http.Handler, so a Client built on it with NewLocal works as one for a worker does, and scores rows with Predict directly, without the Open Inference Protocol.

type NamedBaseline

type NamedBaseline struct {
	Name    string             `json:"name"`
	Metrics map[string]float64 `json:"metrics"`
}

NamedBaseline is one simple rule a scenario was measured against, such as most_overdue, biggest or popular, and its metrics.

type ProbeReport added in v1.18.1

type ProbeReport struct {
	Result  ProbeResult `json:"result"`
	Message string      `json:"message"`
	// DeepLearning says whether the worker can train a neural network, and
	// Frameworks which ones: the "-dl" image has both.
	DeepLearning bool     `json:"deep_learning"`
	Frameworks   []string `json:"frameworks,omitempty"`
	Algorithms   []string `json:"algorithms,omitempty"`
}

ProbeReport is what Probe found, for a person: the result, a sentence, and what the worker can train.

func Probe added in v1.18.1

func Probe(ctx context.Context, baseURL, token string, hc *http.Client) ProbeReport

Probe calls the worker at baseURL with token the way Hermod will: its readiness check, which needs no token, then its capabilities, which do. hc may be nil for Hermod's data client, which New uses too, so a test reaches exactly what training will. The report never repeats the token.

type ProbeResult added in v1.18.1

type ProbeResult string

ProbeResult is what Probe found at an address, in one word.

const (
	// ProbeOK: a hermod-ml worker answered and took the token.
	ProbeOK ProbeResult = "ok"
	// ProbeBadAddress: the address is not an http or https URL Hermod can call.
	ProbeBadAddress ProbeResult = "bad_address"
	// ProbeUnreachable: nothing answered there (refused, no such host, timed
	// out).
	ProbeUnreachable ProbeResult = "unreachable"
	// ProbeNotAWorker: something answered, but not a hermod-ml worker.
	ProbeNotAWorker ProbeResult = "not_a_worker"
	// ProbeUnauthorized: the worker refused the token.
	ProbeUnauthorized ProbeResult = "unauthorized"
	// ProbeError: the worker answered with an error of its own.
	ProbeError ProbeResult = "error"
)

type Provider added in v1.18.1

type Provider struct {
	// contains filtered or unexported fields
}

Provider answers the ML worker in force: the environment's, read once, else the one saved in Hermod's storage, which can change while Hermod runs. It is safe for concurrent use.

func NewProvider added in v1.18.1

func NewProvider(env func() *Client) *Provider

NewProvider returns a provider whose environment's worker is env, called at most once.

func (*Provider) Builtin added in v1.18.2

func (p *Provider) Builtin() *Client

Builtin returns the built-in engine's client, or nil.

func (*Provider) Current added in v1.18.1

func (p *Provider) Current() (*Client, Source)

Current returns the engines in force and where the worker among them was configured: the environment's worker, else the saved one, else none. With the built-in engine installed by SetEngine, the client is that engine routing to the worker, so both serve at once (SourceBuiltin when there is no worker); without it, the client is the worker, else the built-in engine of SetBuiltin, else nil and SourceNone.

func (*Provider) Env added in v1.18.1

func (p *Provider) Env() *Client

Env returns the environment's worker, or nil.

func (*Provider) Refresh added in v1.18.1

func (p *Provider) Refresh(ctx context.Context, every time.Duration, load func(context.Context) (*Client, error)) error

Refresh re-reads the saved worker with load when the last read is at least every old and no other read is running, so another Hermod process sharing the database picks up a worker saved there. A failed read keeps the worker it has and is returned. Nothing is read while the environment names a worker, since that one wins.

func (*Provider) SetBuiltin added in v1.18.2

func (p *Provider) SetBuiltin(c *Client)

SetBuiltin installs an in-process engine's client (NewLocal), in force only while no worker is configured; nil means Hermod has none. SetEngine installs the built-in engine beside the worker instead.

func (*Provider) SetEngine added in v1.18.2

func (p *Provider) SetEngine(route func(remote *Client) *Client)

SetEngine installs Hermod's built-in engine: route returns its client routing to the worker remote, or alone for a nil remote. It is always in force, beside any worker; nil removes it.

func (*Provider) SetSaved added in v1.18.1

func (p *Provider) SetSaved(c *Client)

SetSaved installs the saved worker; nil means none is saved. It counts as a fresh read for Refresh.

type RecommendHealth

type RecommendHealth struct {
	OK     bool           `json:"ok"`
	Checks []HealthCheck  `json:"checks"`
	Stats  map[string]any `json:"stats"`
}

RecommendHealth is a scenario's data health check: one entry per check, green, amber or red, and what the data holds. OK is false when any check is red, which a training refuses.

type RecommendSample

type RecommendSample struct {
	User        string   `json:"user"`
	Recommended []string `json:"recommended"`
	Picked      []string `json:"picked"`
}

RecommendSample is one person of a #268 recommendation model's test: what the model recommended, and what they really picked next. A scenario's samples are example answers instead ({"for", "items"}), so Version keeps Samples as the worker wrote them.

type RecommendSpec

type RecommendSpec struct {
	User     string `json:"user"`
	Item     string `json:"item"`
	Strength string `json:"strength,omitempty"`
	Time     string `json:"time,omitempty"`
}

RecommendSpec is the columns a recommendation model learns from: who (User) picked what (Item), optionally how much they liked it (Strength: a rating, quantity or count) and when (Time, which makes the test hold back each person's latest picks).

type Script

type Script struct {
	Name   string `json:"name"`
	SHA256 string `json:"sha256"`
	Source string `json:"source"`
}

Script is a custom training script as a worker runs it. SHA256 is the hex digest of Source; the worker refuses a script whose source does not match.

type ScriptRef

type ScriptRef struct {
	Name   string `json:"name"`
	SHA256 string `json:"sha256"`
}

ScriptRef names the script, and the exact version of it, that trained a model version.

type Source added in v1.18.1

type Source string

Source says where the worker in force was configured.

const (
	// SourceNone means no worker is configured.
	SourceNone Source = "none"
	// SourceEnvironment is HERMOD_ML_WORKER_URL. It wins over a saved worker,
	// so a deployment that pins its worker in its manifest keeps it.
	SourceEnvironment Source = "environment"
	// SourceSaved is a worker connected from the console and kept in
	// Hermod's storage.
	SourceSaved Source = "saved"
	// SourceBuiltin is Hermod's built-in engine (pkg/ml/builtin) alone, in
	// force when no worker is configured.
	SourceBuiltin Source = "builtin"
)

type TrainCheck

type TrainCheck struct {
	// Task is classification or regression; TargetKind yes_no, category or
	// number. Classes is set for a classification only.
	Task       string         `json:"task"`
	TargetKind string         `json:"target_kind"`
	Classes    *int           `json:"classes,omitempty"`
	Rows       int            `json:"rows"`
	UsableRows int            `json:"usable_rows"`
	Columns    []ColumnCheck  `json:"columns"`
	Warnings   []CheckWarning `json:"warnings"`
	// OK is false when a training would be refused; Warnings say why.
	OK bool `json:"ok"`
}

TrainCheck is the pre-flight answer for a training: what the worker makes of the dataset, without training anything.

type TrainParams

type TrainParams struct {
	HiddenLayers []int   `json:"hidden_layers,omitempty"`
	Epochs       int     `json:"epochs,omitempty"`
	BatchSize    int     `json:"batch_size,omitempty"`
	LearningRate float64 `json:"learning_rate,omitempty"`
	// Patience is how many epochs without a better validation loss end
	// training early.
	Patience int `json:"patience,omitempty"`
}

TrainParams are a deep-learning model's hyperparameters. A zero field is left out, so the worker uses its default; the worker also checks the bounds (at most 5 layers of 1024 units, 1000 epochs, a learning rate in (0, 1]).

type TrainSpec

type TrainSpec struct {
	Dataset string `json:"dataset"`
	// Target is the column to predict; empty for a recommendation model.
	Target string `json:"target"`
	// Features are the columns the model reads; empty means every column but
	// Target.
	Features []string `json:"features,omitempty"`
	// Task is auto, classification, regression or recommendation.
	Task string `json:"task,omitempty"`
	// Recommend names a recommendation model's columns. The worker refuses
	// it for any other task, and Target, Features and Params for this one.
	Recommend *RecommendSpec `json:"recommend,omitempty"`
	// Algorithm is auto, random_forest, gradient_boosting, linear, mlp (the
	// built-in engine only), xgboost, extra_trees, hist_gradient_boosting,
	// pytorch_mlp or keras_mlp; for a recommendation model, auto, als or
	// item_similarity.
	Algorithm string `json:"algorithm,omitempty"`
	// Preset is how hard auto tries: quick, balanced (the worker's default)
	// or best. Only an auto training takes one.
	Preset   string  `json:"preset,omitempty"`
	TestSize float64 `json:"test_size,omitempty"`
	Seed     *int    `json:"seed,omitempty"`
	// Device is cpu (the default) or gpu. Hermod routes a gpu training to its
	// GPU worker pool; the worker reads it as a hint for its own networks.
	Device string `json:"device,omitempty"`
	// Params tunes pytorch_mlp and keras_mlp (mlp on the built-in engine);
	// the engine refuses it for any other algorithm.
	Params *TrainParams `json:"params,omitempty"`

	// A recommendation scenario's training (ml/worker/hermod_ml/scenarios.py)
	// names Scenario and maps each data role (transactions, customers,
	// products, visits, salesmen) to a dataset and its columns in Data,
	// instead of Recommend. Weights are the visit signals' weights, Rules the
	// business rules every call obeys, and PeriodDays the planning (visits)
	// or evaluation period. NearKm and NearPeers make a customer's peers the
	// NearPeers nearest of its category within NearKm kilometres; 0 for the
	// worker's default (5 km, 20 customers). NewDays makes a product launched
	// within that many days new (products.launch_date); 0 for the worker's
	// default (60).
	Scenario   string                       `json:"scenario,omitempty"`
	Data       map[string]map[string]string `json:"data,omitempty"`
	Weights    map[string]float64           `json:"weights,omitempty"`
	Rules      []recommend.Rule             `json:"rules,omitempty"`
	PeriodDays int                          `json:"period_days,omitempty"`
	NearKm     float64                      `json:"near_km,omitempty"`
	NearPeers  int                          `json:"near_peers,omitempty"`
	NewDays    int                          `json:"new_days,omitempty"`
}

TrainSpec is one training: which dataset, what to predict from what, and how.

type Version

type Version struct {
	Model   string `json:"model"`
	Version string `json:"version"`
	// Engine is the engine that trained it and scores it: EngineBuiltin or
	// EngineWorker (engines.go).
	Engine       string             `json:"engine,omitempty"`
	Task         string             `json:"task"`
	Algorithm    string             `json:"algorithm"`
	Dataset      string             `json:"dataset"`
	Target       string             `json:"target"`
	Features     []string           `json:"features"`
	FeatureTypes map[string]string  `json:"feature_types,omitempty"`
	Labels       []any              `json:"labels,omitempty"`
	Metrics      map[string]float64 `json:"metrics"`
	Rows         struct {
		Train int `json:"train"`
		Test  int `json:"test"`
	} `json:"rows"`
	// FeatureStats describe the rows the version was trained on, per
	// feature. A version trained before the worker recorded them has none.
	FeatureStats map[string]FeatureStats `json:"feature_stats,omitempty"`
	CreatedAt    time.Time               `json:"created_at"`
	// Fill is what a null numeric feature becomes: its training median.
	Fill map[string]float64 `json:"fill,omitempty"`
	// Script is the custom script that trained this version, and Log what
	// it printed; both are empty for a built-in algorithm.
	Script *ScriptRef `json:"script,omitempty"`
	Log    string     `json:"log,omitempty"`

	// A recommendation version's columns, catalogue, a sample of its test,
	// and what auto measured for each algorithm (NDCG@10 on a validation
	// split of the training rows).
	Recommend  *RecommendSpec     `json:"recommend,omitempty"`
	Catalog    *Catalog           `json:"catalog,omitempty"`
	Samples    json.RawMessage    `json:"samples,omitempty"`
	Candidates map[string]float64 `json:"candidates,omitempty"`

	// A scenario's training (see TrainSpec): the scenario, its data roles,
	// the weights asked for and those applied, its default rules, its
	// metrics against named baselines, how it was evaluated, and the data
	// health check it passed.
	Scenario       string                       `json:"scenario,omitempty"`
	Roles          map[string]map[string]string `json:"roles,omitempty"`
	Weights        map[string]float64           `json:"weights,omitempty"`
	AppliedWeights map[string]float64           `json:"applied_weights,omitempty"`
	Rules          []recommend.Rule             `json:"rules,omitempty"`
	BaselinesNamed []NamedBaseline              `json:"baselines_named,omitempty"`
	Evaluation     map[string]any               `json:"evaluation,omitempty"`
	Health         *RecommendHealth             `json:"health,omitempty"`
	// Preset and Leaderboard are an auto training's: how hard it tried, and
	// every candidate it scored, best first.
	Preset      string             `json:"preset,omitempty"`
	Leaderboard []LeaderboardEntry `json:"leaderboard,omitempty"`
	// Importance is each feature's permutation importance on the held-out
	// rows, normalised to sum to 1, heaviest first, at most 20.
	Importance []FeatureWeight `json:"importance,omitempty"`
	// Baseline holds the Metrics keys, scored by a model that always answers
	// the most common class or the mean.
	Baseline map[string]float64 `json:"baseline,omitempty"`
	// Warnings are notes on the data, in words.
	Warnings []string `json:"warnings,omitempty"`
}

Version is one trained, immutable model version and how it scored on the rows held back from training.

Jump to

Keyboard shortcuts

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