Text Classification
Transformers
Safetensors
multilingual
snt_classifier
feature-extraction
news
topic-classification
multi-label
xlm-roberta
custom_code
Instructions to use sweenk/snt-classifier with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use sweenk/snt-classifier with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="sweenk/snt-classifier", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("sweenk/snt-classifier", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
SNT classifier v0.5.1
Browse files- modeling_snt.py +4 -2
modeling_snt.py
CHANGED
|
@@ -12,7 +12,7 @@ from __future__ import annotations
|
|
| 12 |
|
| 13 |
import torch
|
| 14 |
import torch.nn as nn
|
| 15 |
-
from transformers import AutoModel, PretrainedConfig, PreTrainedModel
|
| 16 |
|
| 17 |
|
| 18 |
class SNTConfig(PretrainedConfig):
|
|
@@ -55,7 +55,9 @@ class SNTForNewsClassification(PreTrainedModel):
|
|
| 55 |
def __init__(self, config: SNTConfig):
|
| 56 |
super().__init__(config)
|
| 57 |
# Attribute names MUST match DualHeadModel so state_dicts load 1:1.
|
| 58 |
-
|
|
|
|
|
|
|
| 59 |
hidden = self.encoder.config.hidden_size
|
| 60 |
self.dropout = nn.Dropout(config.dropout)
|
| 61 |
self.head_top = nn.Linear(hidden, config.n_l1)
|
|
|
|
| 12 |
|
| 13 |
import torch
|
| 14 |
import torch.nn as nn
|
| 15 |
+
from transformers import AutoConfig, AutoModel, PretrainedConfig, PreTrainedModel
|
| 16 |
|
| 17 |
|
| 18 |
class SNTConfig(PretrainedConfig):
|
|
|
|
| 55 |
def __init__(self, config: SNTConfig):
|
| 56 |
super().__init__(config)
|
| 57 |
# Attribute names MUST match DualHeadModel so state_dicts load 1:1.
|
| 58 |
+
# from_config (not from_pretrained): weights come from this repo's
|
| 59 |
+
# safetensors; from_pretrained breaks under HF's meta-device loading.
|
| 60 |
+
self.encoder = AutoModel.from_config(AutoConfig.from_pretrained(config.encoder_name))
|
| 61 |
hidden = self.encoder.config.hidden_size
|
| 62 |
self.dropout = nn.Dropout(config.dropout)
|
| 63 |
self.head_top = nn.Linear(hidden, config.n_l1)
|