---
title: "ClikaRT::ops::embedding"
sidebar_label: "embedding"
description: "Embedding lookup: gathers rows of weight by indices, with an optional bias + activation epilogue. indices Int32 or Int64, any shape; every value in [0, V)."
---

<!-- Generated by tools/doxygen2mdx from Doxygen XML. Do not edit. -->

<span class="api-kind api-kind--function">function</span>

## embedding() {#embedding}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`embedding`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Tensor`](../Tensor.md) `indices`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Tensor`](../Tensor.md) `weight`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`OptionalTensor`](../../index.md#OptionalTensor) `bias` `=` `{}`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`std::optional<`[`Activation`](./index.md#Activation)`>` `activation` `=` `std::nullopt`<br />
)

</div>

Embedding lookup: gathers rows of `weight` by `indices`, with an optional bias + activation epilogue.

**Parameters**

- `indices`: Int32 or Int64, any shape; every value in `[0, V)`.
- `weight`: the table `[V, E]` (row per vocabulary entry).
- `bias`: optional `[E]`, added to every gathered row.
- `activation`: optional activation applied after the bias.

An index outside the table (negative, or at or past `V`) is refused, on every backend, with `INVALID_ARGUMENT` naming the offending value and the table size, the same contract as [`index_select`](./index_select.md#index_select); no index is ever clamped or wrapped to another row.

**Throws**

- `ClikaRT::Error`: (`INVALID_ARGUMENT`) when `indices` is not an integer dtype, an index is out of range, or the shapes are inconsistent (`code_name()` carries the reason).

**Returns:** `indices.shape ++ [E]`, dtype of `weight`.

```cpp
auto h = ClikaRT::ops::embedding(token_ids, table);   // [B, S] -> [B, S, E]
```

<div class="api-declared">

Declared in `ClikaRT/compute/ops.h`, line 2144

</div>
