Instructions to use helixiora/distilbert-another-classifier with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use helixiora/distilbert-another-classifier with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, CustomDistilBertClassifier tokenizer = AutoTokenizer.from_pretrained("helixiora/distilbert-another-classifier") model = CustomDistilBertClassifier.from_pretrained("helixiora/distilbert-another-classifier", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Download modeling_custom.py from helixiora/distilbert-another-classifier: direct link, hf CLI and curl.
- Browser
- Download file 903 Bytes
-
https://huggingface.co/helixiora/distilbert-another-classifier/resolve/main/modeling_custom.py
- Command line
-
hf download hf://helixiora/distilbert-another-classifier/modeling_custom.py
-
curl -L -o modeling_custom.py https://huggingface.co/helixiora/distilbert-another-classifier/resolve/main/modeling_custom.py
903 Bytes
| import torch | |
| from transformers import DistilBertForSequenceClassification | |
| label_dict = {0: "Clarification", 1: "Factual", 2: "Operational", 3: "Summarization"} | |
| class CustomDistilBertClassifier(DistilBertForSequenceClassification): | |
| def __init__(self, config): | |
| super().__init__(config) | |
| self.label_map = label_dict # Use your predefined label mapping | |
| def forward(self, input_ids, attention_mask): | |
| outputs = super().forward(input_ids=input_ids, attention_mask=attention_mask) | |
| logits = outputs.logits | |
| predicted_class = torch.argmax(logits, dim=-1).item() | |
| return self.label_map[predicted_class] # Return the string label directly | |
| def from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs): | |
| model = super().from_pretrained(pretrained_model_name_or_path, *model_args, **kwargs) | |
| return model | |