Use Hugging Face Models
Use models hosted on Hugging Face in your pipelines.
You can use any model from Hugging Face in your pipelines. There are a couple of ways to do it:
- You can download a model from Hugging Face and then pass its location to the pipeline component that uses it.
- You can use one of Hugging Face's APIs:
Prerequisites
You need a Hugging Face token for the API you want to use.
Use Models from Hugging Face
Connect deepset Cloud to Hugging Face through the Connections page:
-
Click your initials in the top right corner and select Connections.
-
Click Connect next to the provider.
-
Enter your user access token and submit it.
Then, add a component that uses the model you have in mind. Here are the available components by the model type:
- Embedding models:
- HuggingFaceAPIDocumentEmbedder: Computes document embeddings using Hugging Face's APIs.
- HuggingFaceAPITextEmbedder: Computes text embeddings using Hugging Face's APIs.
- OptimumDocumentEmbedder: Calculates document embeddings using models from Hugging Face's Optimum library. You can use it through Hugging Face's APIs.
- OptimumTextEmbedder: Calculates text embeddings using models from Hugging Face's Optimum library. You can use it through Hugging Face's APIs.
- SentenceTransformersDocumentEmbedder: Embeds documents using Sentence Transformers models. You can use it through Hugging Face's APIs.
- SentenceTransformersTextEmbedder: Embeds text using Sentence Transformers models. You can use it through Hugging Face's APIs.
Embedding Models in Query and Indexing Pipelines
The embedding model you use to embed documents in your indexing pipeline must be the same as the embedding model you use to embed the query in your query pipeline.
- Named entity extraction:
- NamedEntityExtractor: Can work with Hugging Face models if you set its
backend
parameter tohugging_face
.
- NamedEntityExtractor: Can work with Hugging Face models if you set its
- LLMs:
- HuggingFaceAPIChatGenerator: Completes chats using Hugging Face APIs.
- HuggingFaceAPIGenerator: Uses text-generating models through Hugging Face APIs.
- HuggingFaceLocalChatGenerator: Uses a Hugging Face chat-completion model that runs locally.
- HuggingFaceLocalGenerator: Generates text using a Hugging Face model that runs locally.
- Ranking models:
- TransformersSimilarityRanker: Uses a cross-encoder model to rank documents. You can use models through Hugging Face APIs.
- SentenceTransformersDiversityRanker: Uses a sentence transformers model to rank documents. You can use models through Hugging Face APIs.
- Readers:
- ExtractiveReader: Extracts answers from the text.
- Routers:
- TransformersTextRouter: Routes text to various outputs based on a categorization label provided by the model it uses.
- TransformersZeroShotTextRouter: Uses a text classification model to route text to various outputs based on user-defined labels.
Usage Examples
Check the documentation of the component you want to use for usage examples.
Updated 3 months ago