ziyuzhou02 commited on
Commit
c99f474
·
verified ·
1 Parent(s): af99df1

Deploy Space: update src

Browse files
Files changed (2) hide show
  1. src/about.py +16 -5
  2. src/utils.py +194 -0
src/about.py CHANGED
@@ -4,10 +4,12 @@ INTRODUCTION_TEXT = """
4
  **TSFM Realworld Bench** evaluates time series foundation models on **live TS-Bench
5
  real-world data** with **zero-shot API inference** via [TSFM.ai](https://tsfm.ai/).
6
  Following [GIFT-Eval](https://huggingface.co/spaces/Salesforce/GIFT-Eval), the leaderboard
7
- reports **absolute metric values** (not normalized to a baseline model) and **per-dataset
8
- ranks**. The Overall tab also reports **RankScore**, an Elo-style rank-based aggregate
9
- computed from per-dataset MSE and CRPS ranks. Use the **Overall** tab for aggregate scores;
10
- each subsequent tab is one **dataset (domain)** with its own absolute results.
 
 
11
  """
12
 
13
  LLM_BENCHMARKS_TEXT = """
@@ -38,9 +40,18 @@ Once your Pull Request is opened, our automated sandbox pipeline will load your
38
  ## Metrics
39
 
40
  - **MSE** — Mean Squared Error on the mean forecast (absolute)
41
- - **CRPS** — Mean Weighted Sum Quantile Loss (probabilistic forecast quality)
 
 
 
 
 
 
42
  - **RankScore** — Elo-style aggregate from per-dataset MSE and CRPS ranks (higher is better)
43
  - **MSE_Rank** / **CRPS_Rank** — per-dataset rank (lower is better)
 
 
 
44
  """
45
 
46
  CITATION_BUTTON_LABEL = "Copy citation"
 
4
  **TSFM Realworld Bench** evaluates time series foundation models on **live TS-Bench
