PowerMachine commited on
Commit
61edc96
·
verified ·
1 Parent(s): 33525b1

Delete src/bigru_t/model/bigru4.py

Browse files
Files changed (1) hide show
  1. src/bigru_t/model/bigru4.py +0 -54
src/bigru_t/model/bigru4.py DELETED
@@ -1,54 +0,0 @@
1
- """bigru4.py — BiGRU4: 4 camadas BiGRU sequenciais.
2
-
3
- Componente base do u8cell_T (Lema 1). Cada BiGRU4 processa a sequência de
4
- entrada através de 4 camadas GRU bidirecionais empilhadas, produzindo uma
5
- representação agregada por média temporal.
6
-
7
- Reaproveita a filosofia das 4 camadas cooperativas do GRU-RING v13.9.2,
8
- mas sem bridge/attention interna — a cooperação entre as 8 BiGRU4 paralelas
9
- é feita pelo TransformerUnit do u8cell_T.
10
- """
11
- from __future__ import annotations
12
-
13
- import torch
14
- import torch.nn as nn
15
-
16
-
17
- class BiGRU4(nn.Module):
18
- """Quatro camadas BiGRU sequenciais.
19
-
20
- Args:
21
- input_dim: dimensão da entrada (batch, T, input_dim)
22
- hidden_dim: dimensão oculta de cada GRU (a saída tem 2*hidden_dim por ser bidirecional)
23
- dropout: dropout entre camadas (0 = desativado)
24
-
25
- Forward:
26
- x: (batch, T, input_dim) → v: (batch, 2*hidden_dim)
27
- v é a média temporal da saída da 4ª GRU.
28
- """
29
-
30
- def __init__(self, input_dim: int, hidden_dim: int, dropout: float = 0.0):
31
- super().__init__()
32
- self.input_dim = input_dim
33
- self.hidden_dim = hidden_dim
34
- self.output_dim = 2 * hidden_dim # bidirecional
35
-
36
- self.gru1 = nn.GRU(input_dim, hidden_dim, bidirectional=True, batch_first=True)
37
- self.gru2 = nn.GRU(2 * hidden_dim, hidden_dim, bidirectional=True, batch_first=True)
38
- self.gru3 = nn.GRU(2 * hidden_dim, hidden_dim, bidirectional=True, batch_first=True)
39
- self.gru4 = nn.GRU(2 * hidden_dim, hidden_dim, bidirectional=True, batch_first=True)
40
-
41
- self.dropout = nn.Dropout(dropout) if dropout > 0 else nn.Identity()
42
-
43
- def forward(self, x: torch.Tensor) -> torch.Tensor:
44
- """x: (batch, T, input_dim) → v: (batch, 2*hidden_dim)"""
45
- out, _ = self.gru1(x)
46
- out = self.dropout(out)
47
- out, _ = self.gru2(out)
48
- out = self.dropout(out)
49
- out, _ = self.gru3(out)
50
- out = self.dropout(out)
51
- out, _ = self.gru4(out)
52
- # Média temporal para obter representação fixa (independente de T)
53
- v = out.mean(dim=1) # (batch, 2*hidden_dim)
54
- return v