Both nn.Embedding and nn.Linear are conceptually equivalent to a matrix used for projecting input vectors. Their implementation and syntax, however, are very different. nn.Linear is designed for arbitrary, unseen inputs, and performs an actual matrix multiplication for each dense input. nn.Embedding assumes that input is one-hot encoded and therefore comes from a fixed vocabulary. Hence, it expects an integer index rather than a vector. Internally, nn.Embedding can cache some or all of these vectors for greater performance.