# Help with using transformers agents for sentiment extraction/ summarisation

**URL:** <https://discuss.huggingface.co/t/help-with-using-transformers-agents-for-sentiment-extraction-summarisation/39895>\
**Category:** Beginners\
**Created:** [May 15, 2023, 8:42am UTC](https://discuss.huggingface.co/t/help-with-using-transformers-agents-for-sentiment-extraction-summarisation/39895 "2023-05-15T08:42:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![SimonZh](https://avatars.discourse-cdn.com/v4/letter/s/ea5d25/32.png) [@SimonZh](https://discuss.huggingface.co/u/SimonZh)\
**Post date:** [May 15, 2023, 8:42am UTC](https://discuss.huggingface.co/t/help-with-using-transformers-agents-for-sentiment-extraction-summarisation/39895/1 "2023-05-15T08:42:53Z")

</div>

I am getting an error when using transformer agent.

```auto
from transformers import OpenAiAgent
from huggingface_hub import login
from transformers import HfAgent
login(" *****")
agent = OpenAiAgent(model="text-davinci-003", api_key=" ******")
# Starcoder
# agent = HfAgent("https://api-inference.huggingface.co/models/bigcode/starcoder")
# StarcoderBase
# agent = HfAgent("https://api-inference.huggingface.co/models/bigcode/starcoderbase")
# OpenAssistant
# agent = HfAgent(url_endpoint="https://api-inference.huggingface.co/models/OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5")

agent.run(f"What is the sentiment of the following comment: 'Him saying income is increasing relative to the rise in house prices, both rental and wholesale purchasing of a house? I guess these politicians are really losing their touch with the middle class. Never thought I’d have to consider living overseas once I start work, but here I am. Such a shame'")

```

Output:

```auto
==Explanation from the agent==
I will use the following tool: `text_classifier` to classify the sentiment of the comment.

==Code generated by the agent==
labels = ["positive", "neutral", "negative"]
sentiment = text_classifier(text=comment, labels=labels)
print(f"The sentiment of the comment is {sentiment}.")

==Result==
Evaluation of the code stopped at line 1 before the end because of the following error:
The variable `comment` is not defined.
['positive', 'neutral', 'negative']

```

Do I need to preprocess the input? Not sure how to resolve the error and any direction/guidance would be greatly appreciated!

My ultimate goal is to summarise and synthesise ideas from different comments using the transformer agent. I am aware of using OpenAI’s API but I want to explore potentially free options and transformer agents seemed promising. I’d be happy to explore other options if anyone has recommendations as well 😄
