Skip to content

Multi-dimensional onehot #1229

@cossio

Description

@cossio

Could we generalize onehot encoding in Flux to more than one or two dimensions? In general, we can have an N dimensional binary array, where the first dimension always has exactly one bit on and the rest are off. This represents a onehot encoding of an N-1 dimensional array where each entry is a category.

An application is a sequence of length L where each site can be one of q letters. Then one sequence can be onehot encoded as a q * L matrix. But to encode a batch of B sequences, we need a multi-dimensional q * L * B array.

One possible implementation: https://github.com/cossio/OneHot.jl/blob/master/src/array.jl.

I can make a PR if people agree this can be useful in general.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions