Views
No views yet
| Model | RMSE |
|---|---|
| Base | 0.5038 |
| XSmall | 0.6296 |
1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import torch
3
4model_name="agentlans/deberta-v3-base-readability-v2"
5
6# Put model on GPU or else CPU
7tokenizer = AutoTokenizer.from_pretrained(model_name)
8model = AutoModelForSequenceClassification.from_pretrained(model_name)
9device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
10model = model.to(device)
11
12def readability(text):
13 """Processes the text using the model and returns its logits.
14 In this case, it's reading grade level in years of education
15 (the higher the number, the harder it is to read the text)."""
16 inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True).to(device)
17 with torch.no_grad():
18 logits = model(**inputs).logits.squeeze().cpu()
19 return logits.tolist()
20
21# Example usage
22texts = [x.strip() for x in """
23The cat sat on the mat.
24I like to eat pizza and ice cream for dinner.
25The quick brown fox jumps over the lazy dog.
26Students must complete their homework before watching television.
27The intricate ecosystem of the rainforest supports a diverse array of flora and fauna.
28Quantum mechanics describes the behavior of matter and energy at the molecular, atomic, nuclear, and even smaller microscopic levels.
29The socioeconomic ramifications of globalization have led to unprecedented levels of interconnectedness and cultural homogenization.
30The ontological argument for the existence of God posits that the very concept of a maximally great being necessitates its existence in reality.
31""".strip().split("\n")]
32
33result = readability(texts)
34for x, s in zip(texts, result):
35 print(f"Text: {x}\nReadability grade: {round(s, 2)}\n")base size model:Text: The cat sat on the mat.
Readability grade: 2.34
Text: I like to eat pizza and ice cream for dinner.
Readability grade: 3.56
Text: The quick brown fox jumps over the lazy dog.
Readability grade: 3.72
Text: Students must complete their homework before watching television.
Readability grade: 10.79
Text: The intricate ecosystem of the rainforest supports a diverse array of flora and fauna.
Readability grade: 11.1
Text: Quantum mechanics describes the behavior of matter and energy at the molecular, atomic, nuclear, and even smaller microscopic levels.
Readability grade: 17.11
Text: The socioeconomic ramifications of globalization have led to unprecedented levels of interconnectedness and cultural homogenization.
Readability grade: 19.53
Text: The ontological argument for the existence of God posits that the very concept of a maximally great being necessitates its existence in reality.
Readability grade: 16.8