Instructions to use cross-encoder/nli-distilroberta-base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use cross-encoder/nli-distilroberta-base with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("cross-encoder/nli-distilroberta-base") sentences = [ "The weather is lovely today.", "It's so sunny outside!", "He drove to the stadium." ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [3, 3] - Transformers
How to use cross-encoder/nli-distilroberta-base with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("zero-shot-classification", model="cross-encoder/nli-distilroberta-base")# Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("cross-encoder/nli-distilroberta-base") model = AutoModelForSequenceClassification.from_pretrained("cross-encoder/nli-distilroberta-base") - Notebooks
- Google Colab
- Kaggle
Not able to use nli-distilroberta-base for zero-shot-classification - getting OS error
from transformers import pipeline
classifier = pipeline("zero-shot-classification", model='cross-encoder/nli-distilroberta-base')
sent = "Apple just announced the newest iPhone X"
candidate_labels = ["technology", "sports", "politics"]
res = classifier(sent, candidate_labels)
print(res)
---------------------------------------Output-----------------------------------
OSError Traceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/transformers/configuration_utils.py in get_config_dict(cls, pretrained_model_name_or_path, **kwargs)
355 if resolved_config_file is None:
--> 356 raise EnvironmentError
357 config_dict = cls._dict_from_json_file(resolved_config_file)
OSError:
During handling of the above exception, another exception occurred:
OSError Traceback (most recent call last)
4 frames
/usr/local/lib/python3.7/dist-packages/transformers/configuration_utils.py in get_config_dict(cls, pretrained_model_name_or_path, **kwargs)
363 f"- or '{pretrained_model_name_or_path}' is the correct path to a directory containing a {CONFIG_NAME} file\n\n"
364 )
--> 365 raise EnvironmentError(msg)
366
367 except json.JSONDecodeError:
OSError: Can't load config for 'cross-encoder/nli-distilroberta-base'. Make sure that:
'cross-encoder/nli-distilroberta-base' is a correct model identifier listed on 'https://huggingface.co/models'
or 'cross-encoder/nli-distilroberta-base' is the correct path to a directory containing a config.json file
Getting OSError, Can anyone please check & help me to resolve