AI-generated image created using Bing Image Creator on 10-28-2024.
- Members
- Project Overview
- Project Directory
- Getting Started
- Project Structure
- Steps to Run the Project
- Analysis and Model Details
- Future Considerations
- References/Acknowledgments
- Carolina Mancina
- Madelyn Smith
- Taylor Peterson
We aim to create a website that generates playlists of recommended songs based on the user's current mood, genres, and/or favorite artists. Our goal is to outperform platforms like Spotify or YouTube Music by curating better recommendations, especially for discovering new songs.
Spotify typically recommends songs based only on what users have listened to or liked, rarely introducing new music. Mood.fm hopes to improve this by utilizing moods and user input to create more personalized recommendations.
- Playlist Recommendations: Curated by mood.
- Rating System: Allows users to rate songs on a 5-star scale.
- Mood Tracking: Users can provide feedback on their mood after listening to songs, genres, or albums to further refine recommendations.
- Initially, we incorporated Spotify's Web API to fetch real-time music data. Unfortunately, due to recent changes in Spotify's API accessibility (announcement, The Verge), we shifted to using the Kaggle dataset instead.
- Check out our Progress folder for a detailed look at the semester-long effort we dedicated to building and refining our model with the Spotify API before transitioning to the Kaggle dataset.
.vscode: Some needed materials for Visual StudioAllMoodPlaylist: This folder should be in the "Progress" folderm but is too large to be officially placed there.NewData/notebooks: Our final working program. Clone and run this one!Progress: Contains all of the files we have worked on in the semester.README.md: You are here!
- Python Environment: Ensure Python 3.8 or higher is installed
- Required Libraries:
numpypandasscikit-learnseaborntorchtorchvisiontqdm
The project directory includes the following:
NewData/notebooks/: Main project folder containing all resources and scripts:
data_preprocessing.ipynb: Notebook for cleaning and preprocessing the datasetfeatures_dataset.csv: Dataset with extracted features for training the model.metadata_dataset.csv; Metadata associated with the datasetmood_prediction_model.pth: Pre-trained neural network model for mood classification.NN.ipynb: Notebook for training the neural network.testing_model.ipynb: Notebook for testing and evaluating the model.resources/dataset.csv: Original raw dataset from Kaggle.
- Clone the repository to your local machine and open the project folder in VSCode.
-
Open
data_preprocessing.ipynb. -
Run all cells to:
- Clean the raw dataset (
resources/dataset.csv) and generate:cleaned_dataset.csv: Preprocessed dataset.features_dataset.csv: Extracted features for training.metadata_dataset.csv: Metadata for analysis
- Clean the raw dataset (
-
Confirm the generated files are in the
notebooksdirectory.
Note: This step is optional as these files already exist.
-
Open
NN.ipynb. -
Run all cells to:
- Load
features_dataset.csv. - Train the neural network for mood clasification.
- Save outputs:
mood_predicting_model.pth: Model weightslabel_encoder.pkl: Encoded mood labelsscaler.pkl: Scaler for feature normalization
- Load
This will overwrite mood_prediction_model.pth with a newly trained model.
-
Open
testing_model.ipynb. -
Run all cells to:
- Normalize features using scaler.pkl.
- Predict moods uing the saved model.
- Generate and print playlists based on predicted moods.
-
View:
- Performance Metrics: Classification report and confusion matrix
- Feature pairplot and distribution charts.
-
Locate the function
generate_user_playlist()underneath the section labeled "Playlist Generation" (at the bottom) -
Once running, user is prompted to input a number corresponding to a specific mood:
1: Happy2: Sad3: Calm4: Energetic
-
Choose one of the above, and a playlist of (10) songs will be generated.
- Valence: Measures positivity in a track (e.g., happy vs. sad).
- Energy: Reflects intensity and activity (e.g., calm vs. energetic).
- Tempo: Speed of a track.
- Danceability: How suitable a track is for dancing.
- Loudness: Overall sound intensity, measured in decibels.
- Speechiness: Presence of spoken words in a track.
- Acousticness: Likelihood of a track being acoustic.
- Instrumentalness: Indicates if a track has no vocals.
- Liveness: Detects if the track is a live recording.
- Key: Musical key of the track.
- Duration (ms): Length of the track in milliseconds.
- Popularity: Spotify score indicating how often a track is played.
Valence and Energy were the primary features for mood classification.
These features were chosen for their relevance to mood classification.
- Source: Spotify Tracks Dataset
- Size: Contains 114,000 Spotify tracks and their attributes.
- Feature Selection:
- Extracted key attributes required for mood classification (e.g., valence, energy, tempo).
- Mood Assignment:
- Moods were assigned based on thresholds for valence and energy:
- Happy: High valence (> 0.6) and medium-to-high energy (> 0.5)
- Sad: Low valence (< 0.4) and low energy (< 0.5)
- Calm: Medium valence (0.4–0.6) and low energy (< 0.5)
- Energetic: High valence (> 0.6) and high energy (> 0.7)
- Moods were assigned based on thresholds for valence and energy:
- Data Cleaning:
- Removed outliers and tracks with missing data.
- Normalization:
- Scaled numeric features using the StandardScaler (scaler.pkl) to ensure consistent input scales.
- Label Encoding:
- Encoded mood categories into numerical labels using
LabelEncoder(label_encoder.pkl).
- Encoded mood categories into numerical labels using
- Dataset Creation/Storage:
- Created two datasets:
features_dataset.csv: For training the neural network.metadata_dataset.csv: For additional analysis and metadata.
- Created two datasets:
- Input Layer: 12 features
- Hidden Layers:
- First Layer: 64 neurons, ReLU activation.
- Second Layer: 32 neurons, ReLU activation
- Output Layer: 4 neurons, representing the four mood categories: Happy, Sad, Calm, and Energetic.
- Loss Function: CrossEntropyLoss.
- Optimizer: Adam optimizer.
- Dataset Splits:
- Training Dataset: 64% of data.
- Validation Dataset: 16% of data for early stopping and monitoring.
- Testing Dataset: 20% for final evaluation.
- Forward Pass:
- Input: Feature vector from the dataset (e.g., valence, tempo).
- Output: Predicted probabilities for each mood category.
- Loss and Backpropagation:
- Loss Function: CrossEntropyLoss to calculate the error between predicted and actual moods.
- Optimizer: Adam optimizer to adjust weights.
- Training Epochs:
- 50 epochs
- Tracked both training and validation losses
- Evaluation Metrics:
- Achieved a test accuracy score of 99.37%.
- Generated accuracy and loss graphs to track performance.
Mood Prediction:
- Input Normalization:
- Scaled features in
metadata_dataset.csvusingscaler.pkl
- Scaled features in
- Prediction:
- The trained neural network (
mood_prediction_model.pth) classifies each track into one of the four mood categories. - Predicted mood labels are mapped back to their readable labels (happy, calm, sad, energetic) using
label_encoder.pkl.
- The trained neural network (
Evaluation and Visualizations:
- Performance Metrics:
- Classification Report: Precision, recall, and F1-score for each mood.
- Confusion Matrix: Displayed as a heatmap (
confusion_matrix.png).
- Visualization:
- Mood Distribution Chart: Shows the number of tracks predicted for each mood.
- Feature Pairplot: Highlights relationships between key features like valence, energy, and danceability, colored by mood.
Playlist Generation:
- Tracks are grouped by their predicted mood catgories.
- For each mood, playlists are displayed in the cell output. Details include:
- Track Name
- Artist
- Album
User Interaction:
- The user is prompted to select a mood from the available categories: 1: Happy 2: Sad 3: Calm 4: Energetic
- Based on the selected mood, a playlist of (up to) 10 tracks from that category is generated and displayed.
- Web/App Integration: The next logical step - to develop a web or mobile interface to make playlist generation user-friendly.
- Additional features: Incorporate more features we have access to within the dataset to further refine our mood predictions.
- Save Playlist: Modify the function to save the generated playlist as a .csv file for future use
- Playlist Length: Customize the number of songs in the playlist by modifying the random selection logic.
- Dynamic Mood Tracking: Incorporate real-time user feedback to refine playlists dynamically.
- Expand Dataset: Integrate additional datasets to include a broader range of tracks and genres.
- Collaborative Playlists: Allow users to share mood-based playlists with friends.
- Genre Customization: Add options for users to filter playlists by specific genres.
- Language Support: Expand mood classification to include songs in multiple languages.
Mood.fm combines machine learning and audio feature analysis to create mood-based playlists. Unlike traditional platforms, it focuses on audio attributes like valence and energy to classify moods. When Spotify restricted API access, we adapted by utilizing publicly available datasets while preserving the core structure of our original Spotify-based model. This transition allowed us to build on the existing framework and maintain our project vision.
Link to our GoogleDrive. Google Drive has been shared with the professor.
- OpenAI. Chatgpt: Assisted with documentation and code generation/formatting.
- Spotify Tracks Dataset: Kaggle Dataset
- Spotify Web API: Previously used before API access was limited
- Audio Features Endpoint: Spotify Web API reference for audio features.
- Spotify Accessibility Guidelines: Accessibility documentation for Spotify developers.
- Spotify Design Guidelines: Design guidelines for Spotify's developer tools.
- Spotify Developer Documentation: Main developer documentation.
- Spotify Research: Spotify's main research page.
- Spotify Engineering: Spotify's engineering blog.
- AI Playlist Expanding (Spotify Newsroom): Note: While we were working on Mood.fm, Spotify began rolling out their AI-generated playlist recommendations in September 2024, aiming for a similar goal.
- Automatic Music Playlist Generation via Simulation-Based Reinforcement Learning: Spotify Research, July 2023.
- Shifting Consumption Towards Diverse Content via Reinforcement Learning: Spotify Research, March 2021.
- How Spotify Uses ML to Create the Future of Personalization: Spotify Engineering, December 2021.
- Socially Motivated Music Recommendation: Spotify Research, June 2024.
- Socially Motivated Music Recommendation (Publication): Spotify Research.
- Global Music Streaming Data Reveals Robust Diurnal and Seasonal Patterns of Affective Preference: Spotify Research.
- Robust Diurnal and Seasonal Patterns of Affective Preference: Nature Publication.
- Shifting Affective Preferences and Patterns: ACM Digital Library.
- ICWSM Article on Music and Mood Analysis: AAAI Conference on Web and Social Media.
- Spotify Deep Learning (GitHub Repository): A GitHub repository for deep learning projects related to Spotify.
- GNN-in-RS (GitHub Repository): A GitHub repository for Graph Neural Networks in Recommendation Systems.
- Deam: MediaEval Database for Emotional Analysis 2017. Used in consideration of other datasets, later discarded.

