Views
No views yet
1from transformers import AutoModelForSequenceClassification, AutoTokenizer
2
3# Load the model and tokenizer from the Hugging Face Hub
4model_name = "qingy2024/HQRD-109M"
5model = AutoModelForSequenceClassification.from_pretrained(model_name)
6tokenizer = AutoTokenizer.from_pretrained(model_name)
7
8# Example text to classify
9text = "Quantum mechanics is a fundamental branch of physics that describes the behavior of particles on very small scales, such as atoms and subatomic particles. It differs significantly from classical mechanics, which governs macroscopic objects, because it introduces concepts like wave-particle duality, uncertainty, and probabilistic outcomes."
10
11# Tokenize the text
12inputs = tokenizer(text, truncation=True, max_length=512, padding=True, return_tensors="pt")
13
14import torch
15# Perform inference
16with torch.no_grad(): # Disable gradient computation for inference
17 outputs = model(**inputs)
18 prediction = outputs.logits.item() # Extract the single float value
19
20# Interpret the result
21print(f"Prediction score: {prediction:.3f}")