Skip to main content
Open on GitHub

Hugging Face

All functionality related to Hugging Face Hub and libraries like transformers, sentence transformers, and datasets.

Hugging Face is an AI platform with all major open source models, datasets, MCPs, and demos. It supplies model inference locally and via serverless Inference Providers.

You can use Inference Providers to run open source models like DeepSeek R1 on scalable serverless infrastructure.

Installationโ€‹

Most of the Hugging Face integrations are available in the langchain-huggingface package.

pip install langchain-huggingface

Chat modelsโ€‹

ChatHuggingFaceโ€‹

We can use the Hugging Face LLM classes or directly use the ChatHuggingFace class.

See a usage example.

from langchain_huggingface import ChatHuggingFace
API Reference:ChatHuggingFace

LLMsโ€‹

HuggingFaceEndpointโ€‹

We can use the HuggingFaceEndpoint class to run open source models via serverless Inference Providers or via dedicated Inference Endpoints.

See a usage example.

from langchain_huggingface import HuggingFaceEndpoint
API Reference:HuggingFaceEndpoint

HuggingFacePipelineโ€‹

We can use the HuggingFacePipeline class to run open source models locally.

See a usage example.

from langchain_huggingface import HuggingFacePipeline
API Reference:HuggingFacePipeline

Embedding Modelsโ€‹

HuggingFaceEmbeddingsโ€‹

We can use the HuggingFaceEmbeddings class to run open source embedding models locally.

See a usage example.

from langchain_huggingface import HuggingFaceEmbeddings
API Reference:HuggingFaceEmbeddings

HuggingFaceEndpointEmbeddingsโ€‹

We can use the HuggingFaceEndpointEmbeddings class to run open source embedding models via a dedicated Inference Endpoint.

See a usage example.

from langchain_huggingface import HuggingFaceEndpointEmbeddings

HuggingFaceInferenceAPIEmbeddingsโ€‹

We can use the HuggingFaceInferenceAPIEmbeddings class to run open source embedding models via Inference Providers.

See a usage example.

from langchain_community.embeddings import HuggingFaceInferenceAPIEmbeddings

HuggingFaceInstructEmbeddingsโ€‹

We can use the HuggingFaceInstructEmbeddings class to run open source embedding models locally.

See a usage example.

from langchain_community.embeddings import HuggingFaceInstructEmbeddings

HuggingFaceBgeEmbeddingsโ€‹

BGE models on the HuggingFace are one of the best open-source embedding models. BGE model is created by the Beijing Academy of Artificial Intelligence (BAAI). BAAI is a private non-profit organization engaged in AI research and development.

See a usage example.

from langchain_community.embeddings import HuggingFaceBgeEmbeddings

Document Loadersโ€‹

Hugging Face datasetโ€‹

Hugging Face Hub is home to over 75,000 datasets in more than 100 languages that can be used for a broad range of tasks across NLP, Computer Vision, and Audio. They used for a diverse range of tasks such as translation, automatic speech recognition, and image classification.

We need to install datasets python package.

pip install datasets

See a usage example.

from langchain_community.document_loaders.hugging_face_dataset import HuggingFaceDatasetLoader

Hugging Face model loaderโ€‹

Load model information from Hugging Face Hub, including README content.

This loader interfaces with the Hugging Face Models API to fetch and load model metadata and README files. The API allows you to search and filter models based on specific criteria such as model tags, authors, and more.

from langchain_community.document_loaders import HuggingFaceModelLoader

Image captionsโ€‹

It uses the Hugging Face models to generate image captions.

We need to install several python packages.

pip install transformers pillow

See a usage example.

from langchain_community.document_loaders import ImageCaptionLoader
API Reference:ImageCaptionLoader

Toolsโ€‹

Hugging Face Hub Toolsโ€‹

Hugging Face Tools support text I/O and are loaded using the load_huggingface_tool function.

We need to install several python packages.

pip install transformers huggingface_hub

See a usage example.

from langchain_community.agent_toolkits.load_tools import load_huggingface_tool
API Reference:load_huggingface_tool

Hugging Face Text-to-Speech Model Inference.โ€‹

It is a wrapper around OpenAI Text-to-Speech API.

from langchain_community.tools.audio import HuggingFaceTextToSpeechModelInference