DEV Community

Cover image for How to run any LLM model with Hugging-Face 🤗
Roshan Sanjeewa Wijesena
Roshan Sanjeewa Wijesena

Posted on

How to run any LLM model with Hugging-Face 🤗

Hugging-face 🤗 is a repository to host all the LLM models available in the world. https://huggingface.co/

If you go to the models sections of the repo, you would see thousands of models available to download or use as it is.

Let's get an example to use google/flan-t5-large to generate text2text prompts

  1. Install below python libs
!pip install huggingface_hub
!pip install transformers
!pip install accelerate
!pip install bitsandbytes
!pip install langchain
Enter fullscreen mode Exit fullscreen mode
  1. Get a huggingface API Key - https://huggingface.co/settings/tokens

  2. You can run below python code now with your Key

from langchain import PromptTemplate, HuggingFaceHub, LLMChain
import os
os.environ["HUGGINGFACEHUB_API_TOKEN"] = "<HUGGINGFACEKEY>"
prompt = PromptTemplate(
    input_variables=["product"],
    template="What is the good name for a company that makes {product}",
)

chain = LLMChain(prompt=prompt, llm=HuggingFaceHub(repo_id="google/flan-t5-large",model_kwargs={"temperature":0.1, "max_length":64}))

chain.run("fruits")

Results from Model = Fruits is a footballer from the United States.
Enter fullscreen mode Exit fullscreen mode

Top comments (0)