File size: 837 Bytes
ba5db94
 
 
 
7d132b9
ba5db94
 
 
 
763e962
 
 
 
 
 
2eda4ed
763e962
 
 
 
 
 
 
 
ba5db94
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
---
license: "mit"
---

This is a fine-tuned RoBERTa model that takes text (up to a few sentences) and predicts to what extent it contains empathic language. 

Example classification:

```python
import torch
import tensorflow as tf
from transformers import RobertaTokenizer, RobertaModel
from transformers import AutoModelForSequenceClassification
from transformers import TFAutoModelForSequenceClassification
from transformers import AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained("paragon-analytics/bert_empathy")
model = AutoModelForSequenceClassification.from_pretrained("paragon-analytics/bert_empathy")

def roberta(x):
    encoded_input = tokenizer(x, return_tensors='pt')
    output = model(**encoded_input)
    scores = output[0][0].detach().numpy()
    scores = tf.nn.softmax(scores)
    return scores.numpy()[1]

```