Instructions to use ardigen/ardisplay-i with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ardigen/ardisplay-i with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="ardigen/ardisplay-i", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForSequenceClassification model = AutoModelForSequenceClassification.from_pretrained("ardigen/ardisplay-i", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Download cli/ardisplay_cli.py from ardigen/ardisplay-i: direct link, hf CLI and curl.
- Browser
- Download file 2.46 kB
-
https://huggingface.co/ardigen/ardisplay-i/resolve/main/cli/ardisplay_cli.py
- Command line
-
hf download hf://ardigen/ardisplay-i/cli/ardisplay_cli.py
-
curl -L -o ardisplay_cli.py https://huggingface.co/ardigen/ardisplay-i/resolve/main/cli/ardisplay_cli.py
2.46 kB
| import re | |
| from typing import List | |
| import click | |
| import torch | |
| def prepare_results(input_data: List[str], predictions: List[dict]) -> List[List[str]]: | |
| return [ | |
| phla.split(",") + [str(pred["Presentation score"]), pred["Label"]] | |
| for phla, pred in zip(input_data, predictions) | |
| ] | |
| def ardisplay_cli(input_file, output_file, batch_size, device): | |
| from datasets import load_dataset | |
| from transformers import pipeline | |
| if not re.match("^cpu$|^cuda:\d+$", device): | |
| raise click.BadParameter( | |
| "Device should be 'cpu' or a CUDA device (e.g. 'cuda:0')" | |
| ) | |
| device = torch.device(device) | |
| pipe = pipeline( | |
| model="ardigen/ardisplay-i", | |
| trust_remote_code=True, | |
| batch_size=batch_size, | |
| device=device, | |
| ) | |
| dataset = load_dataset("text", data_files={"test": input_file}, split="test") | |
| predictions = pipe(dataset["text"]) | |
| results = prepare_results(input_data=dataset["text"], predictions=predictions) | |
| with open(output_file, "w") as f: | |
| f.write("HLA,Peptide,Presentation score,Label\n") | |
| for result in results: | |
| f.write(",".join(result) + "\n") | |
| click.echo(f"Presentation scores calculated, outputting to {output_file}") | |
| if __name__ == "__main__": | |
| ardisplay_cli() | |