agentlans commited on
Commit
03be571
·
verified ·
1 Parent(s): 1ed045e

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +54 -1
README.md CHANGED
@@ -29,7 +29,60 @@ More information needed
29
 
30
  ## Intended uses & limitations
31
 
32
- More information needed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
 
34
  ## Training and evaluation data
35
 
 
29
 
30
  ## Intended uses & limitations
31
 
32
+ Example use:
33
+ ```python
34
+ import torch
35
+ import numpy as np
36
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer
37
+
38
+ # Load model and tokenizer
39
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
40
+
41
+ model_name = "agentlans/deberta-v3-base-zyda-2-readability"
42
+ model = AutoModelForSequenceClassification.from_pretrained(model_name, num_labels=1).to(device)
43
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
44
+
45
+ # Function to perform inference
46
+ def predict_score(text):
47
+ inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True).to(device)
48
+ with torch.no_grad():
49
+ logits = model(**inputs).logits
50
+ return logits.item()
51
+
52
+ # Function to transform the score back to educational grade level
53
+ def grade_level(y):
54
+ # Updated parameters
55
+ lambda_ = 0.8766912
56
+ mean = 7.908629
57
+ sd = 3.339119
58
+
59
+ # Unstandardize the data
60
+ y_unstd = (-y) * sd + mean
61
+
62
+ # Invert the Box-Cox transformation
63
+ return np.power((y_unstd * lambda_ + 1), (1 / lambda_))
64
+
65
+ # Example usage
66
+ input_text = "The mitochondria is the powerhouse of the cell."
67
+ readability = predict_score(input_text)
68
+ grade = grade_level(readability)
69
+ print(f"Predicted score: {readability}\nGrade: {grade}")
70
+ ```
71
+
72
+ Example output:
73
+
74
+ | Text | Readability | Grade |
75
+ |------|---------:|-----:|
76
+ | I like to eat apples. | 1.95 | 2.5 |
77
+ | The cat is on the mat. | 1.93 | 2.6 |
78
+ | The sun is shining brightly today. | 1.85 | 2.9 |
79
+ | Birds are singing in the trees. | 1.84 | 2.9 |
80
+ | The quick brown fox jumps over the lazy dog. | 1.74 | 3.3 |
81
+ | She enjoys reading books in her free time. | 1.69 | 3.5 |
82
+ | After a long day at work, he finally relaxed with a cup of tea. | 1.16 | 5.6 |
83
+ | As the storm approached, the sky turned a deep shade of gray, casting an eerie shadow over the landscape. | 0.54 | 8.2 |
84
+ | Despite the challenges they faced, the team remained resolute in their pursuit of excellence and innovation. | -0.49 | 12.8 |
85
+ | In a world increasingly dominated by technology, the delicate balance between human connection and digital interaction has become a focal point of contemporary discourse. | -2.01 | 20.0 |
86
 
87
  ## Training and evaluation data
88