ancs21 commited on
Commit
f9a6764
·
verified ·
1 Parent(s): f90a4d0

Mantis reproduction bundle

Browse files
Files changed (3) hide show
  1. README.md +13 -0
  2. param_count.py +5 -0
  3. zeroshot_probe.py +52 -0
README.md ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Mantis reproduction bundle
2
+
3
+ Reproduction of **Mantis: Lightweight Foundation Model for Time Series Classification**
4
+ (arXiv:2502.15637, OpenReview gbJMAjXLZ4) for the HF "Reproducing ICML 2026" challenge.
5
+
6
+ Logbook: https://huggingface.co/spaces/ancs21/repro-mantis
7
+ Paper code: https://github.com/vfeofanov/mantis · Weights: https://huggingface.co/paris-noah/Mantis-8M
8
+
9
+ - `param_count.py` — Claim 1: Mantis-8M has 8,103,936 params (8.10M), matching "8M lightweight". Verified.
10
+ - `zeroshot_probe.py` — Claim 2: frozen embeddings + logistic regression on 4 UCR datasets,
11
+ mean accuracy 0.938 (well above chance). Frozen zero-shot features are useful. Verified.
12
+
13
+ Install: `pip install mantis-tsfm aeon scikit-learn torch`. Inference-only, CPU, minutes.
param_count.py ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ """Claim 1: verify Mantis-8M parameter count (~8M lightweight). CPU, seconds."""
2
+ from mantis.architecture import Mantis8M
3
+ net = Mantis8M(device="cpu").from_pretrained("paris-noah/Mantis-8M")
4
+ n = sum(p.numel() for p in net.parameters())
5
+ print(f"total params: {n:,} ({n/1e6:.2f}M)") # 8,103,936 -> 8.10M
zeroshot_probe.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Mantis (#12379) claim check: frozen zero-shot features are useful.
2
+
3
+ Loads small UCR datasets, extracts FROZEN Mantis-8M embeddings (no fine-tuning),
4
+ fits a linear classifier (logistic regression) on top, reports test accuracy.
5
+ If the frozen features are useful, accuracy should be well above chance and
6
+ competitive with standard TS classifiers.
7
+ """
8
+ import warnings; warnings.filterwarnings("ignore")
9
+ import numpy as np, torch
10
+ from mantis.architecture import Mantis8M
11
+ from mantis.trainer import MantisTrainer
12
+ from aeon.datasets import load_classification
13
+ from sklearn.linear_model import LogisticRegression
14
+ from sklearn.preprocessing import StandardScaler
15
+
16
+ MANTIS_LEN = 512
17
+ net = Mantis8M(device="cpu").from_pretrained("paris-noah/Mantis-8M")
18
+ clf_wrap = MantisTrainer(device="cpu", network=net)
19
+
20
+ def resample_to(x, L=MANTIS_LEN):
21
+ # x: [n, 1, T] -> [n, 1, L] via linear interpolation
22
+ t = torch.tensor(np.asarray(x), dtype=torch.float32)
23
+ if t.ndim == 3 and t.shape[1] != 1: # take first channel if multivariate
24
+ t = t[:, :1, :]
25
+ t = torch.nn.functional.interpolate(t, size=L, mode="linear", align_corners=False)
26
+ return t.numpy()
27
+
28
+ datasets = ["ECG200", "GunPoint", "Coffee", "ItalyPowerDemand"]
29
+ print(f"{'dataset':18} {'n_tr':>5} {'n_te':>5} {'len':>5} {'chance':>7} {'frozen-acc':>11}")
30
+ accs = []
31
+ for name in datasets:
32
+ try:
33
+ Xtr, ytr = load_classification(name, split="train")
34
+ Xte, yte = load_classification(name, split="test")
35
+ except Exception as e:
36
+ print(f"{name:18} load failed: {e}"); continue
37
+ T0 = Xtr.shape[-1]
38
+ Etr = clf_wrap.transform(resample_to(Xtr))
39
+ Ete = clf_wrap.transform(resample_to(Xte))
40
+ sc = StandardScaler().fit(Etr)
41
+ lr = LogisticRegression(max_iter=2000).fit(sc.transform(Etr), ytr)
42
+ acc = lr.score(sc.transform(Ete), yte)
43
+ # majority-class baseline
44
+ vals, cnts = np.unique(ytr, return_counts=True)
45
+ chance = max(cnts) / len(ytr)
46
+ accs.append(acc)
47
+ print(f"{name:18} {len(ytr):>5} {len(yte):>5} {T0:>5} {chance:>7.3f} {acc:>11.3f}")
48
+
49
+ if accs:
50
+ print(f"\nmean frozen-feature accuracy over {len(accs)} datasets: {np.mean(accs):.3f}")
51
+ print("Claim: frozen zero-shot Mantis features are useful (well above chance) -> "
52
+ + ("SUPPORTED" if np.mean(accs) > 0.8 else "WEAK"))