
#  Classifying text sentiment

```
Exercise ID 1578135
```

##  Assignment 

As well as answering questions, transforming text, and generating new text, Completions models can also be used for classification tasks, such as categorization and sentiment classification. This sort of task requires not only knowledge of the words but also a deeper understanding of their meaning.

In this exercise, you'll explore using Completions models for sentiment classification using reviews from an online shoe store called **Toe-Tally Comfortable**:

1. Unbelievably good!
1. Shoes fell apart on the second use.
1. The shoes look nice, but they aren't very comfortable.
1. Can't wait to show them off!

The `openai` package has been pre-loaded for you.

##  Pre exercise code 

```
import openai
```



##  Instructions 

- Assign your API key to `openai.api_key`.
<li>Create a request to the `Completion` endpoint to classify the sentiment of the following statements as either `negative`, `positive`, or `neutral`:<ul>
- Unbelievably good!
- Shoes fell apart on the second use.
- The shoes look nice, but they aren't very comfortable.
- Can't wait to show them off!


```
# Set your API key
openai.api_key = "____"

# Create a request to the Completion endpoint
response = openai.____.____(
  model="gpt-3.5-turbo-instruct",
  prompt=____,
  max_tokens=100
)

print(response['choices'][0]['text'])
```

##  Hints 

- The prompt will need to provide an instruction to classify the sentiment and the statements to analyze.
- Use triple backticks ```````` to define a multi-line prompt.



##  Solution 

```
# Set your API key
openai.api_key = "<OPENAI_API_TOKEN>"

# Create a request to the Completion endpoint
response = openai.Completion.create(
  model="gpt-3.5-turbo-instruct",
  prompt="""Classify sentiment as negative, positive, or neutral:
    1. Unbelievably good!
    2. Shoes fell apart on the second use.
    3. The shoes look nice, but they aren't very comfortable.
    4. Can't wait to show them off!
  """,
  max_tokens=100
)

print(response['choices'][0]['text'])
```


