Update README.md
Browse files
README.md
CHANGED
|
@@ -20,54 +20,56 @@ Utilizing this approach, we demonstrated improvements in regression tasks for ev
|
|
| 20 |
|
| 21 |
## Usage
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
| 71 |
|
| 72 |
|
| 73 |
## Results from Qiu et al. (2022)
|
|
|
|
| 20 |
|
| 21 |
## Usage
|
| 22 |
|
| 23 |
+
```python
|
| 24 |
+
|
| 25 |
+
import torch
|
| 26 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 27 |
+
|
| 28 |
+
# Load the model and tokenizer
|
| 29 |
+
model_path = 'nharrel/Valuesnet_DeBERTa_v3'
|
| 30 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
| 31 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_path)
|
| 32 |
+
model.eval()
|
| 33 |
+
|
| 34 |
+
# Define maximum length for padding and truncation
|
| 35 |
+
max_length = 128
|
| 36 |
+
|
| 37 |
+
def custom_round(x):
|
| 38 |
+
if x >= 0.50:
|
| 39 |
+
return 1
|
| 40 |
+
elif x < -0.50:
|
| 41 |
+
return -1
|
| 42 |
+
else:
|
| 43 |
+
return 0
|
| 44 |
+
|
| 45 |
+
def predict(text):
|
| 46 |
+
inputs = tokenizer(text, padding='max_length', truncation=True, max_length=max_length, return_tensors='pt')
|
| 47 |
+
with torch.no_grad():
|
| 48 |
+
outputs = model(**inputs)
|
| 49 |
+
|
| 50 |
+
prediction = torch.tanh(outputs.logits).cpu().numpy()
|
| 51 |
+
rounded_prediction = custom_round(prediction)
|
| 52 |
+
return rounded_prediction
|
| 53 |
+
|
| 54 |
+
def test_sentence(sentence):
|
| 55 |
+
prediction = predict(sentence)
|
| 56 |
+
label_map = {-1: 'Against', 0: 'Not Present', 1: 'Supports'}
|
| 57 |
+
predicted_label = label_map.get(prediction, 'unknown')
|
| 58 |
+
print(f"Sentence: {sentence}")
|
| 59 |
+
print(f"Predicted Label: {predicted_label}")
|
| 60 |
+
|
| 61 |
+
# Define Schwartz's 10 values
|
| 62 |
+
schwartz_values = [
|
| 63 |
+
"BENEVOLENCE", "UNIVERSALISM", "SELF-DIRECTION", "STIMULATION", "HEDONISM",
|
| 64 |
+
"ACHIEVEMENT", "POWER", "SECURITY", "CONFORMITY", "TRADITION"
|
| 65 |
+
]
|
| 66 |
+
|
| 67 |
+
for value in schwartz_values:
|
| 68 |
+
print("Values stance is: " + value)
|
| 69 |
+
test_sentence(f"[{value}] You are a very pleasant person to be around.")
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
```
|
| 73 |
|
| 74 |
|
| 75 |
## Results from Qiu et al. (2022)
|