agentlans commited on
Commit
de65283
1 Parent(s): 702a19c

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +24 -0
README.md CHANGED
@@ -32,6 +32,30 @@ The model was trained on [agentlans/tatoeba-english-translations](https://huggin
32
 
33
  ## Usage
34
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  ## Results
36
 
37
  In this study, 10 English text samples of varying readability were generated and translated into Arabic, Chinese, French, Russian, and Spanish using Google Translate. This resulted in a total of 50 translated samples, which were subsequently analyzed by a trained classifier to predict their readability scores.
 
32
 
33
  ## Usage
34
 
35
+ ```python
36
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
37
+ import torch
38
+
39
+ model_name="agentlans/mdeberta-v3-base-readability"
40
+
41
+ # Put model on GPU or else CPU
42
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
43
+ model = AutoModelForSequenceClassification.from_pretrained(model_name)
44
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
45
+ model = model.to(device)
46
+
47
+ def readability(text):
48
+ """Processes the text using the model and returns its logits.
49
+ In this case, it's reading grade level in years of education
50
+ (the higher the number, the harder it is to read the text)."""
51
+ inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True).to(device)
52
+ with torch.no_grad():
53
+ logits = model(**inputs).logits.squeeze().cpu()
54
+ return logits.tolist()
55
+
56
+ readability("Your text here.")
57
+ ```
58
+
59
  ## Results
60
 
61
  In this study, 10 English text samples of varying readability were generated and translated into Arabic, Chinese, French, Russian, and Spanish using Google Translate. This resulted in a total of 50 translated samples, which were subsequently analyzed by a trained classifier to predict their readability scores.