Upload script.py
Browse files
script.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Submission script for the WMT25 MULR linguistic-reasoning competition.
|
| 2 |
+
|
| 3 |
+
This is what participants put in their submitted Hugging Face MODEL repo. The HF
|
| 4 |
+
Competitions backend:
|
| 5 |
+
1. downloads the hidden test dataset to /tmp/data,
|
| 6 |
+
2. runs `python script.py` in your repo (no internet, no tokens),
|
| 7 |
+
3. uploads the `submission.csv` you write here for scoring.
|
| 8 |
+
|
| 9 |
+
You never see the test data. You only get /tmp/data/test.csv with columns:
|
| 10 |
+
id, prompt
|
| 11 |
+
and you must write `submission.csv` with columns:
|
| 12 |
+
id, prediction
|
| 13 |
+
Every row must have a non-empty prediction (empty/NaN is rejected).
|
| 14 |
+
|
| 15 |
+
Put your model weights in this same repo (downloads are blocked at run time) and load
|
| 16 |
+
them below. The placeholder model just returns "UNKNOWN" for every item.
|
| 17 |
+
"""
|
| 18 |
+
|
| 19 |
+
import os
|
| 20 |
+
import re
|
| 21 |
+
|
| 22 |
+
import pandas as pd
|
| 23 |
+
|
| 24 |
+
TEST_PATH = "/tmp/data/test.csv" # hidden test, provided by the backend
|
| 25 |
+
SUBMISSION_PATH = "submission.csv" # must be written to the working directory
|
| 26 |
+
|
| 27 |
+
# Pandas treats tokens like "N/A", "NA", "null", "None" as NaN; this one is safe.
|
| 28 |
+
EMPTY_PLACEHOLDER = "UNKNOWN"
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def extract_answer(model_output: str) -> str:
|
| 32 |
+
"""Pull the content of the last [...] (the prompt asks for the answer in brackets)."""
|
| 33 |
+
if not isinstance(model_output, str):
|
| 34 |
+
return EMPTY_PLACEHOLDER
|
| 35 |
+
matches = re.findall(r"\[([^\[\]]*)\]", model_output, flags=re.DOTALL)
|
| 36 |
+
if matches:
|
| 37 |
+
ans = matches[-1].strip()
|
| 38 |
+
else:
|
| 39 |
+
lines = [ln.strip() for ln in model_output.splitlines() if ln.strip()]
|
| 40 |
+
ans = lines[-1] if lines else ""
|
| 41 |
+
return ans or EMPTY_PLACEHOLDER
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
# --- Load your model ONCE here -------------------------------------------------
|
| 45 |
+
# from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 46 |
+
# tok = AutoTokenizer.from_pretrained(".") # weights bundled in this repo
|
| 47 |
+
# model = AutoModelForCausalLM.from_pretrained(".", device_map="auto")
|
| 48 |
+
|
| 49 |
+
def solve(prompt: str) -> str:
|
| 50 |
+
"""Return the answer string for one puzzle item. Replace with real inference."""
|
| 51 |
+
# inputs = tok(prompt, return_tensors="pt").to(model.device)
|
| 52 |
+
# out = model.generate(**inputs, max_new_tokens=64, do_sample=False)
|
| 53 |
+
# raw = tok.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)
|
| 54 |
+
# return extract_answer(raw)
|
| 55 |
+
return EMPTY_PLACEHOLDER
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
def main() -> None:
|
| 59 |
+
test = pd.read_csv(TEST_PATH, dtype=str, keep_default_na=False)
|
| 60 |
+
|
| 61 |
+
preds = []
|
| 62 |
+
for _, row in test.iterrows():
|
| 63 |
+
pred = solve(row["prompt"])
|
| 64 |
+
pred = (str(pred).strip() or EMPTY_PLACEHOLDER)
|
| 65 |
+
preds.append({"id": row["id"], "prediction": pred})
|
| 66 |
+
|
| 67 |
+
submission = pd.DataFrame(preds, columns=["id", "prediction"])
|
| 68 |
+
assert submission["id"].is_unique, "duplicate ids in submission"
|
| 69 |
+
assert set(submission["id"]) == set(test["id"]), "submission ids must match the test set"
|
| 70 |
+
assert (submission["prediction"].str.len() > 0).all(), "predictions must be non-empty"
|
| 71 |
+
|
| 72 |
+
submission.to_csv(SUBMISSION_PATH, index=False)
|
| 73 |
+
print(f"Wrote {SUBMISSION_PATH} with {len(submission)} rows")
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
if __name__ == "__main__":
|
| 77 |
+
main()
|