Published in

NLP project

Let’s get started with NLP APIs like GPT-3 & GPT-Neo.

Photo by Thought Catalog on Unsplash


Getting started with GPT-3 is as easy as signing up to an email waiting list by clicking here. The Beta-program access is approved after few weeks. Then, you will be able to create an account for the OpenAI API with 3 months to spend the free $18.00 credit. There is a getting started tutorial.

There are important facts to know prior using GPT-3. Microsoft’s has an exclusive license of GPT-3. It is not open source. The pricing policy is based on consumption and the engine used.

The OpenAI API includes engines called Ada, Babbage, Curie and Davinci. The engine-documentation allows to pick the right engine. For example Davinci-engine offers highest language capability. Curie-engine is faster and with 1/10th of price.

The OpenAI API’s Playground lets to test GPT-3’s capabilities under various NLP tasks. We made few Q&A-pairs here to showcase the Davinci-engine. GPT-3 is able to provide facts.

Q: Which year Elvis Presley died? 
Elvis Presley died in 1977

Yet, as seen below, it is capable of making very simple errors.

Q:What day is today? 
Today is Monday, January 1, 2018.

This flaw can be programmatically fixed. “State-of-the-Art”-models have still deep limitations. We need to understand this point, if we use them in production environments.

GPT-3 is available programmatically with the below code from Jupyter notebook. Libraries must be installed first. Second step is to connect to the API using secret key. Final step is to print the output.

!{sys.executable} -m pip install openaiimport os
import sys
import openai
openai.api_key = "Insert here your Open AI API secret key"
response = openai.Completion.create(engine="davinci", prompt="I expect", max_tokens=5)

The “engine” parameter lets us choose the engine. The “max_tokens” defines the number of words to be generated. The “prompt”-parameter is the beginning of the sentence input. The secret key is available in the Open AI API. The output is JSON response. We can select from the JSON the desired data to be printed.

GPT-3 is capable of making various types of queries. The one used here is “Completion” by stating “openai.Completion”. This will provide one or many predicted completions. The other query types are: “Searches”, “Classifications” and “Answers”. For example “Answers” would provide response to a question.


GPT-Neo is open-source alternative to GPT-3. Three lines of code are required to get started:

#Install Transformers library:import sys
!{sys.executable} -m pip install git+
# Import the pipeline:
from transformers import pipeline
#Generate text, which starts with "My day..."
generator("My day", do_sample=True, min_length=100)
[{'generated_text': 'My day off, as we live in the city, was nice. I went in the city for dinner with my family. My dad and uncle got me a new kitchen appliance-- a food processor! What I love about the city is-- I can'}]

The above implementation relies on the Transformer-open source library by HuggingFace. Second method is to use the HuggingFace API with either its free or paid pricing plan. The third option is to use Colab & Google Cloud-bucket implementation.

GPT-Neo is useful open source alternative for GPT-3. Yet, the GPT-Neo model size still smaller compared to the largest engines of the GPT-3. Everybody will need to carefully review costs prior selecting between these two models. The usage of GPT-Neo via HuggingFace API has a monthly charge in commercial use. There are costs associated with using bucket in Google Cloud too. The third option is to pay based on actual usage via OpenAI API.

🔵 Become a Writer




Data Scientists must think like an artist when finding a solution when creating a piece of code. ⚪️ Artists enjoy working on interesting problems, even if there is no obvious answer ⚪️ 🔵 Follow to join our 18K+ Unique DAILY Readers 🟠

Recommended from Medium

Breaking the barrier: fluid simulations parallel-in-time.

Image to Image Translation

One and a half month into the Machine Learning.

Ensemble Learning with Support Vector Machines and Decision Trees

Shot by Takahiro Sakamoto

Scaling up with Distributed Tensorflow on Spark

Digital Nirvana Announces Trance 3.2 for Closed Captioning and Transcription

Introduction to Reinforcement Learning(RL)

Top Security Threats In Using Machine Learning Models

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Teemu Maatta

Teemu Maatta

Machine Learning Engineer. Top writer in Natural Language Processing (NLP). Multimodal learning. Artificial General Intelligence (AGI). DALL·E 2. GPT-3.

More from Medium

NLP and GPT — 3: A bite-sized lesson

A photo describing different ways nlp can be used

Using NLP For Business Success

Long-Form QA beyond ELI5: an updated dataset and approach

Review — Linguistic Regularities in Continuous Space Word Representations