5
  real-world data** with **zero-shot API inference** via [TSFM.ai](https://tsfm.ai/).
6
  Following [GIFT-Eval](https://huggingface.co/spaces/Salesforce/GIFT-Eval), the leaderboard
7
+ reports **absolute metric values** and **per-dataset ranks**. The Overall tab also reports
8
+ the cumulative **up-to-now live result** with MSE, RMSE, MAPE, quantile CRPS, RTG,
9
+ temporal Stability, Kendall Improvement, Average Rank, Win Rate, and Elo. The
10
+ **GIFT-style Aggregates** tab provides Seasonal-Naive-normalized MSE, CRPS,
11
+ and mean CRPS rank grouped by actual prediction length, domain, and frequency. Each
12
+ subsequent domain tab retains the original absolute per-dataset results.
13
  """
14
 
15
  LLM_BENCHMARKS_TEXT = """
 
40
  ## Metrics
41
 
42
  - **MSE** — Mean Squared Error on the mean forecast (absolute)
43
+ - **RMSE** — Root Mean Squared Error on the mean forecast
44
+ - **MAPE** — Mean Absolute Percentage Error, reported only away from zero
45
+ - **CRPS** — quantile approximation of the Continuous Ranked Probability Score
46
+ - **RTG** — normalized real-time MSE gain over causal Seasonal-Naive (higher is better)
47
+ - **Stability** — standard deviation of release-level MSE (lower is better)
48
+ - **Improvement** — Kendall trend statistic over release-level MSE (more negative is better)
49
+ - **Average Rank / Win Rate / Elo** — paired summaries over shared future releases
50
  - **RankScore** — Elo-style aggregate from per-dataset MSE and CRPS ranks (higher is better)
51
  - **MSE_Rank** / **CRPS_Rank** — per-dataset rank (lower is better)
52
+ - **Grouped MSE / CRPS** — geometric mean after per-configuration normalization against
53
+ Seasonal-Naive (lower is better; 1.0 equals the baseline)
54
+ - **Grouped Rank** — mean per-configuration CRPS rank (lower is better)
55
  """
56
 
57
  CITATION_BUTTON_LABEL = "Copy citation"
src/utils.py CHANGED
@@ -83,6 +83,23 @@ RESULT_COLUMNS = [
83
  "num_variates",
84
  ]
85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
 
87
  def format_number(value):
88
  if isinstance(value, (int, float)):
@@ -289,6 +306,183 @@ def prepare_ranks_table(ranks_df: pd.DataFrame) -> pd.DataFrame:
289
  return format_df(table)
290
 
291
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
292
  DOMAIN_DISPLAY = {
293
  "Weather": "Climate",
294
  "Air Quality": "Climate",
 
83
  "num_variates",
84
  ]
85
 
86
+ GIFT_AGGREGATE_FILES = {
87
+ "prediction_length": "results_by_prediction_length.csv",
88
+ "domain": "results_by_domain.csv",
89
+ "frequency": "results_by_frequency.csv",
90
+ }
91
+
92
+ GIFT_AGGREGATE_LABELS = {
93
+ "prediction_length": "Prediction Length",
94
+ "domain": "Domain",
95
+ "frequency": "Frequency",
96
+ }
97
+
98
+ LIVE_AGGREGATE_FILES = {
99
+ "overall": "live_overall_up_to_now.csv",
100
+ "rank": "live_rank_up_to_now.csv",
101
+ }
102
+
103
 
104
  def format_number(value):
105
  if isinstance(value, (int, float)):
 
306
  return format_df(table)
307
 
308
 
309
+ def load_gift_aggregate_table(
310
+ root_dir: str = "results",
311
+ dimension: str = "prediction_length",
312
+ ) -> pd.DataFrame:
313
+ """Load one persisted GIFT-Eval-style grouped result table."""
314
+
315
+ if dimension not in GIFT_AGGREGATE_FILES:
316
+ raise ValueError(f"Unknown aggregate dimension: {dimension}")
317
+
318
+ label = GIFT_AGGREGATE_LABELS[dimension]
319
+ columns = [label, "Model", "MSE", "CRPS", "Rank", "Configs", "Coverage"]
320
+ path = Path(root_dir) / "aggregates" / GIFT_AGGREGATE_FILES[dimension]
321
+ if not path.exists():
322
+ return pd.DataFrame(columns=columns)
323
+ try:
324
+ table = pd.read_csv(path)
325
+ except (OSError, pd.errors.ParserError, pd.errors.EmptyDataError):
326
+ return pd.DataFrame(columns=columns)
327
+
328
+ required = {
329
+ dimension,
330
+ "model",
331
+ "MSE",
332
+ "CRPS",
333
+ "Rank",
334
+ "n_configs",
335
+ "n_group_configs",
336
+ "coverage",
337
+ }
338
+ if table.empty or not required.issubset(table.columns):
339
+ return pd.DataFrame(columns=columns)
340
+
341
+ table = table.sort_values([dimension, "Rank", "model"]).copy()
342
+ table["Configs"] = (
343
+ table["n_configs"].fillna(0).astype(int).astype(str)
344
+ + "/"
345
+ + table["n_group_configs"].fillna(0).astype(int).astype(str)
346
+ )
347
+ table["Coverage"] = table["coverage"].map(
348
+ lambda value: "n/a" if pd.isna(value) else f"{100.0 * float(value):.1f}%"
349
+ )
350
+ for metric in ("MSE", "CRPS", "Rank"):
351
+ table[metric] = pd.to_numeric(table[metric], errors="coerce").round(3)
352
+ table = table.rename(columns={dimension: label, "model": "Model"})
353
+ return table.loc[:, columns].reset_index(drop=True)
354
+
355
+
356
+ def load_gift_aggregate_metadata_md(root_dir: str = "results") -> str:
357
+ path = Path(root_dir) / "aggregates" / "metadata.json"
358
+ if not path.exists():
359
+ return "Aggregate metadata is not available yet."
360
+ try:
361
+ metadata = json.loads(path.read_text())
362
+ except (OSError, json.JSONDecodeError):
363
+ return "Aggregate metadata could not be loaded."
364
+ generated = format_timestamp_utc8(metadata.get("generated_at", ""))
365
+ return (
366
+ f"**Protocol:** per-configuration normalization against "
367
+ f"`{metadata.get('baseline_model', 'Seasonal-Naive')}`; geometric mean for "
368
+ f"MSE/CRPS; mean CRPS rank. **Coverage:** "
369
+ f"{metadata.get('num_models', 0)} models × {metadata.get('num_configs', 0)} "
370
+ f"configurations. **Generated:** {generated}."
371
+ )
372
+
373
+
374
+ def load_live_aggregate_table(
375
+ root_dir: str = "results",
376
+ table: str = "overall",
377
+ ) -> pd.DataFrame:
378
+ """Load the cumulative future-release metric or rank table."""
379
+
380
+ if table not in LIVE_AGGREGATE_FILES:
381
+ raise ValueError(f"Unknown live aggregate table: {table}")
382
+ if table == "overall":
383
+ columns = [
384
+ "Rank",
385
+ "Model",
386
+ "MSE",
387
+ "RMSE",
388
+ "MAPE",
389
+ "CRPS",
390
+ "RTG",
391
+ "Stability",
392
+ "Improvement",
393
+ "Datasets",
394
+ "Releases",
395
+ ]
396
+ else:
397
+ columns = [
398
+ "Rank",
399
+ "Model",
400
+ "Average Rank",
401
+ "Win Rate",
402
+ "Elo",
403
+ "Dataset Pair Matches",
404
+ "Shared Releases",
405
+ "Pairwise Matches",
406
+ ]
407
+
408
+ path = Path(root_dir) / "aggregates" / LIVE_AGGREGATE_FILES[table]
409
+ if not path.exists():
410
+ return pd.DataFrame(columns=columns)
411
+ try:
412
+ frame = pd.read_csv(path)
413
+ except (OSError, pd.errors.ParserError, pd.errors.EmptyDataError):
414
+ return pd.DataFrame(columns=columns)
415
+ if frame.empty:
416
+ return pd.DataFrame(columns=columns)
417
+
418
+ if table == "overall":
419
+ source_columns = [
420
+ "Rank",
421
+ "model",
422
+ "MSE",
423
+ "RMSE",
424
+ "MAPE",
425
+ "CRPS",
426
+ "RTG",
427
+ "Stability",
428
+ "Improvement",
429
+ "n_datasets",
430
+ "n_releases",
431
+ ]
432
+ if not set(source_columns).issubset(frame.columns):
433
+ return pd.DataFrame(columns=columns)
434
+ frame = frame[source_columns].rename(
435
+ columns={"model": "Model", "n_datasets": "Datasets", "n_releases": "Releases"}
436
+ )
437
+ for metric in ("MSE", "RMSE", "MAPE", "CRPS", "RTG", "Stability", "Improvement"):
438
+ frame[metric] = pd.to_numeric(frame[metric], errors="coerce").round(4)
439
+ else:
440
+ source_columns = [
441
+ "Rank",
442
+ "model",
443
+ "AverageRank",
444
+ "WinRate",
445
+ "Elo",
446
+ "dataset_pair_matches",
447
+ "shared_releases",
448
+ "pairwise_matches",
449
+ ]
450
+ if not set(source_columns).issubset(frame.columns):
451
+ return pd.DataFrame(columns=columns)
452
+ frame = frame[source_columns].rename(
453
+ columns={
454
+ "model": "Model",
455
+ "AverageRank": "Average Rank",
456
+ "WinRate": "Win Rate",
457
+ "dataset_pair_matches": "Dataset Pair Matches",
458
+ "shared_releases": "Shared Releases",
459
+ "pairwise_matches": "Pairwise Matches",
460
+ }
461
+ )
462
+ for metric in ("Average Rank", "Win Rate", "Elo"):
463
+ frame[metric] = pd.to_numeric(frame[metric], errors="coerce").round(4)
464
+ return frame.loc[:, columns].reset_index(drop=True)
465
+
466
+
467
+ def load_live_aggregate_metadata_md(root_dir: str = "results") -> str:
468
+ path = Path(root_dir) / "aggregates" / "live_metadata.json"
469
+ if not path.exists():
470
+ return "Cumulative live metrics are not available yet."
471
+ try:
472
+ metadata = json.loads(path.read_text())
473
+ except (OSError, json.JSONDecodeError):
474
+ return "Cumulative live metric metadata could not be loaded."
475
+ generated = format_timestamp_utc8(metadata.get("generated_at", ""))
476
+ return (
477
+ f"**Up to now:** {metadata.get('num_models', 0)} models, "
478
+ f"{metadata.get('num_datasets', 0)} datasets, and "
479
+ f"{metadata.get('num_unique_releases', 0)} distinct future releases. "
480
+ "MSE/RMSE/CRPS use causal context z-normalization; RTG is relative to "
481
+ "24-step Seasonal-Naive. **Generated:** "
482
+ f"{generated}."
483
+ )
484
+
485
+
486
  DOMAIN_DISPLAY = {
487
  "Weather": "Climate",
488
  "Air Quality": "Climate",