publish()

audmodel.publish(root, name, params, version, *, alias=None, author=None, date=None, meta=None, repository=None, subgroup=None, verbose=False)[source]

Zip model and publish as a new artifact.

Before publishing a model, pick meaningful values for name, subgroup, params. The following table explains what the arguments should encode and shows examples.

Encodes

Examples

name

  • package used to train/create the model

  • onnx

  • sklearn

  • torch

subgroup

  • project

  • task the model was trained for

  • model architecture

  • ser.dimensions.wav2vec2

  • age.cnn

params

  • model

  • data

  • feature set

  • sampling rate

  • { ‘model’: ‘facebook/wav2vec2-large’, ‘data’: ‘msppodcast’, ‘sampling_rate’: 16000 }

  • { ‘model’: ‘cnn10’, ‘data’: [‘agender’, ‘emodb’], ‘feature’: ‘log-melspec’, ‘sampling_rate’: 8000 }

The meta argument encodes additional information. In contrast to name, subgroup, params it can be changed later. It should be used to extend information of the params entries using the same keys. In addition, it can store example output, and benchmark results. For example, a meta entry corresponding to the first params example from the table might contain:

{
    'model': {'facebook/wav2vec2-large': {'layers': 24}},
    'data': {'msppodcast': {'version': '2.6.0'}},
}
Parameters
  • root (str) – folder with model files

  • name (str) – model name

  • params (dict[str, object]) – dictionary with parameters

  • version (str) – version string

  • alias (Optional[str]) – optional alias name for the model. If provided, the model can be accessed using this alias in addition to its UID

  • author (Optional[str]) – author name(s), defaults to user name

  • date (Optional[date]) – date, defaults to current timestamp

  • meta (Optional[dict[str, object]]) – dictionary with meta information

  • repository (Optional[Repository]) – repository where the model will be published, defaults to config.REPOSITORIES[0]

  • subgroup (Optional[str]) – subgroup under which the model is stored on backend. . are replaced by / on the backend

  • verbose (bool) – show debug messages

Return type

str

Returns

unique model ID

Raises
  • audbackend.BackendError – if connection to repository on backend cannot be established

  • RuntimeError – if a model with same UID exists already

  • RuntimeError – if an unexpected error occurs during publishing

  • RuntimeError – if meta or params cannot be serialized to a YAML file

  • ValueError – if subgroup is set to '_uid'

  • FileNotFoundError – if root folder cannot be found

  • ValueError – if alias can be confused with an UID, or it does contain chars other than [A-Za-z0-9._-]+

Examples

>>> # Assuming your model files are stored under `model_root`
>>> # and your repository is given by `repository`
>>> # (which you usually don't specify, but use its default value)
>>> import datetime
>>> name = "torch"
>>> subgroup = "audmodel.dummy.cnn"
>>> version = "4.0.0"
>>> author = "Calvin and Hobbes"
>>> data = datetime.date(1985, 11, 18)
>>> params = {
...     "model": "cnn10",
...     "data": "emodb",
...     "feature": "melspec",
...     "sampling_rate": 16000,
... }
>>> meta = {
...     "model": {
...         "cnn10": {
...             "learning-rate": 1e-4,
...             "optimizer": "sgd",
...         },
...     },
...     "data": {
...         "emodb": {
...             "version": "1.2.0",
...         },
...     },
...     "feature": {
...         "melspec": {
...             "win_dur": "32ms",
...             "hop_dur": "10ms",
...             "num_fft": 512,
...             "mel_bins": 64,
...         },
...     },
... }
>>> publish(
...     model_root,
...     name,
...     params,
...     version,
...     author=author,
...     date=date,
...     meta=meta,
...     subgroup=subgroup,
...     repository=repository,
... )
'd4e9c65b-4.0.0'