The internal weight matrix of an nn.Embedding layer will have the shape [num_embeddings, embedding_dim], which is [30522, 768] in your case. The error is raised since you are trying to pass a 3D tensor in the shape [1, 15, 768] to this layer as its weight. Based on your code it seems you want to use the output activation of a model as the embedding weight, so maybe try to remove the batch dimension and change num_embeddings to 15.