Text Classification
jev-style
Safetensors
minicpm
minicpm5
system-one
decision-model
probability
calibration
agent
routing
Instructions to use link921/CPM-jev with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- jev-style
How to use link921/CPM-jev with jev-style:
pip install "jev-style[torch]"
from jev_style import JevStyle, noul, choice js = JevStyle.from_pretrained("link921/CPM-jev") out = js.decide("I was charged twice for one order.", { "billing": noul("This message is about billing."), "team": choice("Which team should handle it?", ["billing", "shipping", "tech"]), }) print(out["answers"]["team"]["choice"]) - Notebooks
- Google Colab
- Kaggle
Download test_release.py from link921/CPM-jev: direct link, hf CLI and curl.
- Browser
- Download file 2.46 kB
-
https://huggingface.co/link921/CPM-jev/resolve/main/test_release.py
- Command line
-
hf download hf://link921/CPM-jev/test_release.py
-
curl -L -o test_release.py https://huggingface.co/link921/CPM-jev/resolve/main/test_release.py
2.46 kB
| import json | |
| from pathlib import Path | |
| import pytest | |
| import torch | |
| from safetensors import safe_open | |
| from inference import DecisionModel, format_candidate | |
| ROOT = Path(__file__).resolve().parent | |
| def test_required_release_files_exist(): | |
| required = { | |
| "README.md", "adapter_model.safetensors", "adapter_config.json", | |
| "decision_head.safetensors", "tokenizer.json", "tokenizer_config.json", | |
| "model.py", "inference.py", "requirements.txt", "example.py", | |
| "calibration.json", "evaluation_report.json", | |
| } | |
| assert not required.difference(path.name for path in ROOT.iterdir()) | |
| def test_release_configs_are_portable(): | |
| adapter = json.loads((ROOT / "adapter_config.json").read_text(encoding="utf-8")) | |
| calibration = json.loads((ROOT / "calibration.json").read_text(encoding="utf-8")) | |
| assert adapter["base_model_name_or_path"] == "openbmb/MiniCPM5-2B-Base" | |
| assert calibration["use_temperature"] is False | |
| assert calibration["default_prediction"] == "raw" | |
| def test_safetensors_are_readable_and_finite(): | |
| for name in ("adapter_model.safetensors", "decision_head.safetensors"): | |
| with safe_open(ROOT / name, framework="pt", device="cpu") as handle: | |
| keys = list(handle.keys()) | |
| assert keys | |
| for key in keys: | |
| assert torch.isfinite(handle.get_tensor(key)).all(), key | |
| def test_probability_sum_with_stubbed_runtime(monkeypatch): | |
| model = DecisionModel.__new__(DecisionModel) | |
| model.device = torch.device("cpu") | |
| model.max_length = 512 | |
| class Encoded(dict): | |
| def to(self, _device): | |
| return self | |
| class Tokenizer: | |
| def __call__(self, texts, **_kwargs): | |
| n = len(texts) | |
| return Encoded(input_ids=torch.ones((n, 2), dtype=torch.long), attention_mask=torch.ones((n, 2), dtype=torch.long)) | |
| class Scorer: | |
| def __call__(self, input_ids, attention_mask): | |
| del attention_mask | |
| return torch.arange(input_ids.shape[0], dtype=torch.float32) | |
| model.tokenizer = Tokenizer() | |
| model.model = Scorer() | |
| result = model.decide(state="s", question="q", options=["a", "b", "c"]) | |
| assert sum(result["probabilities"]) == pytest.approx(1.0, abs=1e-7) | |
| assert result["choice"] == "c" | |
| def test_prompt_format_is_stable(): | |
| text = format_candidate("state", "choice", "question", "option") | |
| assert text.endswith("How well does this candidate answer the question?") | |