Use Azure OpenAI for sentiment feedback

Thomas Jeffery 0 Reputation points

How should I use Azure OpenAI to get sentiment feedback from my customer review in Yelp?

Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
317 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. YutongTie-MSFT 31,121 Reputation points

    Hello @Thomas Jeffery

    Thanks for reaching out to us, Azure OpenAI provides several APIs that can be used for sentiment analysis, depending on the type of data you are working with. Here's an example of how to use the OpenAI GPT-3 API to analyze sentiment in Yelp reviews:

    First, you'll need to obtain an API key for the OpenAI GPT-3 API.

    Once you have an API key, you can use the following Python code to analyze the sentiment of Yelp reviews:

    import openai
    openai.api_key = "YOUR_API_KEY"
    def analyze_sentiment(review_text):
        response = openai.Completion.create(
            prompt=f"Analyze the sentiment of the following Yelp review:\n\n{review_text}\n\nSentiment:",
        sentiment = response.choices[0].text.strip()
        return sentiment

    In this code, you provide a Yelp review as input to the OpenAI API and ask it to analyze the sentiment of the review. The API will return a sentiment score between -1 and 1, where negative scores indicate negative sentiment and positive scores indicate positive sentiment.

    You can call this function for each Yelp review that you want to analyze, like this:

    reviews = [

    "I had a great experience at this restaurant. The food was delicious and the service was excellent.",
    "The service at this restaurant was terrible. The waiter was rude and unhelpful.",
    "The food at this restaurant was mediocre at best. I wouldn't recommend it to anyone.",


    for review in reviews:

    sentiment = analyze_sentiment(review)
    print(f"Sentiment for review '{review}': {sentiment}")

    This code will print the sentiment score for each Yelp review in the reviews list. You can modify the code to read Yelp reviews from a file or database, depending on your needs.

    I hope this helps. Thanks.



    -Please kindly accept the answer if you feel helpful to support the community, thanks a lot.

    0 comments No comments