Text Classification
Transformers
Safetensors
English
modernbert
lean
lean4
theorem-proving
formal-verification
encoder
text-embeddings-inference
Instructions to use EPFL-LARA/lean-encoder-modernbert-large with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use EPFL-LARA/lean-encoder-modernbert-large with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="EPFL-LARA/lean-encoder-modernbert-large")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("EPFL-LARA/lean-encoder-modernbert-large") model = AutoModelForSequenceClassification.from_pretrained("EPFL-LARA/lean-encoder-modernbert-large", device_map="auto") - Notebooks
- Google Colab
- Kaggle
File size: 1,115 Bytes
1b6fcc6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | import json
import torch
from transformers import AutoModelForSequenceClassification, AutoTokenizer
from predict import encode_head_tail
MODEL_ID = 'EPFL-LARA/lean-encoder-modernbert-large'
source_code = """import Mathlib
theorem nat_add_zero_identity (n : ℕ) : n + 0 = n := by
rfl
"""
device = "cuda" if torch.cuda.is_available() else "cpu"
dtype = torch.bfloat16 if device == "cuda" else torch.float32
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
model = AutoModelForSequenceClassification.from_pretrained(
MODEL_ID, dtype=dtype, attn_implementation="sdpa",
).to(device).eval()
inputs = encode_head_tail(
tokenizer, [source_code], max_length=8192, head_fraction=0.25,
)
inputs = {key: value.to(device) for key, value in inputs.items()}
with torch.inference_mode():
probabilities = model(**inputs).logits[0].float().softmax(dim=-1)
probability_valid = float(probabilities[1]) # Class 0: INVALID; class 1: VALID.
print(json.dumps({
"is_valid": probability_valid >= 0.5,
"valid_probability": probability_valid,
"invalid_probability": float(probabilities[0]),
}, indent=2))
|