(self,
vocab,
dim,
dim_attn,
dim_ffn,
num_heads,
num_layers,
num_buckets,
shared_pos=True,
dropout=0.1)
| 261 | class T5Encoder(nn.Module): |
| 262 | |
| 263 | def __init__(self, |
| 264 | vocab, |
| 265 | dim, |
| 266 | dim_attn, |
| 267 | dim_ffn, |
| 268 | num_heads, |
| 269 | num_layers, |
| 270 | num_buckets, |
| 271 | shared_pos=True, |
| 272 | dropout=0.1): |
| 273 | super(T5Encoder, self).__init__() |
| 274 | self.dim = dim |
| 275 | self.dim_attn = dim_attn |
| 276 | self.dim_ffn = dim_ffn |
| 277 | self.num_heads = num_heads |
| 278 | self.num_layers = num_layers |
| 279 | self.num_buckets = num_buckets |
| 280 | self.shared_pos = shared_pos |
| 281 | |
| 282 | # layers |
| 283 | self.token_embedding = vocab if isinstance(vocab, nn.Embedding) \ |
| 284 | else nn.Embedding(vocab, dim) |
| 285 | self.pos_embedding = T5RelativeEmbedding( |
| 286 | num_buckets, num_heads, bidirectional=True) if shared_pos else None |
| 287 | self.dropout = nn.Dropout(dropout) |
| 288 | self.blocks = nn.ModuleList([ |
| 289 | T5SelfAttention(dim, dim_attn, dim_ffn, num_heads, num_buckets, |
| 290 | shared_pos, dropout) for _ in range(num_layers) |
| 291 | ]) |
| 292 | self.norm = T5LayerNorm(dim) |
| 293 | |
| 294 | # initialize weights |
| 295 | self.apply(init_weights) |
| 296 | |
| 297 | def forward(self, ids, mask=None): |
| 298 | x = self.token_embedding(ids) |
nothing calls this directly
no test coverage detected