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
Download example_transformers.py from EPFL-LARA/lean-encoder-modernbert-large: direct link, hf CLI and curl.
- Browser
- Download file 1.12 kB
-
https://huggingface.co/EPFL-LARA/lean-encoder-modernbert-large/resolve/main/example_transformers.py
- Command line
-
hf download hf://EPFL-LARA/lean-encoder-modernbert-large/example_transformers.py
-
curl -L -o example_transformers.py https://huggingface.co/EPFL-LARA/lean-encoder-modernbert-large/resolve/main/example_transformers.py
1.12 kB
| 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)) | |