Instructions to use farzadab/test-dynamic-pipeline with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use farzadab/test-dynamic-pipeline with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="farzadab/test-dynamic-pipeline")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("farzadab/test-dynamic-pipeline") model = AutoModelForSequenceClassification.from_pretrained("farzadab/test-dynamic-pipeline", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Download pair_classification.py from farzadab/test-dynamic-pipeline: direct link, hf CLI and curl.
- Browser
- Download file 1.17 kB
-
https://huggingface.co/farzadab/test-dynamic-pipeline/resolve/main/pair_classification.py
- Command line
-
hf download hf://farzadab/test-dynamic-pipeline/pair_classification.py
-
curl -L -o pair_classification.py https://huggingface.co/farzadab/test-dynamic-pipeline/resolve/main/pair_classification.py
1.17 kB
| import numpy as np | |
| from transformers import Pipeline | |
| from ultravox.model import ultravox_model | |
| def softmax(outputs): | |
| maxes = np.max(outputs, axis=-1, keepdims=True) | |
| shifted_exp = np.exp(outputs - maxes) | |
| return shifted_exp / shifted_exp.sum(axis=-1, keepdims=True) | |
| class PairClassificationPipeline(Pipeline): | |
| def _sanitize_parameters(self, **kwargs): | |
| preprocess_kwargs = {} | |
| if "second_text" in kwargs: | |
| preprocess_kwargs["second_text"] = kwargs["second_text"] | |
| return preprocess_kwargs, {}, {} | |
| def preprocess(self, text, second_text=None): | |
| return self.tokenizer( | |
| text, text_pair=second_text, return_tensors=self.framework | |
| ) | |
| def _forward(self, model_inputs): | |
| return self.model(**model_inputs) | |
| def postprocess(self, model_outputs): | |
| logits = model_outputs.logits[0].numpy() | |
| probabilities = softmax(logits) | |
| best_class = np.argmax(probabilities) | |
| label = self.model.config.id2label[best_class] | |
| score = probabilities[best_class].item() | |
| logits = logits.tolist() | |
| return {"label": label, "score": score, "logits": logits} | |