Text Classification
Transformers
Safetensors
English
manta
feature-extraction
medical
decision-model
classification
calibration
multimodal
vision
radiology
pathology
clinical-text
custom_code
Instructions to use gevaertlab/MANTA-4B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use gevaertlab/MANTA-4B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="gevaertlab/MANTA-4B", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("gevaertlab/MANTA-4B", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Download example.py from gevaertlab/MANTA-4B: direct link, hf CLI and curl.
- Browser
- Download file 1.76 kB
-
https://huggingface.co/gevaertlab/MANTA-4B/resolve/main/example.py
- Command line
-
hf download hf://gevaertlab/MANTA-4B/example.py
-
curl -L -o example.py https://huggingface.co/gevaertlab/MANTA-4B/resolve/main/example.py
1.76 kB
| """Answer the example requests with MANTA-4B (one GPU with about 16 GB). | |
| python example.py # examples/text_request.json and image_request.json | |
| python example.py --request my_request.json | |
| Prints, per question, the option probabilities (most probable first) and the answer. | |
| """ | |
| from __future__ import annotations | |
| import argparse | |
| import json | |
| import sys | |
| from pathlib import Path | |
| HERE = Path(__file__).resolve().parent | |
| sys.path.insert(0, str(HERE)) | |
| def main(argv=None) -> int: | |
| ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) | |
| ap.add_argument("--request", nargs="*", type=Path, | |
| default=[HERE / "examples" / "text_request.json", HERE / "examples" / "image_request.json"]) | |
| ap.add_argument("--release", default=str(HERE), help="the release folder or its Hub repository id") | |
| ap.add_argument("--device", default="cuda") | |
| ap.add_argument("--option-order", default="eval", choices=("eval", "given", "sorted")) | |
| args = ap.parse_args(argv) | |
| from manta import Manta | |
| model = Manta.from_pretrained(args.release, device=args.device) | |
| for path in args.request: | |
| request = json.loads(path.read_text()) | |
| result = model.predict(request, option_order=args.option_order) | |
| print(f"\n{path.name} ({result['prompt_tokens']} prompt tokens)") | |
| for qid, answer in result["questions"].items(): | |
| ranked = sorted(answer["probabilities"].items(), key=lambda kv: -kv[1]) | |
| shown = ", ".join(f"{option} {p:.3f}" for option, p in ranked) | |
| print(f" {qid} ({answer['type']}): answer {answer['answer']} | {shown}") | |
| return 0 | |
| if __name__ == "__main__": | |
| sys.exit(main()) | |