{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%load_ext autoreload\n", "%autoreload 2" ] }, { "cell_type": "code", "execution_count": 99, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import librosa\n", "import torch\n", "from src import laion_clap\n", "from glob import glob\n", "import pandas as pd\n", "import jmespath" ] }, { "cell_type": "code", "execution_count": 54, "metadata": {}, "outputs": [], "source": [ "# quantization\n", "def int16_to_float32(x):\n", " return (x / 32767.0).astype(np.float32)\n", "\n", "\n", "def float32_to_int16(x):\n", " x = np.clip(x, a_min=-1., a_max=1.)\n", " return (x * 32767.).astype(np.int16)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "model = laion_clap.CLAP_Module(enable_fusion=False, amodel= 'HTSAT-base')\n", "model.load_ckpt(ckpt=\"/Users/berkayg/Codes/music-project/laion-clap-project/curate-me-a-playlist/model_checkpoints/music_audioset_epoch_15_esc_90.14.pt\")" ] }, { "cell_type": "code", "execution_count": 55, "metadata": {}, "outputs": [], "source": [ "def load_music_file(file_name):\n", " audio_data, _ = librosa.load(file_name, sr=48000) # sample rate should be 48000\n", " audio_data = audio_data.reshape(1, -1) # Make it (1,T) or (N,T)\n", " # audio_data = torch.from_numpy(int16_to_float32(float32_to_int16(audio_data))).float() # quantize before send it in to the model\n", " with torch.no_grad():\n", " audio_embed = model.get_audio_embedding_from_data(x = audio_data, use_tensor=False)\n", " return audio_embed\n" ] }, { "cell_type": "code", "execution_count": 54, "metadata": {}, "outputs": [], "source": [ "with open(\"/Users/berkayg/Codes/music-project/laion-clap-project/curate-me-a-playlist/data/json/final_track_data.json\", \"r\") as reader:\n", " track_data = json.load(reader)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "music_files = glob(\"/Users/berkayg/Codes/music-project/AudioCLIP/data/downloaded_tracks/*.wav\")" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "import pickle\n", "with open(\"/Users/berkayg/Codes/music-project/laion-clap-project/curate-me-a-playlist/data/vectors/song_names.pkl\", \"rb\") as reader:\n", " ls = pickle.load(reader)\n" ] }, { "cell_type": "code", "execution_count": 69, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/var/folders/sr/r72219hj06x_1xvw7hhd517h0000gn/T/ipykernel_39391/3009710654.py:2: UserWarning: PySoundFile failed. Trying audioread instead.\n", " audio_data, _ = librosa.load(file_name, sr=48000) # sample rate should be 48000\n", "/Users/berkayg/miniforge3/envs/playlist-curator/lib/python3.10/site-packages/librosa/core/audio.py:183: FutureWarning: librosa.core.audio.__audioread_load\n", "\tDeprecated as of librosa version 0.10.0.\n", "\tIt will be removed in librosa version 1.0.\n", " y, sr_native = __audioread_load(path, offset, duration, dtype)\n" ] } ], "source": [ "music_data = np.zeros((len(track_data), 512), dtype=np.float32)\n", "track_data_new = []\n", "idx = 0\n", "for m in track_data:\n", " if m[\"file_path\"]:\n", " music_data[idx] = load_music_file(m[\"file_path\"])\n", " dc = m.copy()\n", " dc.update({\"vector_idx\": idx})\n", " track_data_new.append(dc)\n", " idx += 1\n" ] }, { "cell_type": "code", "execution_count": 105, "metadata": {}, "outputs": [], "source": [ "vector_db_data = track_data_new.copy()\n", "vector_db_data.sort(key=lambda x: x[\"vector_idx\"])\n", "vector_ids = [f\"audio_{k['vector_idx']}\" for k in vector_db_data]\n", "vector_indices = [k[\"vector_idx\"] for k in vector_db_data]\n", "vector_db_data = jmespath.search(\"[*].{artist_name: artist_name, track_name: track_name, title: title, link: link, vector_idx: vector_idx}\", vector_db_data)" ] }, { "cell_type": "code", "execution_count": 110, "metadata": {}, "outputs": [], "source": [ "from chromadb import Documents, EmbeddingFunction, Embeddings\n", "\n", "class CuratorTextEmbedding(EmbeddingFunction):\n", " def __call__(self, text: Documents) -> Embeddings:\n", " # embed the documents somehow\n", " return embeddings" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "import chromadb\n", "chroma_client = chromadb.Client()" ] }, { "cell_type": "code", "execution_count": 166, "metadata": {}, "outputs": [], "source": [ "chroma_client.delete_collection(name=\"playlist_collection\")\n", "collection = chroma_client.create_collection(name=\"playlist_collection\", metadata={\"hnsw:space\": \"ip\"})" ] }, { "cell_type": "code", "execution_count": 167, "metadata": {}, "outputs": [], "source": [ "collection.add(\n", " embeddings=music_data[vector_indices].tolist(),\n", " metadatas=vector_db_data,\n", " ids=vector_ids\n", " )" ] }, { "cell_type": "code", "execution_count": 172, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[0;31mSignature:\u001b[0m\n", "\u001b[0mcollection\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mquery\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mquery_embeddings\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mUnion\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mSequence\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mfloat\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mSequence\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mint\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mList\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mUnion\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mSequence\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mfloat\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mSequence\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mint\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mNoneType\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mquery_texts\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mUnion\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mList\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mstr\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mNoneType\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mquery_images\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mUnion\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mnumpy\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mndarray\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mAny\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnumpy\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdtype\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mUnion\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mnumpy\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0muint64\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnumpy\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mint64\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnumpy\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfloat64\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mList\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mnumpy\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mndarray\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mAny\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnumpy\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdtype\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mUnion\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mnumpy\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0muint64\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnumpy\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mint64\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnumpy\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfloat64\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mNoneType\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mquery_uris\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mUnion\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mList\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mstr\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mNoneType\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mn_results\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mint\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m10\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mwhere\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mOptional\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mDict\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mUnion\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mLiteral\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'$and'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mLiteral\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'$or'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mUnion\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mint\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfloat\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mbool\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mDict\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mUnion\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mLiteral\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'$gt'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mLiteral\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'$gte'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mLiteral\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'$lt'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mLiteral\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'$lte'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mLiteral\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'$ne'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mLiteral\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'$eq'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mLiteral\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'$and'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mLiteral\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'$or'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mUnion\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mint\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfloat\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mbool\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mDict\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mUnion\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mLiteral\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'$in'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mLiteral\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'$nin'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mList\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mUnion\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mint\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfloat\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mbool\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mList\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mForwardRef\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'Where'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mwhere_document\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mOptional\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mDict\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mUnion\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mLiteral\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'$contains'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mLiteral\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'$and'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mLiteral\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'$or'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mUnion\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mList\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mForwardRef\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'WhereDocument'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0minclude\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mList\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mUnion\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mLiteral\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'documents'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mLiteral\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'embeddings'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mLiteral\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'metadatas'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mLiteral\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'distances'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mLiteral\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'uris'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mLiteral\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'data'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m'metadatas'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'documents'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'distances'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m->\u001b[0m \u001b[0mchromadb\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mapi\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtypes\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mQueryResult\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31mDocstring:\u001b[0m\n", "Get the n_results nearest neighbor embeddings for provided query_embeddings or query_texts.\n", "\n", "Args:\n", " query_embeddings: The embeddings to get the closes neighbors of. Optional.\n", " query_texts: The document texts to get the closes neighbors of. Optional.\n", " query_images: The images to get the closes neighbors of. Optional.\n", " n_results: The number of neighbors to return for each query_embedding or query_texts. Optional.\n", " where: A Where type dict used to filter results by. E.g. `{\"$and\": [\"color\" : \"red\", \"price\": {\"$gte\": 4.20}]}`. Optional.\n", " where_document: A WhereDocument type dict used to filter by the documents. E.g. `{$contains: {\"text\": \"hello\"}}`. Optional.\n", " include: A list of what to include in the results. Can contain `\"embeddings\"`, `\"metadatas\"`, `\"documents\"`, `\"distances\"`. Ids are always included. Defaults to `[\"metadatas\", \"documents\", \"distances\"]`. Optional.\n", "\n", "Returns:\n", " QueryResult: A QueryResult object containing the results.\n", "\n", "Raises:\n", " ValueError: If you don't provide either query_embeddings, query_texts, or query_images\n", " ValueError: If you provide both query_embeddings and query_texts\n", " ValueError: If you provide both query_embeddings and query_images\n", " ValueError: If you provide both query_texts and query_images\n", "\u001b[0;31mFile:\u001b[0m ~/miniforge3/envs/playlist-curator/lib/python3.10/site-packages/chromadb/api/models/Collection.py\n", "\u001b[0;31mType:\u001b[0m method" ] } ], "source": [ "collection.query?" ] }, { "cell_type": "code", "execution_count": 173, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'ids': [['audio_292',\n", " 'audio_481',\n", " 'audio_298',\n", " 'audio_474',\n", " 'audio_121',\n", " 'audio_476',\n", " 'audio_337',\n", " 'audio_472',\n", " 'audio_225',\n", " 'audio_482']],\n", " 'distances': [[0.6302633285522461,\n", " 0.6571106910705566,\n", " 0.6896730661392212,\n", " 0.7028166055679321,\n", " 0.7428299784660339,\n", " 0.7440136671066284,\n", " 0.7793576717376709,\n", " 0.7837952971458435,\n", " 0.8032999038696289,\n", " 0.8056029081344604]],\n", " 'metadatas': [[{'artist_name': 'Coldplay',\n", " 'link': 'https://www.youtube.com/watch?v=kcASPx3-HuI',\n", " 'title': 'Coldplay - Trouble (Official video)',\n", " 'track_name': 'Trouble',\n", " 'vector_idx': 292},\n", " {'artist_name': 'Coldplay',\n", " 'link': 'https://www.youtube.com/watch?v=k4V3Mo61fJM',\n", " 'title': 'Coldplay - Fix You (Official Video)',\n", " 'track_name': 'Fix You',\n", " 'vector_idx': 481},\n", " {'artist_name': 'Coldplay',\n", " 'link': 'https://www.youtube.com/watch?v=57rEQZiklxQ',\n", " 'title': 'See You Soon',\n", " 'track_name': 'See You Soon',\n", " 'vector_idx': 298},\n", " {'artist_name': 'Coldplay',\n", " 'link': 'https://www.youtube.com/watch?v=xtQirM784oM',\n", " 'title': 'Warning Sign',\n", " 'track_name': 'Warning Sign',\n", " 'vector_idx': 474},\n", " {'artist_name': 'Coldplay',\n", " 'link': 'https://www.youtube.com/watch?v=BPNTC7uZYrI',\n", " 'title': 'Coldplay - Up&Up (Official Video)',\n", " 'track_name': 'Up&Up',\n", " 'vector_idx': 121},\n", " {'artist_name': 'Coldplay',\n", " 'link': 'https://www.youtube.com/watch?v=gnIZ7RMuLpU',\n", " 'title': 'Coldplay - In My Place (Official 4K Video)',\n", " 'track_name': 'In My Place',\n", " 'vector_idx': 476},\n", " {'artist_name': 'Coldplay',\n", " 'link': 'https://www.youtube.com/watch?v=z1rYmzQ8C9Q',\n", " 'title': 'Coldplay - Christmas Lights (Official Video)',\n", " 'track_name': 'Christmas Lights',\n", " 'vector_idx': 337},\n", " {'artist_name': 'Coldplay',\n", " 'link': 'https://www.youtube.com/watch?v=Lh3TokLzzmw',\n", " 'title': 'Coldplay - Atlas (Hunger Games: Catching Fire)(Official Lyric Video)',\n", " 'track_name': 'Atlas - From “The Hunger Games: Catching Fire”/Soundtrack',\n", " 'vector_idx': 472},\n", " {'artist_name': 'Coldplay',\n", " 'link': 'https://www.youtube.com/watch?v=1Uw6ZkbsAH8',\n", " 'title': 'Coldplay - Princess Of China ft. Rihanna (Official Video)',\n", " 'track_name': 'Princess of China',\n", " 'vector_idx': 225},\n", " {'artist_name': 'Coldplay',\n", " 'link': 'https://www.youtube.com/watch?v=EhC_c7p50so',\n", " 'title': 'White Shadows',\n", " 'track_name': 'White Shadows',\n", " 'vector_idx': 482}]],\n", " 'embeddings': None,\n", " 'documents': [[None, None, None, None, None, None, None, None, None, None]],\n", " 'uris': None,\n", " 'data': None}" ] }, "execution_count": 173, "metadata": {}, "output_type": "execute_result" } ], "source": [ "text_data = [\"romantic, depressing\"] \n", "text_embed = model.get_text_embedding(text_data)\n", "collection.query(query_embeddings=text_embed.tolist(), n_results=10, where={\"artist_name\": \"Coldplay\"})" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 111, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(1, 512)\n" ] } ], "source": [ "text_data = [\"This audio is an energetic, uplifting song\"] \n", "text_embed = model.get_text_embedding(text_data)\n", "print(text_embed.shape)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "song_names = [k.split(\"/\")[-1] for k in music_files]" ] }, { "cell_type": "code", "execution_count": 52, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "torch.Size([630, 1])\n" ] } ], "source": [ "ranking = torch.tensor(audio_vectors) @ torch.tensor(text_embed).t()\n", "ranking = ranking[:, 0].reshape(-1, 1)\n", "print(ranking.shape)" ] }, { "cell_type": "code", "execution_count": 53, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
This audio is an energetic, uplifting song
Ciara - Can't Leave 'Em Alone (feat. 50 Cent).wav0.423258
The Weeknd - Blinding Lights.wav0.415049
Stromae - Tous les mêmes.wav0.412208
Empire of the Sun - Alive.wav0.373571
Kylie Minogue - Chocolate.wav0.348002
Sia - Elastic Heart.wav0.334062
Sia - Chandelier.wav0.330263
Stevie Wonder - Signed, Sealed, Delivered (I'm Yours).wav0.324698
Coldplay - Princess of China.wav0.319533
Florence + The Machine - Spectrum (Say My Name) - Calvin Harris Remix.wav0.315443
Coldplay - True Love.wav0.308231
Coldplay - Talk.wav0.307894
Lily Allen - Not Fair.wav0.300576
Andru Donalds - Mishale.wav0.296594
Linkin Park - Numb.wav0.294131
\n", "
" ], "text/plain": [ " This audio is an energetic, uplifting song\n", "Ciara - Can't Leave 'Em Alone (feat. 50 Cent).wav 0.423258\n", "The Weeknd - Blinding Lights.wav 0.415049\n", "Stromae - Tous les mêmes.wav 0.412208\n", "Empire of the Sun - Alive.wav 0.373571\n", "Kylie Minogue - Chocolate.wav 0.348002\n", "Sia - Elastic Heart.wav 0.334062\n", "Sia - Chandelier.wav 0.330263\n", "Stevie Wonder - Signed, Sealed, Delivered (I'm ... 0.324698\n", "Coldplay - Princess of China.wav 0.319533\n", "Florence + The Machine - Spectrum (Say My Name)... 0.315443\n", "Coldplay - True Love.wav 0.308231\n", "Coldplay - Talk.wav 0.307894\n", "Lily Allen - Not Fair.wav 0.300576\n", "Andru Donalds - Mishale.wav 0.296594\n", "Linkin Park - Numb.wav 0.294131" ] }, "execution_count": 53, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pd.DataFrame(ranking, columns=[text_data[0]], index=song_names).nlargest(15, text_data[0])" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "import json\n", "import pickle\n", "def load_data():\n", " vectors = np.load(\"/Users/berkayg/Codes/music-project/laion-clap-project/curate-me-a-playlist/data/vectors/audio_representations.npy\")\n", " with open(\"/Users/berkayg/Codes/music-project/laion-clap-project/curate-me-a-playlist/data/vectors/song_names.pkl\", \"rb\") as reader:\n", " song_names = pickle.load(reader)\n", "\n", " with open(\"/Users/berkayg/Codes/music-project/laion-clap-project/curate-me-a-playlist/data/json/youtube_data.json\", \"r\") as reader:\n", " youtube_data = json.load(reader)\n", "\n", " df_youtube = pd.DataFrame(youtube_data)\n", " df_youtube[\"id\"] = df_youtube[\"artist_name\"] + \" - \" + df_youtube[\"track_name\"] + \".wav\"\n", " df_youtube.set_index(\"id\", inplace=True)\n", " return vectors, song_names, df_youtube\n", "audio_vectors, song_names, df_youtube = load_data()" ] }, { "cell_type": "code", "execution_count": 44, "metadata": {}, "outputs": [], "source": [ "from sklearn.manifold import TSNE\n", "decomposer = TSNE(3)\n", "audio_components = decomposer.fit_transform(np.vstack([audio_vectors, text_embed]))" ] }, { "cell_type": "code", "execution_count": 76, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "torch.Size([630, 1])" ] }, "execution_count": 76, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import plotly.express as px\n", "(torch.tensor(text_embed) / torch.linalg.norm(torch.tensor(text_embed), dim=-1, keepdim=True))\n", "torch.linalg.norm(torch.tensor(audio_vectors), dim=-1, keepdim=True).shape" ] }, { "cell_type": "code", "execution_count": 48, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[-0.0228844 , -0.01531727, -0.02099325, ..., 0.02487872,\n", " -0.04954423, -0.00967047],\n", " [ 0.05719518, -0.05181887, 0.02295402, ..., 0.04154928,\n", " -0.01846843, 0.0015544 ],\n", " [-0.01932843, -0.03254181, -0.02956614, ..., 0.04285421,\n", " -0.00225228, -0.00785008],\n", " ...,\n", " [-0.05801252, 0.05521129, -0.06229992, ..., -0.02577653,\n", " 0.01485025, -0.04933776],\n", " [-0.01117569, 0.03371193, 0.03643309, ..., 0.03710453,\n", " 0.06688339, 0.04197252],\n", " [ 0.02041594, -0.00629344, -0.10389867, ..., -0.02280687,\n", " -0.02982889, 0.03500484]], dtype=float32)" ] }, "execution_count": 48, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.vstack([audio_vectors, text_embed])" ] }, { "cell_type": "code", "execution_count": 45, "metadata": {}, "outputs": [], "source": [ "songs = song_names.copy()\n", "songs.append(\"text_embedding\")" ] }, { "cell_type": "code", "execution_count": 46, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
012song_namesis_text
6267.839409-2.56620925.651859Wilson Pickett - Hey Joe.wavFalse
62725.03012110.9932562.521003Bülent Ortaçgil - Değirmenler.wavFalse
628-11.4222836.371774-33.630165Sufle - Köprüaltı.wavFalse
629-21.5449037.802368-11.589836Keane - Somewhere Only We Know.wavFalse
630-32.042549-20.397856-20.176537text_embeddingTrue
\n", "
" ], "text/plain": [ " 0 1 2 song_names \\\n", "626 7.839409 -2.566209 25.651859 Wilson Pickett - Hey Joe.wav \n", "627 25.030121 10.993256 2.521003 Bülent Ortaçgil - Değirmenler.wav \n", "628 -11.422283 6.371774 -33.630165 Sufle - Köprüaltı.wav \n", "629 -21.544903 7.802368 -11.589836 Keane - Somewhere Only We Know.wav \n", "630 -32.042549 -20.397856 -20.176537 text_embedding \n", "\n", " is_text \n", "626 False \n", "627 False \n", "628 False \n", "629 False \n", "630 True " ] }, "execution_count": 46, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df_vectors = pd.DataFrame(audio_components).assign(song_names=songs, is_text=lambda x: x[\"song_names\"] == \"text_embedding\")\n", "df_vectors.tail()" ] }, { "cell_type": "code", "execution_count": 47, "metadata": {}, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "config": { "plotlyServerURL": "https://plot.ly" }, "data": [ { "customdata": [ [ "Teoman - Hayalperest.wav" ], [ "Jason Mraz - I'm Yours.wav" ], [ "AC_DC - Back In Black.wav" ], [ "Pirates Of New Providence - Dead Man's Chest.wav" ], [ "B.B. King - Ghetto Woman.wav" ], [ "Elle King - Playing For Keeps.wav" ], [ "Tame Impala - The Less I Know The Better.wav" ], [ "Procol Harum - A Whiter Shade Of Pale.wav" ], [ "Duman - Yanibasimdan.wav" ], [ "Coldplay - Adventure of a Lifetime.wav" ], [ "Müslüm Gürses - Affet.wav" ], [ "Stereo Avenue - Mad World.wav" ], [ "Coldplay - Sparks.wav" ], [ "Santana - Day of Celebration.wav" ], [ "Queen - I Want To Break Free - Remastered 2011.wav" ], [ "Guns N' Roses - This I Love.wav" ], [ "123 - binalar.wav" ], [ "Serena Ryder - Stompa.wav" ], [ "Passion Pit - Take a Walk.wav" ], [ "Marvin Gaye - Got To Give It Up - Pt. 1.wav" ], [ "Erik Truffaz - Let Me Go ! (feat. Sophie Hunger).wav" ], [ "Blonde Redhead - For the Damaged Coda.wav" ], [ "Israel Kamakawiwo'ole - Somewhere Over The Rainbow_What A Wonderful World.wav" ], [ "Daft Punk - Lose Yourself to Dance (feat. Pharrell Williams).wav" ], [ "Zülfü Livaneli - Gözlerin.wav" ], [ "Adamlar - İnsanın Düştüğü Durumlar.wav" ], [ "Foghat - Louisiana Blues.wav" ], [ "Amy Winehouse - Mr Magic (Through The Smoke).wav" ], [ "Pinhani - Dünyadan Uzak.wav" ], [ "Queen - Don't Stop Me Now - 2011 Remaster.wav" ], [ "Gevende - Sanki.wav" ], [ "Mirkelam - Hatıralar.wav" ], [ "Hüseyin Bitmez - Nazende Sevgilim.wav" ], [ "Sertab Erener - Kumsalda.wav" ], [ "Eric Clapton - Ramblin' on My Mind.wav" ], [ "Aretha Franklin - At Last.wav" ], [ "Bob Marley & The Wailers - No Woman, No Cry - Live At The Lyceum, London_1975.wav" ], [ "Maroon 5 - Harder To Breathe.wav" ], [ "James Brown - It's A Man's, Man's, Man's World - Mono.wav" ], [ "Buddy Guy - Mustang Sally (feat. Jeff Beck).wav" ], [ "Cem Karaca - Resimdeki Gözyaslari (Apaslar).wav" ], [ "Adamlar - Yanmış İçinden.wav" ], [ "Adamlar - Ah Benim Hayatım.wav" ], [ "Adamlar - Tın Tın.wav" ], [ "Ali Kızıltuğ - Sen Gel Diyorsun - Öf Öf.wav" ], [ "Wes Montgomery - In Your Own Sweet Way.wav" ], [ "Duman - Elleri Ellerime.wav" ], [ "Bob Marley & The Wailers - Three Little Birds.wav" ], [ "Bee Gees - Stayin' Alive - Remastered Version.wav" ], [ "Grover Washington, Jr. - Just the Two of Us.wav" ], [ "Queen - Save Me - 2011 Remaster.wav" ], [ "Adele - Hometown Glory.wav" ], [ "Dido - White Flag.wav" ], [ "Adamlar - Utanmazsan Unutmam.wav" ], [ "Dire Straits - Sultans Of Swing.wav" ], [ "Bülent Ortaçgil - Bozburun.wav" ], [ "Sting - Shape Of My Heart.wav" ], [ "Barcelona Gipsy Klezmer Orchestra - Hasta Siempre, Comandante.wav" ], [ "Jimi Hendrix - Purple Haze.wav" ], [ "Craig David - Rise & Fall - feat. Sting.wav" ], [ "Los Naranjos - Cantarte a Ti.wav" ], [ "Cem Karaca - Beni Siz Delirttiniz.wav" ], [ "Bob Dylan - You Belong To Me.wav" ], [ "Milky Chance - Stolen Dance.wav" ], [ "Nirvana - The Man Who Sold The World.wav" ], [ "Pink Floyd - Wish You Were Here - 2011 Remastered Version.wav" ], [ "Emilíana Torrini - Dead Duck.wav" ], [ "Johnnie Taylor - Running Out Of Lies.wav" ], [ "No Doubt - Don't Speak.wav" ], [ "Bob Marley & The Wailers - African Herbsman.wav" ], [ "MIKA - Grace Kelly.wav" ], [ "Coldplay - True Love.wav" ], [ "Enya - Only Time.wav" ], [ "Cem Karaca - Sevda Kuşun Kanadında.wav" ], [ "Replikas - Yaş Elli.wav" ], [ "John Mayer - New Light.wav" ], [ "Elvis Presley - All Shook Up.wav" ], [ "emir taha - Huyu Suyu.wav" ], [ "Foo Fighters - The Sky Is A Neighborhood.wav" ], [ "Lucio Quarantotto - Time To Say Goodbye (Con Te Partirò).wav" ], [ "123 - so much to say.wav" ], [ "fun. - We Are Young (feat. Janelle Monáe).wav" ], [ "Fallulah - I Lay My Head.wav" ], [ "TOTO - Hold the Line.wav" ], [ "Ray Charles - Mess Around.wav" ], [ "Queen - Innuendo - Remastered 2011.wav" ], [ "Aerosmith - Walk This Way.wav" ], [ "Foster The People - Pumped Up Kicks.wav" ], [ "Santana - Primavera.wav" ], [ "David Dallas - Runnin'.wav" ], [ "Eric Clapton - Worried Life Blues - Live; 2015 Remaster.wav" ], [ "Coldplay - Warning Sign.wav" ], [ "Joe Cocker - Unchain My Heart.wav" ], [ "Nur Yoldas - Sultan-ı Yegah.wav" ], [ "Nil Karaibrahimgil - Kanatlarım Var Ruhumda.wav" ], [ "Wilson Pickett - Hey Joe.wav" ], [ "Bülent Ortaçgil - Değirmenler.wav" ], [ "Sufle - Köprüaltı.wav" ], [ "Keane - Somewhere Only We Know.wav" ] ], "hovertemplate": "is_text=False
0=%{x}
1=%{y}
2=%{z}
song_names=%{customdata[0]}", "legendgroup": "False", "marker": { "color": "#636efa", "opacity": 0.8, "symbol": "circle" }, "mode": "markers", "name": "False", "scene": "scene", "showlegend": true, "type": "scatter3d", "x": [ 3.960073471069336, 6.63026237487793, 6.366035461425781, 35.9576301574707, 25.72879409790039, -23.749359130859375, -18.918292999267578, 20.815343856811523, 3.548778533935547, -9.880792617797852, -1.626604676246643, -25.692523956298828, -9.009389877319336, 21.91187858581543, -8.398816108703613, -13.183920860290527, -16.33573341369629, -20.739084243774414, -16.058250427246094, -5.901383876800537, -29.334606170654297, -21.556638717651367, -32.477176666259766, -10.107562065124512, 2.0257608890533447, 3.539175510406494, 9.495028495788574, -8.56347370147705, 2.9173169136047363, 12.427820205688477, 22.154857635498047, -9.044797897338867, 24.114742279052734, -25.635881423950195, 19.347545623779297, -19.076709747314453, 17.552734375, -12.944130897521973, 29.22037696838379, 5.216680526733398, 4.647155284881592, -5.739335536956787, 1.2586489915847778, 9.793363571166992, 22.0106143951416, 28.065549850463867, 13.323224067687988, 6.095829010009766, -8.249640464782715, 5.1530609130859375, -22.9552001953125, -25.220529556274414, -17.555011749267578, 26.815658569335938, 6.869404315948486, 34.0200080871582, -10.640585899353027, -29.66428565979004, 16.96628761291504, -12.059541702270508, 18.312807083129883, 18.12636947631836, -0.4769120514392853, 11.270349502563477, 15.4771089553833, -9.384946823120117, 10.876140594482422, -3.506535053253174, -33.04511260986328, 21.82001304626465, -20.24302101135254, -21.872957229614258, -26.808494567871094, -4.571284770965576, 4.80881929397583, 16.436382293701172, 27.422374725341797, -26.98200035095215, -19.272430419921875, -20.390697479248047, -32.17781066894531, -30.004587173461914, -23.986347198486328, -3.3886325359344482, 31.404930114746094, -6.3269734382629395, 12.990680694580078, 3.9187815189361572, 4.270918369293213, -28.737621307373047, 26.91798210144043, -4.584568023681641, 25.394004821777344, -27.019210815429688, -24.920318603515625, 7.839408874511719, 25.030120849609375, -11.422283172607422, -21.544902801513672 ], "y": [ -6.303861141204834, 15.232268333435059, -18.639732360839844, 16.955612182617188, -4.059649467468262, 5.14973258972168, -2.5839288234710693, 0.775934636592865, -6.10317325592041, 0.692775309085846, -1.615648627281189, 4.755437850952148, -0.393994003534317, -19.156991958618164, 22.87925910949707, 11.058145523071289, 3.0950820446014404, 5.530603885650635, -3.080402374267578, 13.579002380371094, -4.78978157043457, 7.763420104980469, -7.65438985824585, 23.316055297851562, 24.696044921875, 3.7123682498931885, -21.037315368652344, 13.44579029083252, -2.354578733444214, -26.491195678710938, -18.70002555847168, 13.3438720703125, -2.367952823638916, 24.548198699951172, -17.782995223999023, 14.160982131958008, 22.661109924316406, -15.065990447998047, 14.719420433044434, -16.994403839111328, -2.528127431869507, -9.89771556854248, -6.246743202209473, 25.03219985961914, -1.4081578254699707, -2.3774948120117188, -27.25217056274414, 23.652070999145508, 16.401748657226562, 20.747957229614258, 14.122920036315918, 15.15066909790039, 19.500532150268555, 3.8085296154022217, -0.638141393661499, -6.328094482421875, 2.543947696685791, 24.652851104736328, -14.238359451293945, 19.87712287902832, 15.849624633789062, 9.969474792480469, 11.297757148742676, -18.961462020874023, -23.89181137084961, 6.338683128356934, -6.532224178314209, 8.980716705322266, 10.482304573059082, 19.634340286254883, -19.921180725097656, -18.082565307617188, -3.7091286182403564, 21.601825714111328, -21.571517944335938, -11.576738357543945, 19.804643630981445, -2.666598081588745, -23.158870697021484, -8.012092590332031, 14.015975952148438, 8.013833999633789, 13.031487464904785, 18.049388885498047, 7.4357523918151855, 15.054443359375, -21.247608184814453, 3.2007644176483154, 25.249967575073242, -8.995502471923828, -2.2580485343933105, -9.61690616607666, 22.74266242980957, 27.359724044799805, 16.42228126525879, -2.566208839416504, 10.993255615234375, 6.371773719787598, 7.8023681640625 ], "z": [ -4.585926055908203, 7.6198248863220215, 11.197002410888672, 10.61091423034668, -0.16559484601020813, 15.873065948486328, 6.092303276062012, 13.278153419494629, -13.814813613891602, -32.1518669128418, -2.846285104751587, -24.60615348815918, -14.583600044250488, -5.089763641357422, 17.827316284179688, -8.723794937133789, -0.46522191166877747, 22.079736709594727, -27.905847549438477, 26.410999298095703, -24.432289123535156, -29.81077766418457, -24.935848236083984, 14.596731185913086, -11.877199172973633, -23.376184463500977, 2.7458457946777344, 19.448259353637695, -7.996399879455566, 9.06856918334961, 1.2749879360198975, -12.594420433044434, -22.486719131469727, 2.873701572418213, -24.027612686157227, 2.2689332962036133, 21.957611083984375, 13.603313446044922, 16.907148361206055, 21.468961715698242, 23.266664505004883, 1.334670066833496, -9.798734664916992, 5.956639766693115, -24.757957458496094, -16.810287475585938, -0.19127635657787323, 17.18698501586914, 23.69522476196289, 11.511524200439453, -16.232465744018555, -11.024603843688965, 0.2891804277896881, 4.686855792999268, 4.955519676208496, -11.170580863952637, -9.173028945922852, 9.23276424407959, 20.439125061035156, -21.887910842895508, -25.068744659423828, -2.6079728603363037, -19.979209899902344, -16.800277709960938, -7.8158345222473145, -20.36083984375, -13.97440242767334, 13.297832489013672, 6.4031662940979, 16.68050193786621, -7.421001434326172, -20.746915817260742, -17.661420822143555, -16.111785888671875, -6.790570259094238, -10.68458080291748, 4.448904991149902, 5.806682586669922, -18.60723114013672, -32.03889465332031, -3.2083699703216553, 8.138893127441406, 10.776344299316406, 15.558555603027344, 14.651917457580566, -17.637117385864258, 20.528764724731445, 16.84113883972168, 10.138716697692871, 6.520318984985352, 8.3370361328125, -3.437776565551758, -6.115707874298096, -4.344021797180176, -2.9191675186157227, 25.651859283447266, 2.521003484725952, -33.630165100097656, -11.589836120605469 ] }, { "customdata": [ [ "text_embedding" ] ], "hovertemplate": "is_text=True
0=%{x}
1=%{y}
2=%{z}
song_names=%{customdata[0]}", "legendgroup": "True", "marker": { "color": "#EF553B", "opacity": 0.8, "symbol": "circle" }, "mode": "markers", "name": "True", "scene": "scene", "showlegend": true, "type": "scatter3d", "x": [ -32.04254913330078 ], "y": [ -20.397855758666992 ], "z": [ -20.176536560058594 ] } ], "layout": { "legend": { "title": { "text": "is_text" }, "tracegroupgap": 0 }, "margin": { "t": 60 }, "scene": { "domain": { "x": [ 0, 1 ], "y": [ 0, 1 ] }, "xaxis": { "title": { "text": "0" } }, "yaxis": { "title": { "text": "1" } }, "zaxis": { "title": { "text": "2" } } }, "template": { "data": { "bar": [ { "error_x": { "color": "#2a3f5f" }, "error_y": { "color": "#2a3f5f" }, "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "bar" } ], "barpolar": [ { "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "barpolar" } ], "carpet": [ { "aaxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "baxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "type": "carpet" } ], "choropleth": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "choropleth" } ], "contour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "contour" } ], "contourcarpet": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "contourcarpet" } ], "heatmap": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "heatmap" } ], "heatmapgl": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "heatmapgl" } ], "histogram": [ { "marker": { "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "histogram" } ], "histogram2d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "histogram2d" } ], "histogram2dcontour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "histogram2dcontour" } ], "mesh3d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "mesh3d" } ], "parcoords": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "parcoords" } ], "pie": [ { "automargin": true, "type": "pie" } ], "scatter": [ { "fillpattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 }, "type": "scatter" } ], "scatter3d": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatter3d" } ], "scattercarpet": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattercarpet" } ], "scattergeo": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergeo" } ], "scattergl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergl" } ], "scattermapbox": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattermapbox" } ], "scatterpolar": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolar" } ], "scatterpolargl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolargl" } ], "scatterternary": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterternary" } ], "surface": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "surface" } ], "table": [ { "cells": { "fill": { "color": "#EBF0F8" }, "line": { "color": "white" } }, "header": { "fill": { "color": "#C8D4E3" }, "line": { "color": "white" } }, "type": "table" } ] }, "layout": { "annotationdefaults": { "arrowcolor": "#2a3f5f", "arrowhead": 0, "arrowwidth": 1 }, "autotypenumbers": "strict", "coloraxis": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "colorscale": { "diverging": [ [ 0, "#8e0152" ], [ 0.1, "#c51b7d" ], [ 0.2, "#de77ae" ], [ 0.3, "#f1b6da" ], [ 0.4, "#fde0ef" ], [ 0.5, "#f7f7f7" ], [ 0.6, "#e6f5d0" ], [ 0.7, "#b8e186" ], [ 0.8, "#7fbc41" ], [ 0.9, "#4d9221" ], [ 1, "#276419" ] ], "sequential": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "sequentialminus": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ] }, "colorway": [ "#636efa", "#EF553B", "#00cc96", "#ab63fa", "#FFA15A", "#19d3f3", "#FF6692", "#B6E880", "#FF97FF", "#FECB52" ], "font": { "color": "#2a3f5f" }, "geo": { "bgcolor": "white", "lakecolor": "white", "landcolor": "#E5ECF6", "showlakes": true, "showland": true, "subunitcolor": "white" }, "hoverlabel": { "align": "left" }, "hovermode": "closest", "mapbox": { "style": "light" }, "paper_bgcolor": "white", "plot_bgcolor": "#E5ECF6", "polar": { "angularaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "radialaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "scene": { "xaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "yaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "zaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" } }, "shapedefaults": { "line": { "color": "#2a3f5f" } }, "ternary": { "aaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "baxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "caxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "title": { "x": 0.05 }, "xaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 }, "yaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 } } } } } }, "metadata": {}, "output_type": "display_data" } ], "source": [ "fig = px.scatter_3d(x=0, y=1, z=2, data_frame=df_vectors.tail(100), hover_data={\"song_names\": True}, color=\"is_text\", opacity=0.8)\n", "fig.show()\n" ] } ], "metadata": { "kernelspec": { "display_name": "playlist-curator", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.13" } }, "nbformat": 4, "nbformat_minor": 2 }