Quickstart

Using AI21 Studio, you can solve challenging text understanding and generation tasks. Its straightforward API and interactive playground allows you to get started in minutes, without any prior knowledge in Natural Language Processing (NLP).

Below is a quickstart guide to cover all the basics you need in order to start building your solution. After that, you should feel comfortable using our large language models to start and solve your own use-case.

Some basics

A language model takes some text as input and produces a likely continuation. You can think of it as an exceptional student that can follow instructions and imitate examples.

Here are two words you should know:

  • Prompt - the input you provide to the model.

  • Completion - the output text the model returns.

Experiment with your first use-case

Imagine owning an online retail platform. Your job requires you to come up with appealing titles for your products. By using AI21 Studio language models, you can optimize the process.

1. Tell the model what you want to do

The most naive thing to do is simply provide the model a prompt which is a simple instruction. This is what it looks like:

The title is nice, but it is very generic. Let's add the T-shirt type (sports) to the prompt and see what we get:

The title has been refined to reflect the actual product. You can also apply a more realistic scenario: ask the model to incorporate specific keywords in the title.

This is called Zero-shot prompting, because we are giving the model zero examples in the prompt. If you care about a specific style you want the model to follow, you should consider adding examples to your prompt.

2. Provide examples to the model

By providing the model with examples, just as a human would, it could produce completions that are more aligned with your intentions. It could also adhere to patterns that are more difficult to explain via instructions. In order to help the model distinguish between each example, we use a stop sequence. The stop sequence itself should be immediately recognizable when looking at the text as a whole. In this example, the stop sequence is ##:

This is called Few-shot prompting, because we are inserting a prompt which includes a few examples.

3. Adjust the parameters

Another way to affect the completion is to adjust some of the model parameters. A useful parameter is the temperature. You can increase creativity by tweaking the temperature. With temperature 0, the model will always choose the most probable completion, so it will always be the same. Increasing the temperature will provide variable completions, where the completion may be different for every generation:

A task that requires accurate results (such as classification) is best performed with low temperature, whereas a task that requires more creativity should be conducted with high temperature (0.7 is a reasonable starting point).

Want to explore the various descriptions the model can generate? Try it yourself!

4. Make it a part of your product

Once you have created your prompt, you can easily integrate it into your product using either our Python SDK or HTTP request:

from ai21 import AI21Client

client = AI21Client(
    # This is the default and can be omitted
    api_key=os.environ.get("AI21_API_KEY"),
)

client.completion.create(
  model="j2-ultra",
  prompt="Write a product title for a sports T-shirt to be published on an online retail platform. Include the following keywords: activewear, gym, dryfit.",
  temperature=0.8,
  max_tokens=200,
)

Now you're ready to improve your product using generative AI.

What's next?

We encourage you to play with our models in the AI21 Studio and explore the out-of-the-box solutions our task-specific models can provide.

Want to know more about the prompt design process? Read about prompt engineering.

Want to know more about our APIs? See the full API reference.