agentlans/readability
Viewer • Updated • 131k • 46
How to use agentlans/deberta-v3-xsmall-readability with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-classification", model="agentlans/deberta-v3-xsmall-readability") # Load model directly
from transformers import AutoTokenizer, AutoModelForSequenceClassification
tokenizer = AutoTokenizer.from_pretrained("agentlans/deberta-v3-xsmall-readability")
model = AutoModelForSequenceClassification.from_pretrained("agentlans/deberta-v3-xsmall-readability")# Load model directly
from transformers import AutoTokenizer, AutoModelForSequenceClassification
tokenizer = AutoTokenizer.from_pretrained("agentlans/deberta-v3-xsmall-readability")
model = AutoModelForSequenceClassification.from_pretrained("agentlans/deberta-v3-xsmall-readability")This is a fine-tuned DeBERTa-v3-xsmall model for predicting the readability level of English texts.
Suitable for:
The model was fine-tuned on the agentlans/readability dataset containing paragraphs from four sources.
Each paragraph was annotated with 6 readability metrics that estimate U.S. grade level reading comprehension.
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
model_name="agentlans/deberta-v3-xsmall-readability"
# Put model on GPU or else CPU
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = model.to(device)
def readability(text):
"""Processes the text using the model and returns its logits.
In this case, it's reading grade level in years of education
(the higher the number, the harder it is to read the text)."""
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True).to(device)
with torch.no_grad():
logits = model(**inputs).logits.squeeze().cpu()
return logits.tolist()
# Example usage
text = ["One day, Tim's teddy bear was sad. Tim did not know why his teddy bear was sad.",
"A few years back, I decided it was time for me to take a break from my mundane routine and embark on an adventure.",
"We also experimentally verify that simply scaling the pulse energy by 3/2 between linearly and circularly polarized pumping closely reproduces the soliton and dispersive wave dynamics."]
result = readability(text)
[round(x, 1) for x in result] # Estimated reading grades [2.9, 9.8, 21.9]
On the evaluation set:
Base model
microsoft/deberta-v3-xsmall
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="agentlans/deberta-v3-xsmall-readability")