# helia_edge.models.conformer

## Conformer Model

Conformer model implementation in Keras.

Parameters are in ``helia_edge.models.conformer_params``.

**Functions**

| Name | Description |
| --- | --- |
| `build` | Conformer model from ``ConformerParams`` |
| `subsampler` | Subsampler block |
| `fc_block` | Fully connected block |
| `conv_block` | Convolutional block |
| `att_block` | Attention block |
| `conformer_block` | Conformer block |
| `conformer_layer` | Conformer functional layer |

## helia_edge.models.conformer.subsampler

`function` · `python`

```python
subsampler(
    blocks: SubsampleBlockParams,
    kernel_initializer: str = 'glorot_uniform',
    bias_initializer: str = 'zeros',
    kernel_regularizer=None,
    bias_regularizer=None,
    name: str | None = None,
) -> keras.Layer
```

Subsampler block

**Parameters**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| blocks | SubsampleBlockParams | Required | Subsample block parameters |
| kernel_initializer | str | 'glorot_uniform' | Kernel initializer. Defaults to "glorot_uniform". |
| bias_initializer | str | 'zeros' | Bias initializer. Defaults to "zeros". |
| kernel_regularizer | [type] | None | Kernel regularizer. Defaults to None. |
| bias_regularizer | [type] | None | Bias regularizer. Defaults to None. |
| name | str | None | Name. Defaults to None. |

**Returns**

| Name | Type | Description |
| --- | --- | --- |
|  | keras.Layer | keras.Layer: Subsampler layer |

Source: `helia_edge/models/conformer.py:26`

## helia_edge.models.conformer.fc_block

`function` · `python`

```python
fc_block(
    depth: int,
    ex_factor: int = 4,
    residual_factor: float = 0.5,
    dropout: float = 0,
    use_bias: bool = True,
    kernel_initializer: str = 'glorot_uniform',
    bias_initializer: str = 'zeros',
    kernel_regularizer=None,
    bias_regularizer=None,
    name: str = 'fc_block',
) -> keras.Layer
```

Fully connected block

**Parameters**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| depth | int | Required | Depth |
| ex_factor | int | 4 | Expansion factor. Defaults to 4. |
| residual_factor | float | 0.5 | Residual factor. Defaults to 0.5. |
| dropout | float | 0 | Dropout rate. Defaults to 0. |
| use_bias | bool | True | Use bias. Defaults to True. |
| kernel_initializer | str | 'glorot_uniform' | Kernel initializer. Defaults to "glorot_uniform". |
| bias_initializer | str | 'zeros' | Bias initializer. Defaults to "zeros". |
| kernel_regularizer | [type] | None | Kernel regularizer. Defaults to None. |
| bias_regularizer | [type] | None | Bias regularizer. Defaults to None. |
| name | str | 'fc_block' | Name. Defaults to "fc_block". |

**Returns**

| Name | Type | Description |
| --- | --- | --- |
|  | keras.Layer | keras.Layer: Functional layer |

Source: `helia_edge/models/conformer.py:85`

## helia_edge.models.conformer.conv_block

`function` · `python`

```python
conv_block(
    depth: int,
    kernel_size: int = 9,
    dropout: float = 0.0,
    padding: str = 'same',
    scale_factor: int = 2,
    kernel_initializer: str = 'glorot_uniform',
    bias_initializer: str = 'zeros',
    kernel_regularizer=None,
    bias_regularizer=None,
    name: str = 'conv_module',
) -> keras.Layer
```

Convolutional block

**Parameters**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| depth | int | Required | Depth |
| kernel_size | int | 9 | Kernel size. Defaults to 9. |
| dropout | float | 0.0 | Dropout rate. Defaults to 0.0. |
| padding | str | 'same' | Padding. Defaults to "same". |
| scale_factor | int | 2 | Scale factor. Defaults to 2. |
| kernel_initializer | str | 'glorot_uniform' | Kernel initializer. Defaults to "glorot_uniform". |
| bias_initializer | str | 'zeros' | Bias initializer. Defaults to "zeros". |
| kernel_regularizer | [type] | None | Kernel regularizer. Defaults to None. |
| bias_regularizer | [type] | None | Bias regularizer. Defaults to None. |
| name | str | 'conv_module' | Name. Defaults to "conv_module". |

**Returns**

| Name | Type | Description |
| --- | --- | --- |
|  | keras.Layer | keras.Layer: Functional layer |

Source: `helia_edge/models/conformer.py:151`

## helia_edge.models.conformer.att_block

`function` · `python`

```python
att_block(
    depth: int,
    embedding: str = 'rel',
    num_heads: int = 4,
    dropout: float = 0.1,
    name: str = 'att_block',
) -> keras.Layer
```

Attention block

**Parameters**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| depth | int | Required | Depth |
| embedding | str | 'rel' | Embedding type. Defaults to "rel". |
| num_heads | int | 4 | Number of heads. Defaults to 4. |
| dropout | float | 0.1 | Dropout rate. Defaults to 0.1. |
| name | str | 'att_block' | Name. Defaults to "att_block". |

**Returns**

| Name | Type | Description |
| --- | --- | --- |
|  | keras.Layer | keras.Layer: Functional layer |

Source: `helia_edge/models/conformer.py:235`

## helia_edge.models.conformer.conformer_block

`function` · `python`

```python
conformer_block(
    depth: int,
    fc_ex_factor: int = 4,
    fc_res_factor: int = 0.5,
    embedding: str = 'relative',
    num_heads: int = 4,
    kernel_size: int = 9,
    dropout: float = 0.1,
    use_bias: bool = True,
    name: str = 'cf_block',
) -> keras.Layer
```

Conformer block

**Parameters**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| depth | int | Required | Depth |
| fc_ex_factor | int | 4 | FC expansion factor. Defaults to 4. |
| fc_res_factor | int | 0.5 | FC residual factor. Defaults to 0.5. |
| embedding | str | 'relative' | Embedding type. Defaults to "relative". |
| num_heads | int | 4 | Number of heads. Defaults to 4. |
| kernel_size | int | 9 | Kernel size. Defaults to 9. |
| dropout | float | 0.1 | Dropout rate. Defaults to 0.1. |
| use_bias | bool | True | Use bias. Defaults to True. |
| name | str | 'cf_block' | Name. Defaults to "cf_block". |

**Returns**

| Name | Type | Description |
| --- | --- | --- |
|  | keras.Layer | keras.Layer: Functional layer |

Source: `helia_edge/models/conformer.py:278`

## helia_edge.models.conformer.conformer_layer

`function` · `python`

```python
conformer_layer(x: keras.KerasTensor, params: ConformerParams) -> keras.KerasTensor
```

Conformer functional layer

**Parameters**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| x | keras.KerasTensor | Required | Input tensor |
| params | ConformerParams | Required | Model parameters. |

**Returns**

| Name | Type | Description |
| --- | --- | --- |
|  | keras.KerasTensor | keras.KerasTensor: Output tensor |

Source: `helia_edge/models/conformer.py:350`

## helia_edge.models.conformer.build

`function` · `python`

```python
build(
    params: ConformerParams,
    input_shape: tuple[int | None, ...],
    *,
    batch_size: int | None = None,
    name: str | None = None,
) -> keras.Model
```

Build a Conformer model.

**Parameters**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| params | ConformerParams | Required | Model parameters. |
| input_shape | tuple[int \| None, ...] | Required | Input shape without the batch axis; None for a variable axis. |
| batch_size | int \| None | None | Static batch size; None for a dynamic batch. |
| name | str \| None | None | Model name; the family when None. |

**Returns**

| Name | Type | Description |
| --- | --- | --- |
|  | keras.Model | keras.Model: The model, named ``conformer`` unless ``name`` is given. |

Source: `helia_edge/models/conformer.py:389`
