Analyzing Reviews using Phi-3 and Ollama

Amal
ScrapeHero
Published in
4 min readJul 3, 2024
A microsoft bot analyzing reviews

Review Analysis has become an essential task for businesses to understand customer’s way of thinking and improve their products or services. In fact, manually processing large volumes of reviews can be time-consuming and inefficient.

Here, we use the large language model Phi-3 and Ollama platform to automate the review analysis process and gain valuable insights.

Phi-3 from Microsoft is a state-of-the-art open source model with 3.8 billion parameters and is known for its lightweight design and impressive performance that matches large models like Mixtral 8x7B and GPT-3.5.

When combined with Ollama, a platform that enables users to run large language models locally, Phi3 becomes a powerful tool for analyzing reviews efficiently and ensuring data privacy.

To learn more about Ollama, check out Building a QA bot with Ollama .

Installation / Dependencies

Linux:

curl https://ollama.ai/install.sh | sh

Mac:

https://ollama.ai/download/Ollama-darwin.zip

Windows:

https://ollama.com/download/OllamaSetup.exe

Python Dependency:

pip install openai pandas

Open your Terminal,

Start Ollama server:

ollama serve

Ollama will be running on localhost:11434

Download the model:

ollama pull phi3

To run the model:

ollama run phi3

We will be using ScrapeHero’s Starbucks Location Data for analysis. Once you get the data, we can use any data analysis library like Pandas to load the data and later use it for further analysis.

Analysis on Starbucks Reviews

Now, using Python we call the Ollama server and then request the Phi3 model to return an analysis based on the question.

You can make use of requests library or urllib3 to call Ollama API, but for the ease of work and efficiency we use OpenAI library.

import openai

client = openai.OpenAI(
base_url=”http://localhost:11434/v1",
api_key=”nokeyneeded”,
)

Why localhost:11434? Because that’s the local server Ollama is up and running. Remember, we ran the server by ollama serve.

Okay, let’s do a simple task of summarizing Starbucks reviews from Orlando, USA .

import openai
import pandas as pd

starbucks_df = pd.read_csv(“Starbucks_reviews.csv”)
orlando_reviews = starbucks_df[starbucks_df.city == “Orlando”].review

client = openai.OpenAI(
base_url=”http://localhost:11434/v1",
api_key=”nokeyneeded”,
)

response = client.chat.completions.create(
model=”phi3",
temperature=0.5,
n=1,
messages=[
{“role”: “system”, “content”: “You are a AI assistant that summarizes review from a list of reviews”},
{“role”: “user”, “content”: list(orlando_reviews)},
],
)

print(response.choices[0].message.content)

Response:

Based on your reviews, it seems that while Starbucks locations vary, some common highlights include their efficient service, friendly staff (despite occasional challenges), clean and enjoyable atmosphere, especially at certain locations like the one near Orlando’s Magic Kingdom or Surfside Lobbies. However, you also noted instances of slow service, errors in orders, and concerns with pricing that deviate from expectations based on your previous interactions with Starbucks. It appears there are both positives to look forward to as well as areas for potential improvement to ensure consistency across all locations.

.

Seems good!! Let’s try to tweak the prompt to summarize some of the positive and negative comments mentioned in the review.

response = client.chat.completions.create(
model=”phi3",
temperature=0.5,
n=1,
messages=[
{“role”: “system”, “content”: “You are a AI assistant that summarizes positive and negative comments from a list of reviews”},
{“role”: “user”, “content”: list(orlando_reviews)},
],
)

Response:

Based on your reviews, it seems that experiences at this particular Starbucks location have had their ups and downs. Here’s a summary:

Positive Aspects:

- Friendly staff who were jovial, engaging, helpful, and efficient in handling customer orders.

- Great coffee quality with consistent taste from one location to another.

- Efficient service with short waiting times. Lines move quickly and customers don’t appear to be left behind or overlooked. The employee even remade a drink for you when it wasn’t up to expectations, showing attentiveness towards customer satisfaction.

- Nice ambiance with cleanliness throughout the store. You can find leather seating and free wifi available. There is also convenient accessibility, being located just a few minutes away from other attractions.

Negative Aspects:

- Occasional issues with order accuracy leading to complaints or dissatisfaction.

- Some customers had a negative experience due to rude and unhelpful staff.

- A couple of incidents where the place felt understaffed, affecting service speed. There were instances when there weren’t enough employees to handle peak times effectively. This seems like an area that could benefit from improvement in terms of managing shifts and staff allocation.

- Unpleasant interactions between customers due to perceived rudeness or inconsideration, impacting the overall dining experience for some visitors.

Improvements: To enhance customer experiences at this Starbucks location, consider implementing training programs focused on improving staff communication and attitude towards customers. This can help in handling situations better when mistakes happen with orders. Additionally, managing shifts efficiently to avoid understaffing during peak times may contribute positively to the service quality.

Overall Assessment: While this Starbucks location has its fair share of positive experiences regarding coffee quality and cleanliness, there are areas for improvement in staff performance, customer interactions, and service speed during busy periods. By addressing these concerns, you can further elevate the dining experience at your store.

Conclusion:

We saw a glimpse of the lightweight and powerful Phi-3 model that will be able to generate valuable insights, by making use of Ollama we ensure data privacy since we are running this LLM completely on local.

As these cutting-edge technologies evolve, we can utilize state-of-the-art models to run securely, ensuring businesses to stay ahead of the competition, maintaining brand reputation and building more meaningful relationships with their customers.

--

--