Lookup table, weight[indices]
Easy FundamentalsImplement an embedding lookup table from scratch.
• self.weight: nn.Parameter of shape (num_embeddings, embedding_dim)
• Forward: index into weight matrix โ weight[indices]
• Do NOT use nn.Embedding
Implement the function below. Use only basic PyTorch operations.
Use this code to debug before submitting.
Try solving it yourself first! Click below to reveal the solution.
For interactive practice with auto-grading, run TorchCode locally:pip install torch-judge then use check("embedding")
Lookup table, weight[indices]