Text Classification
Transformers
PyTorch
Safetensors
English
empathy_classifier
feature-extraction
empathy
mental-health
psychology
custom_code
Instructions to use RyanDDD/empathy-mental-health-reddit-ER with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use RyanDDD/empathy-mental-health-reddit-ER with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="RyanDDD/empathy-mental-health-reddit-ER", trust_remote_code=True)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("RyanDDD/empathy-mental-health-reddit-ER", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Upload folder using huggingface_hub
Browse files- modeling_empathy.py +5 -3
modeling_empathy.py
CHANGED
|
@@ -99,10 +99,11 @@ class BiEncoderAttentionWithRationaleClassification(nn.Module):
|
|
| 99 |
|
| 100 |
self.apply(self._init_weights)
|
| 101 |
|
| 102 |
-
#
|
|
|
|
| 103 |
roberta_config = RobertaConfig.from_pretrained("roberta-base")
|
| 104 |
-
self.seeker_encoder = RobertaModel
|
| 105 |
-
self.responder_encoder = RobertaModel
|
| 106 |
|
| 107 |
def _init_weights(self, module):
|
| 108 |
"""Initialize the weights"""
|
|
@@ -212,6 +213,7 @@ class EmpathyModelConfig(PretrainedConfig):
|
|
| 212 |
class EmpathyModel(PreTrainedModel):
|
| 213 |
"""HuggingFace wrapper for Empathy Model"""
|
| 214 |
config_class = EmpathyModelConfig
|
|
|
|
| 215 |
|
| 216 |
def __init__(self, config):
|
| 217 |
super().__init__(config)
|
|
|
|
| 99 |
|
| 100 |
self.apply(self._init_weights)
|
| 101 |
|
| 102 |
+
# Initialize RoBERTa encoders (will be loaded from saved weights)
|
| 103 |
+
# Don't use from_pretrained here to avoid overwriting trained weights
|
| 104 |
roberta_config = RobertaConfig.from_pretrained("roberta-base")
|
| 105 |
+
self.seeker_encoder = RobertaModel(config=roberta_config)
|
| 106 |
+
self.responder_encoder = RobertaModel(config=roberta_config)
|
| 107 |
|
| 108 |
def _init_weights(self, module):
|
| 109 |
"""Initialize the weights"""
|
|
|
|
| 213 |
class EmpathyModel(PreTrainedModel):
|
| 214 |
"""HuggingFace wrapper for Empathy Model"""
|
| 215 |
config_class = EmpathyModelConfig
|
| 216 |
+
base_model_prefix = "model" # Important: matches the saved state_dict structure
|
| 217 |
|
| 218 |
def __init__(self, config):
|
| 219 |
super().__init__(config)
|