Download parser/labels.py from Ericu950/Stoicheia-code: direct link, hf CLI and curl.
- Browser
- Download file 798 Bytes
-
https://huggingface.co/Ericu950/Stoicheia-code/resolve/main/parser/labels.py
- Command line
-
hf download hf://Ericu950/Stoicheia-code/parser/labels.py
-
curl -L -o labels.py https://huggingface.co/Ericu950/Stoicheia-code/resolve/main/parser/labels.py
798 Bytes
| """Dependency-relation label vocabulary (built from train split only).""" | |
| from __future__ import annotations | |
| import json | |
| from pathlib import Path | |
| class DeprelVocab: | |
| def __init__(self, rels): | |
| self.rels = rels | |
| self.idx = {r: i for i, r in enumerate(rels)} | |
| def build(cls, sents): | |
| rels = sorted({t.deprel for s in sents for t in s.tokens if t.deprel and t.deprel != "_"}) | |
| return cls(rels) | |
| def id(self, r): | |
| return self.idx.get(r, 0) | |
| def label(self, i): | |
| return self.rels[i] if 0 <= i < len(self.rels) else self.rels[0] | |
| def save(self, path): | |
| Path(path).write_text(json.dumps(self.rels, ensure_ascii=False)) | |
| def load(cls, path): | |
| return cls(json.loads(Path(path).read_text())) | |