This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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("-----") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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("-----") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/', | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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() |
NewerOlder