Instructions to use Herb-Lab/LLM_housing_livability with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Herb-Lab/LLM_housing_livability with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("zero-shot-classification", model="Herb-Lab/LLM_housing_livability")# Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("Herb-Lab/LLM_housing_livability") model = AutoModelForSequenceClassification.from_pretrained("Herb-Lab/LLM_housing_livability", device_map="auto") - Notebooks
- Google Colab
- Kaggle
metadata
license: mit
language:
- en
base_model:
- facebook/bart-large-mnli
pipeline_tag: zero-shot-classification
🚀 Other links:
- 📝 Checkout our GitHub repository
- 🤗 Test the model with sentiment analysis on the Huggingface Space
Additional information about this model:
- The bart-large-mnli model page
- BART: Denoising Sequence-to-Sequence Pre-training for Natural Language Generation, Translation, and Comprehension
The following instructions for model deployment is a slightly modified version from the The bart-large-mnli model page.
With the zero-shot classification pipeline
The model can be loaded with the zero-shot-classification pipeline like so:
from transformers.pipelines import pipeline
classifier = pipeline("zero-shot-classification",
model="Herb-Lab/LLM_housing_livability")
You can then use this pipeline to classify sequences into any of the class names you specify.
sequence_to_classify = "The air conditioning was a bit noisy, and had to be turned off to sleep."
candidate_labels = ['Indoor Air Quality', 'Thermal', 'Acoustic', 'Visual']
classifier(sequence_to_classify, candidate_labels)
If more than one candidate label can be correct, pass multi_label=True to calculate each class independently:
candidate_labels = ['Indoor Air Quality', 'Thermal', 'Acoustic', 'Visual']
classifier(sequence_to_classify, candidate_labels, multi_label=True)
With manual PyTorch
# pose sequence as a NLI premise and label as a hypothesis
from transformers import AutoModelForSequenceClassification, AutoTokenizer
nli_model = AutoModelForSequenceClassification.from_pretrained('Herb-Lab/LLM_housing_livability')
tokenizer = AutoTokenizer.from_pretrained('Herb-Lab/LLM_housing_livability')
premise = sequence
hypothesis = f'This example is {label}.'
# run through model pre-trained on MNLI
x = tokenizer.encode(premise, hypothesis, return_tensors='pt',
truncation_strategy='only_first')
logits = nli_model(x.to(device))[0]
# we throw away "neutral" (dim 1) and take the probability of
# "entailment" (2) as the probability of the label being true
entail_contradiction_logits = logits[:,[0,2]]
probs = entail_contradiction_logits.softmax(dim=1)
prob_label_is_true = probs[:,1]