File size: 496 Bytes
dadf189
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from __future__ import annotations

import torch
import torch.nn as nn


class ScoreAggregator(nn.Module):
    """Aggregate concept vector into scalar score in [0, 100]."""

    def __init__(self, k: int = 6):
        super().__init__()
        self.mlp = nn.Sequential(
            nn.Linear(k, 32),
            nn.GELU(),
            nn.Linear(32, 1),
            nn.Sigmoid(),
        )

    def forward(self, concepts: torch.Tensor) -> torch.Tensor:
        return self.mlp(concepts) * 100.0