avatarVikash Singh

Summary

The website content provides a guide on getting started with large language models (LLMs) using OpenAI's API, comparing it with the Hugging Face API, and demonstrates how to build an LLM model with OpenAI's gpt-3.5-turbo-instruct model.

Abstract

The article "Getting started in LLMs with OpenAI" is a follow-up to a previous blog on using Hugging Face for LLMs. It introduces OpenAI's powerful language models, which are part of their proprietary technology and selected training data. The guide instructs readers on how to obtain an OpenAI API key and use the LangChain library to create an LLM model, specifically the gpt-3.5-turbo-instruct model. The article illustrates the simplicity of integrating OpenAI's models into applications using a unified syntax provided by LangChain, which allows for easy switching between different models. An example demonstrates the usage of the OpenAI API to generate text based on a given input, showcasing the model's ability to produce a detailed and coherent response. The article also compares the output from the OpenAI model with that of a Hugging Face model, noting that while both prioritize health, the OpenAI model provides a more elaborate answer. The author encourages readers to experiment with different models and share their findings, and concludes by providing a list of related blogs on topics such as statistics, data science, machine learning, and AI.

Opinions

  • The author suggests that OpenAI's models, due to their proprietary technology and carefully selected training data, are more powerful than alternatives in many cases.
  • The article highlights the ease of use of the LangChain library, emphasizing its unified syntax for integrating different LLMs.
  • The OpenAI model is presented as providing more detailed responses compared to the Hugging Face model in the provided example.
  • The author expresses enthusiasm for the field of AI and encourages community engagement by inviting readers to share their experiences with different models.
  • A list of related blogs suggests the author's view that the topics covered in the article are part of a broader ecosystem of interest to the reader, including AI, machine learning, and data science.

Getting started in LLMs with OpenAI

Also comparing results with Hugging Face API

In the previous blog, we discussed about how to get started in LLMs with Hugging Face.

Let’s revisit the framework in LangChain, but this time with arguably, the more popular OpenAI models.

These models are part of Open AI’s proprietary technology and carefully selected training data, which makes them more powerful in many cases.

Steps to access the Hugging Face API token

To follow-along, you’ll need an OpenAI API key. You can create your account on their signup page. The next step will be to navigate to the API keys page to create your secret key. Sometimes, OpenAI provides free credits, but that can differ depending on location.

Once you have the above logistics set-up, you’re ready to get started!

Build an LLM model using OpenAI API

To begin, we’ll import the necessary libraries.

!pip install langchain_openai
from langchain_openai import OpenAI

One great feature about Lang chain is its unified syntax, which makes it super easy to swap one model for another with only a small change in code. We’ll begin with defining the object that will store the OpenAI API key.

openai_api_key = "<Your OpenAI API Key>"

Next, we’ll define an LLM using the default OpenAI model available on LangChain, `gpt-3.5-turbo-instruct`

llm = OpenAI(model_name="gpt-3.5-turbo-instruct", openai_api_key=openai_api_key)

We have instantiated the llm object, and we’ll pass a text as an input, and then use the llm.invoke() function to predict the words based on the input provided. This is shown in the code below.

input = 'Health is wealth, but is it the order of priority for most of us?'
output = llm.invoke(input)
print(output)

The above code will generate the following output:

Unfortunately, it’s not the priority for many. We all are aware of keeping ourselves healthy, but we tend to ignore it. We ignore our health and fitness by saying that we are busy with our work. We work for hours together, neglecting our health which is the most crucial factor in our lives. Why do we need to take care of our health? Let’s discuss why health is wealth.

1. Physical health
Physical health is the most vital element of health. We all know the importance of physical health. Regular exercise and healthy food habits help us to stay fit. Our daily routine must include a minimum of 30 mins of physical exercise. It helps to keep diseases at bay. Good nutrition is an essential aspect of health. A balanced diet with all the necessary vitamins and minerals helps us to stay healthy. A healthy meal gives us the energy to work and keeps our immune system strong.

2. Mental health
Mental health is also an essential aspect of health. A healthy body leads to a healthy mind. Regular exercise helps to reduce stress, anxiety, depression, and other mental problems. People who are physically active are less likely to suffer from mental illnesses. A healthy mind helps us to think and make decisions better. It also helps us to maintain good relationships.

You can see the response from the llm. Note this can be different at your end, but you get the sense of what to expect from the language model.

Let’s compare this with the output we got from the Hugging Face model.

Health is wealth, but is it the order of priority for most of us?
We are all guilty of putting our health on the back burner. We all know that we should be eating healthier, exercising more, and getting enough sleep. But we all have our own priorities and we all have our own ways of prioritizing our lives.
I have been working on my health for the past 5 years. I have been working on my health for the past 5 years. I have been working on my

Both the models are giving the response that health is often not the priority for us. However, the OpenAI model gives a more elaborate answer.

It’s to be noted that in this blog, we have used the default models. There are several language models available in both Hugging Face and OpenAI API; and the results and performance will vary based on choice of the model.

Please feel free to share your thoughts. And if you have tried out other models, do share the findings.

If you’re interested in statistics, data science and machine learning, you’ll like these blogs:

  1. Getting started with LLMs in Hugging Face
  2. Credit Risk Modelling in Python
  3. Exploring Credit Risk and IRFS9 Models
  4. Analyzing Loan Data with Binomial and Poisson Distributions in Python
  5. Mastering Credit Risk Analysis: A Step-by-Step Guide to Descriptive Statistics in Python
  6. Introduction to Hypothesis Testing
  7. Fraud Analytics — Strategies and Approaches
  8. Understanding Financial Risk Models: A Guide to Credit Risk, Stress Testing, and More
  9. The What, Why, and How of Generative AI
  10. Interview-Ready: Top Generative AI Questions You Need to Know
  11. 10 Movies to Binge-Watch for Data Science and AI Nerds!
  12. Sentiment Analysis in Python
  13. Frequently Asked Hypothesis Testing Questions for Data Scientist Interviews
  14. Frequently Asked Hypothesis Testing Interview Questions for Aspiring Data Scientists (Part 2)
  15. How to Transition into Data Science from a Non-Technical Background

You can also connect with me on LinkedIn.

#ConversationalAI #Chatbots #OpenAI #Python #LearningJourney #LLM #FinetuningLLMs #PromptEngineering #HuggingFace #LangChain #HuggingFace

Large Language Models
OpenAI
Generative Ai Tools
Artificial Intelligence
ChatGPT
Recommended from ReadMedium