Spaces:
Sleeping
Sleeping
File size: 1,511 Bytes
8d7b4b1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | from __future__ import annotations
import torch
import torch.nn as nn
class RegressionHead(nn.Module):
def __init__(self, input_dim: int):
super().__init__()
self.head = nn.Sequential(
nn.LayerNorm(input_dim),
nn.Dropout(0.2),
nn.Linear(input_dim, 1),
)
def forward(self, x: torch.Tensor) -> torch.Tensor:
return self.head(x).squeeze(-1)
class QuestionHead(nn.Module):
def __init__(self, input_dim: int, num_questions: int = 8):
super().__init__()
self.head = nn.Sequential(
nn.LayerNorm(input_dim),
nn.Dropout(0.2),
nn.Linear(input_dim, num_questions),
)
def forward(self, x: torch.Tensor) -> torch.Tensor:
return self.head(x)
class ClassificationHead(nn.Module):
def __init__(self, input_dim: int):
super().__init__()
self.head = nn.Sequential(
nn.LayerNorm(input_dim),
nn.Dropout(0.2),
nn.Linear(input_dim, 1),
)
def forward(self, x: torch.Tensor) -> torch.Tensor:
return self.head(x).squeeze(-1)
class ConfidenceHead(nn.Module):
def __init__(self, input_dim: int):
super().__init__()
self.head = nn.Sequential(
nn.LayerNorm(input_dim),
nn.Dropout(0.2),
nn.Linear(input_dim, 1),
nn.Sigmoid(),
)
def forward(self, x: torch.Tensor) -> torch.Tensor:
return self.head(x).squeeze(-1)
|