Open shouya opened 1 year ago
Completed in #2413
@laggui I'd argue that the function suggested by this issue is not implemented in #2413. #2413 implements a special case of this function: Tensor<B, 1, Int> -> Tensor<B, 2, Float>
but not the more general form Tensor<B, D, Int> -> Tensor<B, D+1, Float>
that works for any dimensions of indices.
Shall we reopen the issue until the problem is fully addressed?
Ahh you're right sorry! I'll leave this open.
Feature description
Burn currently supports creating one_hot vector for a single token:
pub fn one_hot(index: usize, num_classes: usize) -> Tensor<B, 1>
.However, it is a common use case to create a tensor for a sequence of tokens (or even multiple sequences in batching scenario). So it would be good to have a more versatile one_hot function that operates on inputs of higher dimensions.
Here's a proposed function signature:
Suggest a Solution
I crafted this version to use in my project:
But I'm not sure if this can be improved further.