Spaces:
Running on Zero
Running on Zero
Download experiments/common.py from ArchitSharma/FeatureLens: direct link, hf CLI and curl.
- Browser
- Download file 669 Bytes
-
https://huggingface.co/spaces/ArchitSharma/FeatureLens/resolve/main/experiments/common.py
- Command line
-
hf download hf://spaces/ArchitSharma/FeatureLens/experiments/common.py
-
curl -L -o common.py https://huggingface.co/spaces/ArchitSharma/FeatureLens/resolve/main/experiments/common.py
669 Bytes
| from __future__ import annotations | |
| import json | |
| import random | |
| from pathlib import Path | |
| import numpy as np | |
| import torch | |
| ROOT = Path(__file__).resolve().parents[1] | |
| DATA_DIR = ROOT / 'data' | |
| ARTIFACT_DIR = ROOT / 'artifacts' | |
| def load_jsonl(path: str | Path) -> list[dict]: | |
| rows = [] | |
| with Path(path).open(encoding='utf-8') as handle: | |
| for line in handle: | |
| line = line.strip() | |
| if line: | |
| rows.append(json.loads(line)) | |
| return rows | |
| def set_seed(seed: int) -> None: | |
| random.seed(seed) | |
| np.random.seed(seed) | |
| torch.manual_seed(seed) | |
| if torch.cuda.is_available(): | |
| torch.cuda.manual_seed_all(seed) | |