Using HuggingFace, OpenAI, and Cohere models with Langchain

An in-depth tutorial on how to use popular models with Langchain. This can be used with private data too!

Mostafa Ibrahim
CodeContent

--

Photo by Eyasu Etsub on Unsplash

Langchain has been becoming one of the most popular NLP libraries, with around 30K starts on GitHub. I have recently tried it myself, and it is honestly amazing. If you are not familiar with Langchain, it is a library that helps developers build applications powered by large language models (LLMs). It does this by providing a framework for connecting LLMs to other sources of data, such as the internet or your personal files. This allows developers to chain together multiple commands to create more complex applications.

In this tutorial, we are going to be creating a question-answering model. This is pretty much what we are going to cover:

  1. Load hugging face transformer & embeddings
  2. Create a long chain index and fit it into our data
  3. Create a chain and ask it questions

Note that the current Langchain-HuggingFace ecosystem only supports text-generation and text2text-generation models according to the docs, so we will just go with that:

There exists two Hugging Face LLM wrappers, one for a local pipeline and one for a model…

--

--

Mostafa Ibrahim
CodeContent

Software Eng. University College London Computer Science Graduate. Passionate about Machine Learning in Healthcare. Top writer in AI