Skip to content

Instantly share code, notes, and snippets.

# Example usage
reviews = [
"The touchpad responsiveness is quick and accurate, making it easy to use.",
"I was amazed at how light the jacket was, yet it kept me warm in cold weather.",
"The headphone may lack the automation and battery life of the Sony, but it offers superior comfort, lighter weight, and exceptional sound quality for both music and calls."
]
for review in reviews:
extract_product_features(review)
print("-----")
# Example usage
feedback_examples = [
"I'm really disappointed with the late delivery of my order. It was supposed to arrive last week!",
"Your support team did a fantastic job helping me resolve an issue with my account.",
"I found the pricing to be quite competitive compared to other brands."
]
for feedback in feedback_examples:
categorize_feedback(feedback)
print("-----")
import openai
# Replace "your_api_key_here" with your actual OpenAI API key
openai.api_key = 'your_api_key_here'
def extract_product_features(review: str):
"""
Extracts product features from a customer review using few-shot learning via the OpenAI API.
Parameters:
- review (str): The customer review text from which to extract product features.
import openai
# Replace with your actual OpenAI API key
openai.api_key = 'your_api_key_here'
def categorize_feedback(feedback: str):
"""
Categorizes customer feedback into predefined themes using zero-shot learning.
Parameters:
- feedback (str): The customer feedback text to be categorized.
Method Prompt Engineer
Definition Crafting inputs to guide AI model behavior for specific outputs
Primary Use Case Quick guidance for AI models
Data Requirments None
# Loop through each source and generate word clouds
for source, headlines in trending_news.items():
# Combine the headlines into a single string
headlines_text = ' '.join(headlines)
# Generate the word cloud
wordcloud = WordCloud(width=800, height=400, background_color='white').generate(headlines_text)
# Display the word cloud with the source name as the title
plt.figure(figsize=(12, 6))
import requests
from bs4 import BeautifulSoup
# Define the URLs of the news websites
urls = {
'BBC': 'https://www.bbc.com/news',
'NBC': 'https://www.nbcnews.com/',
'FOX': 'https://www.foxnews.com/',
}
import requests
from bs4 import BeautifulSoup
from wordcloud import WordCloud
import matplotlib.pyplot as plt
# URL of the BBC News website
url = 'https://www.bbc.com/news'
# Send an HTTP GET request to the website
response = requests.get(url)
# Testing
if __name__ == "__main__":
# Create an instance of the RankingModel class
model = RankingModel()
# Define model_input as a dictionary (region is not used in this case)
model_input = {"region": ["Region_3"], 'user_id': [100]}
# Call the predict method of the model
result = model.predict(None, model_input)
# Create a temp table from DataFrame generated for example
listing_df.createOrReplaceTempView("listing_df")
# Call the function to rank listings by region
ranked_listings = rank_listings_by_region("Region_3", spark)
# Show the ranked listings
ranked_listings.show()