nharrel commited on
Commit
5b0bab2
·
verified ·
1 Parent(s): 4e61b88

Update README.md

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