Download desklib_model.py from AkshatSG/hero-api: direct link, hf CLI and curl.
- Browser
- Download file 861 Bytes
-
https://huggingface.co/spaces/AkshatSG/hero-api/resolve/main/desklib_model.py
- Command line
-
hf download hf://spaces/AkshatSG/hero-api/desklib_model.py
-
curl -L -o desklib_model.py https://huggingface.co/spaces/AkshatSG/hero-api/resolve/main/desklib_model.py
861 Bytes
| """desklib/ai-text-detector-v1.01 (DeBERTa-v3-large + mean pooling + linear head): the "Peregrine" model. | |
| Kept in its own file so the detector runs anywhere (no MLX needed), e.g. on a Hugging Face Space.""" | |
| import torch.nn as nn | |
| from transformers import AutoModel, AutoConfig, PreTrainedModel | |
| DESKLIB = "desklib/ai-text-detector-v1.01" | |
| class DesklibModel(PreTrainedModel): | |
| config_class = AutoConfig | |
| def __init__(self, config): | |
| super().__init__(config) | |
| self.model = AutoModel.from_config(config) | |
| self.classifier = nn.Linear(config.hidden_size, 1) | |
| self.post_init() | |
| def forward(self, input_ids, attention_mask): | |
| h = self.model(input_ids, attention_mask=attention_mask)[0] | |
| m = attention_mask.unsqueeze(-1).float() | |
| return self.classifier((h * m).sum(1) / m.sum(1).clamp(min=1e-9)).squeeze(-1) | |