WhisperSpec

class ctranslate2.specs.WhisperSpec

Describes a Whisper model.

Inherits from: ctranslate2.specs.LanguageModelSpec

Attributes:

Methods:

__init__(num_encoder_layers, num_encoder_heads, num_decoder_layers, num_decoder_heads)

Initializes the model specification.

Parameters
  • num_encoder_layers – The number of encoder layers.

  • num_encoder_heads – The number of encoder attention heads.

  • num_decoder_layers – The number of decoder layers.

  • num_decoder_heads – The number of decoder attention heads.

get_default_config()

Returns the default configuration used by this model.

get_vocabulary_size()

Returns the vocabulary size expected by the model.

optimize(quantization: Optional[str] = None) None

Recursively applies some optimizations to this layer:

  • Alias variables with the same shape and value.

  • Quantize weights.

Parameters

quantization – Weight quantization scheme (possible values are: int8, int8_float32, int8_float16, int8_bfloat16, int16, float16, bfloat16, float32).

register_file(path: str, filename: Optional[str] = None) None

Registers a file to be saved in the model directory.

register_vocabulary(tokens: List[str]) None

Registers the vocabulary of tokens.

Parameters

tokens – List of tokens.

save(output_dir: str) None

Saves this model on disk.

Parameters

output_dir – Output directory where the model is saved.

validate() None

Verify that the required weights are set.

Raises

ValueError – If a required weight is not set in the specification.

variables(prefix: str = '', ordered: bool = False) Dict[str, ndarray]

Recursively returns the weights from this layer and its children.

Parameters
  • prefix – Prefix to prepend to all variable names.

  • ordered – If set, an ordered list is returned instead.

Returns

Dictionary mapping variables name to value.

property config

The model configuration.

property name

The name of the model specification.

property revision

The model specification revision.

This value is incremented each time the weights layout of the model is changed (e.g. a weight is renamed).