Instructions to use Syigen/rgcm with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Syigen/rgcm with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="Syigen/rgcm")# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("Syigen/rgcm", device_map="auto") - Notebooks
- Google Colab
- Kaggle
File size: 1,686 Bytes
3155e2a | 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 | from __future__ import annotations
import torch
from torch import Tensor, nn
class RawExpert(nn.Module):
def __init__(self, hidden_size: int, decision_size: int):
super().__init__()
self.net = nn.Sequential(
nn.Linear(hidden_size * 2, decision_size),
nn.GELU(),
nn.LayerNorm(decision_size),
nn.Linear(decision_size, decision_size),
)
def forward(self, state: Tensor, question: Tensor) -> Tensor:
return self.net(torch.cat((state, question), dim=-1))
class CandidateScorer(nn.Module):
"""Shared pointwise scorer; candidate permutation only permutes its outputs."""
def __init__(self, decision_size: int):
super().__init__()
self.net = nn.Sequential(
nn.Linear(decision_size * 4, decision_size),
nn.GELU(),
nn.Linear(decision_size, 1),
)
def forward(self, decision: Tensor, candidates: Tensor) -> Tensor:
if decision.ndim == 1:
decision = decision.unsqueeze(0)
if candidates.ndim == 2:
candidates = candidates.unsqueeze(0).expand(decision.size(0), -1, -1)
decision = decision.unsqueeze(1).expand(-1, candidates.size(1), -1)
features = torch.cat(
(decision, candidates, decision * candidates, torch.abs(decision - candidates)), dim=-1
)
return self.net(features).squeeze(-1).squeeze(0)
class NoulHead(nn.Module):
def __init__(self, decision_size: int):
super().__init__()
self.linear = nn.Linear(decision_size, 1)
def forward(self, decision: Tensor) -> Tensor:
return self.linear(decision).squeeze(-1)
|