Instructions to use facebook/bart-large-mnli with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use facebook/bart-large-mnli with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")# Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("facebook/bart-large-mnli") model = AutoModelForSequenceClassification.from_pretrained("facebook/bart-large-mnli") - Inference
- Notebooks
- Google Colab
- Kaggle
Need help speeding up headline categorization
#36
by karpathy-beezy - opened
Hi all,
I’m working on a project that needs to categorize 300 headlines into 9-16 dynamic categories every hour. I'm using the BART model via Huggingface's API. My current implementation in Python takes 3-5 seconds per headline, which is too slow.
def categorise(categories, item):
API_URL = "https://api-inference.huggingface.co/models/facebook/bart-large-mnli"
headers = {"Authorization": "Bearer <token>"}
payload = {
"inputs": item,
"parameters": {"candidate_labels": categories},
}
response = requests.post(API_URL, headers=headers, json=payload)
if response.status_code == 200:
results = response.json()
return {"category": results[0]['labels'][0], "confidence": results[0]['scores'][0]}
else:
return {"error": f"API request failed with status {response.status_code}"}
I call this function in a for loop for each headline. Is there a way to make this faster?