嵌入 (Embedding)¶
- class torch.ao.nn.quantized.Embedding(num_embeddings, embedding_dim, padding_idx=None, max_norm=None, norm_type=2.0, scale_grad_by_freq=False, sparse=False, _weight=None, dtype=torch.quint8)[source][source]¶
一個量化的 Embedding 模組,使用量化的 packed 權重作為輸入。我們採用與 torch.nn.Embedding 相同的介面,請參閱 https://pytorch.dev.org.tw/docs/stable/generated/torch.nn.Embedding.html 以取得文件。
與
Embedding
類似,屬性將在模組建立時隨機初始化,並在稍後被覆寫- 變數
weight (Tensor) – 模組的非可學習量化權重,形狀為 。
- 範例:
>>> m = nn.quantized.Embedding(num_embeddings=10, embedding_dim=12) >>> indices = torch.tensor([9, 6, 5, 7, 8, 8, 9, 2, 8]) >>> output = m(indices) >>> print(output.size()) torch.Size([9, 12])