Views
No views yet
answerdotai/ModernBERT-base1from transformers import AutoModelForSequenceClassification, AutoTokenizer
2import torch
3
4# Load model and tokenizer
5model = AutoModelForSequenceClassification.from_pretrained("kiddom/modernbert-readability-grade-predictor")
6tokenizer = AutoTokenizer.from_pretrained("kiddom/modernbert-readability-grade-predictor")
7
8# Prepare text
9text = "Your text goes here."
10inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=512)
11
12# Run inference
13with torch.no_grad():
14 outputs = model(**inputs)
15
16# Get prediction (ensure it's between 0 and 12)
17pred_grade = outputs.logits.item()
18pred_grade = max(0, min(pred_grade, 12.0))
19print(f"Predicted grade level: {pred_grade:.1f}")The cat sat on the mat. It was happy. The sun was shining.The water cycle is a continuous process that includes evaporation, condensation, and precipitation. ...The quantum mechanical model of atomic structure provides a theoretical framework for understanding ...