hezar.builders module

Builder functions are used to create an instance of a module e.g, models, preprocessors, etc. without having to import their corresponding classes manually. These builders use modules’ registries to do so. Every builder gets a name and optional config or config kwargs to build the object.

Examples

>>> from hezar.builders import build_model
>>> model = build_model('distilbert_text_classification', id2label={0: 'negative', 1: 'positive'})
>>> print(model)
hezar.builders.build_dataset(name: str, config: DatasetConfig | None = None, split: SplitType | None = None, **kwargs)[source]

Build the dataset using its registry name. If config is None then the dataset is built using the default config.

Parameters:
  • name (str) – name of the dataset in the datasets’ registry

  • config (DatasetConfig) – a DatasetConfig instance

  • split (str) – Dataset split to load

  • **kwargs – extra config parameters that are loaded to the dataset

Returns:

A Dataset instance

hezar.builders.build_embedding(name: str, config: EmbeddingConfig | None = None, **kwargs)[source]

Build the embedding using its registry name. If config is None then the embedding is built using the default config.

Parameters:
  • name (str) – Name of the embedding in the embeddings’ registry

  • config (EmbeddingConfig) – An EmbeddingConfig instance

  • **kwargs – Extra config parameters that are loaded to the embedding

Returns:

A Embedding instance

hezar.builders.build_metric(name: str, config: MetricConfig | None = None, **kwargs)[source]

Build the metric using its registry name. If config is None then the metric is built using the default config.

Parameters:
  • name (str) – Name of the metric in the metrics’ registry

  • config (MetricConfig) – A MetricConfig instance

  • **kwargs – Extra config parameters that are loaded to the metric

Returns:

A Metric instance

hezar.builders.build_model(name: str, config: ModelConfig | None = None, **kwargs)[source]

Build the model using its registry name. If config is None then the model is built using the default config. Notice that this function only builds the model and does not perform any weights loading/initialization unless these actions are done in the model’s __init__() .

Parameters:
  • name (str) – name of the model in the models’ registry

  • config (ModelConfig) – a ModelConfig instance

  • **kwargs – extra config parameters that are loaded to the model

Returns:

A Model instance

hezar.builders.build_preprocessor(name: str, config: PreprocessorConfig | None = None, **kwargs)[source]

Build the preprocessor using its registry name. If config is None then the preprocessor is built using the default config.

Parameters:
  • name (str) – name of the preprocessor in the preprocessors’ registry

  • config (PreprocessorConfig) – a PreprocessorConfig instance

  • **kwargs – extra config parameters that are loaded to the preprocessor

Returns:

A Preprocessor instance