/
maratgaliulin
/
landcode_classifier
Обзор
Документация
Войти
/
maratgaliulin
/
landcode_classifier
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
methods/classes/BertWithNumeric.py
23 строки
1004 B
maratgaliulin
.
21 июн 2026, 18:12
21 июн 2026, 18:12
2f0edd6
Код
Авторство
О чём код?
import torch class BertWithNumeric(torch.nn.Module): def __init__(self, bert_model, num_labels, dropout=0.1, use_numeric_area=False): super().__init__() self.bert = bert_model self.dropout = torch.nn.Dropout(dropout) self.use_numeric_area = use_numeric_area device = torch.device("cuda" if torch.cuda.is_available() else "cpu") in_features = self.bert.config.hidden_size + (1 if use_numeric_area else 0) self.classifier = torch.nn.Linear(in_features, num_labels, True, device) def forward(self, input_ids, attention_mask, area=None): outputs = self.bert(input_ids=input_ids, attention_mask=attention_mask) pooled_output = outputs.pooler_output pooled_output = self.dropout(pooled_output) if self.use_numeric_area: combined = torch.cat([pooled_output, area.unsqueeze(1)], dim=1) else: combined = pooled_output logits = self.classifier(combined) return logits