# helia_edge.losses.simclr

## SimCLR Loss

This module implements the SimCLR loss function for contrastive self-supervised learning.

**Classes**

| Name | Description |
| --- | --- |
| `SimCLRLoss` | Implements SimCLR Cosine Similarity loss. |

**Functions**

| Name | Description |
| --- | --- |
| `l2_normalize` | Normalizes a tensor along a given axis. |

## helia_edge.losses.simclr.LARGE_NUM

`constant` · `python`

```python
LARGE_NUM = 1000000000.0
```

Source: `helia_edge/losses/simclr.py:18`

## helia_edge.losses.simclr.l2_normalize

`function` · `python`

```python
l2_normalize(x: keras.KerasTensor, axis: int | tuple[int, ...] | None = None) -> keras.KerasTensor
```

Performs L2 normalization on a tensor along a given axis.

**Parameters**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| x | tf.Tensor | Required | Input tensor |
| axis | int \| tuple[int] | None | Axis. Defaults to None. |

**Returns**

| Name | Type | Description |
| --- | --- | --- |
|  | keras.KerasTensor | tf.Tensor: Normalized tensor |

Source: `helia_edge/losses/simclr.py:21`

## helia_edge.losses.simclr.SimCLRLoss

`class` · `python`

```python
SimCLRLoss(temperature: float, **kwargs={})
```

Implements SimCLR Cosine Similarity loss.

SimCLR loss is used for contrastive self-supervised learning.

:::note[References]
- [SimCLR paper](https://arxiv.org/pdf/2002.05709)

:::

**Parameters**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| temperature | float | Required | A scaling factor for cosine similarity b/w [0, 1]. |

Source: `helia_edge/losses/simclr.py:37`

### helia_edge.losses.simclr.SimCLRLoss.temperature

`attribute` · `python`

```python
temperature = temperature
```

Source: `helia_edge/losses/simclr.py:52`

### helia_edge.losses.simclr.SimCLRLoss.call

`method` · `python`

```python
call(projections_1: keras.KerasTensor, projections_2: keras.KerasTensor) -> keras.KerasTensor
```

Computes SimCLR loss for a pair of projections in a contrastive
learning trainer.

Note that unlike most loss functions, this should not be called with
y_true and y_pred, but with two unlabeled projections. It can otherwise
be treated as a normal loss function.

**Parameters**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| projections_1 | keras.KerasTensor | Required | a tensor with the output of the first projection model in a contrastive learning trainer |
| projections_2 | keras.KerasTensor | Required | a tensor with the output of the second projection model in a contrastive learning trainer |

**Returns**

| Name | Type | Description |
| --- | --- | --- |
|  | keras.KerasTensor | keras.KerasTensor: A tensor with the SimCLR loss computed from the input projections |

Source: `helia_edge/losses/simclr.py:54`

### helia_edge.losses.simclr.SimCLRLoss.get_config

`method` · `python`

```python
get_config()
```

Source: `helia_edge/losses/simclr.py:97`
