Spaces:
Running
Running
| """ | |
| config.py β Centralised configuration for the Smart MCQ Solver. | |
| All constants, label mappings, model paths, and | |
| example questions live here so they are easy to change in one place. | |
| """ | |
| import os | |
| import torch | |
| # ββ Device ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| DEVICE = "cuda" if torch.cuda.is_available() else "cpu" | |
| # ββ Label mapping (must match training) βββββββββββββββββββββββββββββββββββββββ | |
| LABEL2ID = {"A": 0, "B": 1, "C": 2, "D": 3, "E": 4} | |
| ID2LABEL = {v: k for k, v in LABEL2ID.items()} | |
| NUM_LABELS = 5 | |
| # ββ Tokenisation ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| MAX_LEN = 384 | |
| # ββ Model source ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| # Set MODEL_SOURCE env var to "local" to load from disk instead of the Hub. | |
| # Defaults to "hub" because the Space repo does not ship model weights β | |
| # they live in the separate Pro-aryan00/roberta-mcq-ft model repo. | |
| MODEL_SOURCE = os.environ.get("MODEL_SOURCE", "hub").lower() | |
| # HuggingFace Hub config (used when MODEL_SOURCE == "hub") | |
| HF_USERNAME = os.environ.get("HF_USERNAME", "Pro-aryan00") | |
| HF_TOKEN = os.environ.get("HF_TOKEN", None) | |
| ROBERTA_HUB_REPO = f"{HF_USERNAME}/roberta-mcq-ft" | |
| # Local model paths (used when MODEL_SOURCE == "local") | |
| # Resolve relative to project root, not cwd | |
| _PROJECT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) | |
| ROBERTA_LOCAL_PATH = os.path.join(_PROJECT_ROOT, "models", "roberta-mcq-ft") | |
| # Base checkpoint on HuggingFace Hub (always downloaded from Hub) | |
| ROBERTA_BASE_CHECKPOINT = "roberta-base" | |
| # ββ UI colours for probability bars βββββββββββββββββββββββββββββββββββββββββββ | |
| BAR_COLORS = ["#a78bfa", "#60a5fa", "#34d399", "#f472b6", "#fb923c"] | |
| # ββ Example questions for the demo ββββββββββββββββββββββββββββββββββββββββββββ | |
| # These are real test samples that RoBERTa answered correctly with 99%+ confidence. | |
| EXAMPLES = [ | |
| { | |
| # Sample 10 β SI base unit of time β B (correct: the second) | |
| "prompt": "Which of the following is correct? What is the SI base unit of time and how is it defined? carefully.", | |
| "A": "The SI base unit of time is the week, which is defined by measuring the electronic transition frequency of caesium atoms.", | |
| "B": "The SI base unit of time is the second, which is defined by measuring the electronic transition frequency of caesium atoms.", | |
| "C": "The SI base unit of time is the hour, which is defined by measuring the electronic transition frequency of caesium atoms.", | |
| "D": "The SI base unit of time is the day, which is defined by measuring the electronic transition frequency of caesium atoms.", | |
| "E": "The SI base unit of time is the minute, which is defined by measuring the electronic transition frequency of caesium atoms.", | |
| }, | |
| { | |
| # Sample 9 β Maxwell's Demon β C (correct description) | |
| "prompt": "What is the Maxwell's Demon thought experiment?", | |
| "A": "A thought experiment in which a demon guards a microscopic trapdoor in a wall separating two parts of a container filled with different gases at equal temperatures. The demon selectively allows molecules to pass from one side to the other, causing an increase in temperature in one part and a decrease in temperature in the other, contrary to the second law of thermodynamics.", | |
| "B": "A thought experiment in which a demon guards a macroscopic trapdoor in a wall separating two parts of a container filled with different gases at different temperatures. The demon selectively allows molecules to pass from one side to the other, causing a decrease in temperature in one part and an increase in temperature in the other, in accordance with the second law of thermodynamics.", | |
| "C": "A thought experiment in which a demon guards a microscopic trapdoor in a wall separating two parts of a container filled with the same gas at equal temperatures. The demon selectively allows faster-than-average molecules to pass from one side to the other, causing a decrease in temperature in one part and an increase in temperature in the other, contrary to the second law of thermodynamics.", | |
| "D": "A thought experiment in which a demon guards a macroscopic trapdoor in a wall separating two parts of a container filled with the same gas at equal temperatures. The demon selectively allows faster-than-average molecules to pass from one side to the other, causing an increase in temperature in one part and a decrease in temperature in the other, contrary to the second law of thermodynamics.", | |
| "E": "A thought experiment in which a demon guards a microscopic trapdoor in a wall separating two parts of a container filled with the same gas at different temperatures. The demon selectively allows slower-than-average molecules to pass from one side to the other, causing a decrease in temperature in one part and an increase in temperature in the other, in accordance with the second law of thermodynamics.", | |
| }, | |
| { | |
| # Sample 5 β Landau-Lifshitz-Gilbert equation β C (correct description) | |
| "prompt": "What is the Landau-Lifshitz-Gilbert equation used for in physics?", | |
| "A": "The Landau-Lifshitz-Gilbert equation is a differential equation used to describe the precessional motion of magnetization M in a liquid, and is commonly used in micromagnetics to model the effects of a magnetic field on ferromagnetic materials.", | |
| "B": "The Landau-Lifshitz-Gilbert equation is a differential equation used to describe the precessional motion of magnetization M in a solid, and is commonly used in astrophysics to model the effects of a magnetic field on celestial bodies.", | |
| "C": "The Landau-Lifshitz-Gilbert equation is a differential equation used to describe the precessional motion of magnetization M in a solid, and is commonly used in micromagnetics to model the effects of a magnetic field on ferromagnetic materials.", | |
| "D": "The Landau-Lifshitz-Gilbert equation is a differential equation used to describe the precessional motion of magnetization M in a solid, and is commonly used in macro-magnetics to model the effects of a magnetic field on ferromagnetic materials.", | |
| "E": "The Landau-Lifshitz-Gilbert equation is a differential equation used to describe the precessional motion of magnetization M in a liquid, and is commonly used in macro-magnetics to model the effects of a magnetic field on ferromagnetic materials.", | |
| }, | |
| ] | |