Skip to content
This repository was archived by the owner on Sep 10, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/source/nn_modules.rst
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
.. role:: hidden
:class: hidden-section

torchtext.nn.modules.multiheadattention
torchtext.nn
=======================================

.. automodule:: torchtext.nn.modules.multiheadattention
.. currentmodule:: torchtext.nn.modules.multiheadattention
.. automodule:: torchtext.nn
.. currentmodule:: torchtext.nn

:hidden:`MultiheadAttentionContainer`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
3 changes: 3 additions & 0 deletions torchtext/nn/modules/multiheadattention.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def __init__(self, nhead, in_proj_container, attention_layer, out_proj, batch_fi

Examples::
>>> import torch
>>> from torchtext.nn import MultiheadAttentionContainer, InProjContainer, ScaledDotProduct
>>> embed_dim, num_heads, bsz = 10, 5, 64
>>> in_proj_container = InProjContainer(torch.nn.Linear(embed_dim, embed_dim),
torch.nn.Linear(embed_dim, embed_dim),
Expand Down Expand Up @@ -122,6 +123,7 @@ def __init__(self, dropout=0.0, batch_first=False):
as `(batch, seq, feature)`. Default: ``False``

Examples::
>>> import torch, torchtext
>>> SDP = torchtext.nn.ScaledDotProduct(dropout=0.1)
>>> q = torch.randn(21, 256, 3)
>>> k = v = torch.randn(21, 256, 3)
Expand Down Expand Up @@ -245,6 +247,7 @@ def forward(self,
value (Tensor): The values to be projected.

Examples::
>>> import torch
>>> from torchtext.nn import InProjContainer
>>> embed_dim, bsz = 10, 64
>>> in_proj_container = InProjContainer(torch.nn.Linear(embed_dim, embed_dim),
Expand Down