MCPcopy Create free account
hub / github.com/algorithmicsuperintelligence/optillm / OptILMClassifier

Class OptILMClassifier

scripts/train_optillm_classifier.py:110–128  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

108 return (predictions == labels).float().mean()
109
110class OptILMClassifier(nn.Module):
111 def __init__(self, base_model, num_labels):
112 super().__init__()
113 self.base_model = base_model
114 self.effort_encoder = nn.Sequential(
115 nn.Linear(1, 64),
116 nn.ReLU(),
117 nn.Linear(64, 64),
118 nn.ReLU()
119 )
120 self.classifier = nn.Linear(base_model.config.hidden_size + 64, num_labels)
121
122 def forward(self, input_ids, attention_mask, effort):
123 outputs = self.base_model(input_ids=input_ids, attention_mask=attention_mask)
124 pooled_output = outputs.last_hidden_state[:, 0] # Shape: (batch_size, hidden_size)
125 effort_encoded = self.effort_encoder(effort.unsqueeze(1)) # Shape: (batch_size, 64)
126 combined_input = torch.cat((pooled_output, effort_encoded), dim=1)
127 logits = self.classifier(combined_input)
128 return logits
129
130def train(model, train_dataloader, val_dataloader, optimizer, scheduler, num_epochs, patience, clip_value):
131 best_val_accuracy = 0.0

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected