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
| #!/usr/bin/env python3 | |
| # Example usage of empathy-mental-health-reddit-ER | |
| from transformers import AutoModel, AutoTokenizer | |
| import torch | |
| # Load model | |
| model_name = "RyanDDD/empathy-mental-health-reddit-ER" | |
| tokenizer = AutoTokenizer.from_pretrained(model_name) | |
| model = AutoModel.from_pretrained(model_name, trust_remote_code=True) | |
| # Example | |
| seeker_post = "I've been feeling really anxious lately." | |
| response_post = "I understand how difficult that must be. Anxiety can be overwhelming." | |
| # Tokenize | |
| encoded_sp = tokenizer(seeker_post, max_length=64, padding='max_length', | |
| truncation=True, return_tensors='pt') | |
| encoded_rp = tokenizer(response_post, max_length=64, padding='max_length', | |
| truncation=True, return_tensors='pt') | |
| # Predict | |
| model.eval() | |
| with torch.no_grad(): | |
| outputs = model( | |
| input_ids_SP=encoded_sp['input_ids'], | |
| input_ids_RP=encoded_rp['input_ids'], | |
| attention_mask_SP=encoded_sp['attention_mask'], | |
| attention_mask_RP=encoded_rp['attention_mask'] | |
| ) | |
| logits_empathy = outputs[0] | |
| logits_rationale = outputs[1] | |
| empathy_level = torch.argmax(logits_empathy, dim=1).item() | |
| print(f"Empathy Level (ER): {['Low', 'Medium', 'High'][empathy_level]}") | |