Download LE_detection/model.py from shallowblueQAQ/PsyEvent-model: direct link, hf CLI and curl.
- Browser
- Download file 859 Bytes
-
https://huggingface.co/shallowblueQAQ/PsyEvent-model/resolve/main/LE_detection/model.py
- Command line
-
hf download hf://shallowblueQAQ/PsyEvent-model/LE_detection/model.py
-
curl -L -o model.py https://huggingface.co/shallowblueQAQ/PsyEvent-model/resolve/main/LE_detection/model.py
859 Bytes
| import torch | |
| from torch import nn | |
| from transformers import AutoModel, PreTrainedModel, AutoConfig | |
| class BERTDiseaseClassifier(nn.Module): | |
| def __init__(self, model_type, num_symps) -> None: | |
| super().__init__() | |
| self.model_type = model_type | |
| self.num_symps = num_symps | |
| # multi-label binary classification | |
| self.encoder = AutoModel.from_pretrained(model_type) | |
| self.dropout = nn.Dropout(self.encoder.config.hidden_dropout_prob) | |
| self.clf = nn.Linear(self.encoder.config.hidden_size, num_symps) | |
| def forward(self, input_ids=None, attention_mask=None, token_type_ids=None, **kwargs): | |
| outputs = self.encoder(input_ids, attention_mask, token_type_ids) | |
| x = outputs.last_hidden_state[:, 0, :] # [CLS] pooling | |
| x = self.dropout(x) | |
| logits = self.clf(x) | |
| return logits |