reconstruction
Utilities for measuring the reconstruction of (transformed) embeddings to tokens.
Functions:
| Name | Description |
|---|---|
reconstruction_rank |
Compute the reconstruction rank for each element of |
reconstruction_rank_histogram |
Count the number of observations of each reconstruction rank. |
symmetric_tokens_transformed_at_k |
Measure if each reconstruction rank is outside the top-k and bottom-k ranks. |
tokens_transformed_at_k |
Measure if each reconstruction rank is outside the top-k ranks. |
reconstruction_rank
¶
reconstruction_rank(
input_ids: Tensor, ranked_neighbors: Tensor
) -> torch.Tensor
Compute the reconstruction rank for each element of input_ids from its corresponding element in ranked_neighbors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Tensor
|
The ground truth clean indices of the embeddings of shape ( |
required |
|
Tensor
|
A ranked list of which clean embeddings were closest to each transformed embedding of shape ( |
required |
Returns:
| Type | Description |
|---|---|
torch.Tensor
|
The reconstruction rank for each element of |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Added in version v3.36.0.
reconstruction_rank_histogram
¶
reconstruction_rank_histogram(
num_embeddings: int, reconstruction_ranks: Tensor
) -> torch.Tensor
Count the number of observations of each reconstruction rank.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
int
|
The number of embeddings in the model. |
required |
|
Tensor
|
A tensor of reconstruction ranks consisting of integers from |
required |
Returns:
| Type | Description |
|---|---|
torch.Tensor
|
A 1-D tensor of shape ( |
Added in version v3.36.0.
symmetric_tokens_transformed_at_k
¶
symmetric_tokens_transformed_at_k(
num_embeddings: int,
reconstruction_ranks: Tensor,
k: int,
) -> torch.Tensor
Measure if each reconstruction rank is outside the top-k and bottom-k ranks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
int
|
The number of embeddings in the model. |
required |
|
Tensor
|
A tensor of reconstruction ranks consisting of integers from |
required |
|
int
|
The cutoff rank to be considered "transformed". |
required |
Returns:
| Type | Description |
|---|---|
torch.Tensor
|
A boolean tensor of whether each reconstruction rank is |
Added in version v3.36.0.
tokens_transformed_at_k
¶
tokens_transformed_at_k(
reconstruction_ranks: Tensor, k: int
) -> torch.Tensor
Measure if each reconstruction rank is outside the top-k ranks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Tensor
|
A tensor of reconstruction ranks consisting of integers from |
required |
|
int
|
The cutoff rank to be considered "transformed". Should be at least |
required |
Returns:
| Type | Description |
|---|---|
torch.Tensor
|
A boolean tensor of whether each reconstruction rank is |
Added in version v3.36.0.