PLUG-challenge / models.py
alanclayrichard's picture
lohi splits and supervised and unsupervised tracks
49442cb
Raw History Blame Contribute Delete
4.9 kB
"""Pydantic model for a PLUG challenge submission."""
import uuid
from datetime import UTC, datetime
from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator
from plug_challenge.benchmarks import TRACKS
from utils import safeify_username
class Submission(BaseModel):
"""One competition submission: a bundle plus who sent it.
Serialised to JSON and stored beside the uploaded bundle in the private
dataset repo. Only the non-private fields ever reach the leaderboard.
A PLUG submission always covers every benchmark in one bundle, so the
benchmark breakdown lives in the scores rather than in the submission's
identity. What does belong to the identity is the ``track``: supervised and
unsupervised entries are ranked on separate leaderboards.
Attributes
----------
model_config
``protected_namespaces=()`` disables Pydantic's "model_" warning, which
would otherwise fire on ``model_report_link``.
submission_id : str
Auto-generated UUID; the storage path component.
submitted_at : datetime
UTC timestamp of submission.
username : str
Hugging Face username. Required, and with ``track`` the deduplication
key: only a user's latest submission to each track is ranked.
track : str
``supervised`` (scored on the Lo-Hi test rows) or ``unsupervised``
(scored on every row of every benchmark).
safe_username : str
Path-safe form of ``username``, derived automatically.
user_alias : str
Display name shown instead of the username for anonymous entries.
anonymous : bool
If True, show ``user_alias`` on the leaderboard.
participant_name : str
Real name — stored privately, never displayed.
discord_username : str
Contact handle — stored privately.
email : str
Contact email — stored privately.
affiliation : str
Institutional affiliation — stored privately.
model_report_link : str
URL describing the method — a report, preprint or code repository.
Required, and displayed on the leaderboard.
used_proprietary_data : bool
Whether non-public training data was used. Displayed publicly.
open_source_code : bool
Whether the method's code is public. Displayed publicly.
filename : str
Original uploaded filename.
bundle_path : str
Path the bundle was stored at in the private repo.
"""
model_config = ConfigDict(protected_namespaces=())
# --- generated ---
submission_id: str = Field(default_factory=lambda: str(uuid.uuid4()))
submitted_at: datetime = Field(default_factory=lambda: datetime.now(UTC))
# --- public identity ---
username: str
track: str
safe_username: str = ""
user_alias: str = ""
anonymous: bool = True
# --- private contact ---
participant_name: str = ""
discord_username: str = ""
email: str = ""
affiliation: str = ""
# --- public disclosures ---
model_report_link: str
used_proprietary_data: bool = False
open_source_code: bool = False
# --- submission ---
filename: str = ""
bundle_path: str = ""
@field_validator("track")
@classmethod
def _known_track(cls, track: str) -> str:
"""Reject a track the challenge does not run."""
if track not in TRACKS:
raise ValueError(f"track must be one of {', '.join(TRACKS)}, got {track!r}")
return track
@model_validator(mode="after")
def _populate_safe_username(self) -> "Submission":
"""Derive ``safe_username`` from ``username`` after construction."""
self.safe_username = safeify_username(self.username)
return self
@property
def display_name(self) -> str:
"""Name to show on the leaderboard."""
if self.anonymous and self.user_alias:
return self.user_alias
return self.username
def public_fields(self) -> dict:
"""Return the identity columns that go into a leaderboard row.
``username`` is the display name, so an anonymous entry never writes the
real account name into the leaderboard file; ``safe_username`` is kept as
the (non-displayed) deduplication and cooldown key.
Returns
-------
dict
Leaderboard identity columns for this submission.
"""
return {
"submission_id": self.submission_id,
"submitted_at": self.submitted_at.isoformat(),
"track": self.track,
"username": self.display_name,
"safe_username": self.safe_username,
"anonymous": self.anonymous,
"model_report_link": self.model_report_link,
"used_proprietary_data": self.used_proprietary_data,
"open_source_code": self.open_source_code,
}