Use Azure OpenAI for sentiment feedback

Thomas Jeffery 40 Reputation points
2023-05-25T21:40:39.24+00:00

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.
2,161 questions
0 comments No comments
{count} votes

Accepted answer
  1. YutongTie-MSFT 46,566 Reputation points
    2023-05-26T00:52:12.6533333+00:00

    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(
            engine="text-davinci-002",
            prompt=f"Analyze the sentiment of the following Yelp review:\n\n{review_text}\n\nSentiment:",
            max_tokens=1,
            n=1,
            stop=None,
            temperature=0.0,
        )
        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.

    Regards,

    Yutong

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

    0 comments No comments

0 additional answers

Sort by: Most helpful