{ "cells": [ { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [], "source": [ "from openai import OpenAI\n", "import numpy as np\n", "import pandas as pd\n", "import json\n", "import joblib\n", "import tqdm\n", "import os\n", "import glob" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/research/dept8/gds/zjxu21/Anaconda3/envs/IATSF/lib/python3.12/site-packages/huggingface_hub/file_download.py:943: FutureWarning: `resume_download` is deprecated and will be removed in version 1.0.0. Downloads always resume when possible. If you want to force a new download, use `force_download=True`.\n", " warnings.warn(\n", "flash_attn is not installed. Using PyTorch native attention implementation.\n", "flash_attn is not installed. Using PyTorch native attention implementation.\n", "flash_attn is not installed. Using PyTorch native attention implementation.\n", "flash_attn is not installed. Using PyTorch native attention implementation.\n", "flash_attn is not installed. Using PyTorch native attention implementation.\n", "flash_attn is not installed. Using PyTorch native attention implementation.\n", "flash_attn is not installed. Using PyTorch native attention implementation.\n", "flash_attn is not installed. Using PyTorch native attention implementation.\n", "flash_attn is not installed. Using PyTorch native attention implementation.\n", "flash_attn is not installed. Using PyTorch native attention implementation.\n", "flash_attn is not installed. Using PyTorch native attention implementation.\n", "flash_attn is not installed. Using PyTorch native attention implementation.\n", "flash_attn is not installed. Using PyTorch native attention implementation.\n", "flash_attn is not installed. Using PyTorch native attention implementation.\n", "flash_attn is not installed. Using PyTorch native attention implementation.\n", "flash_attn is not installed. Using PyTorch native attention implementation.\n", "flash_attn is not installed. Using PyTorch native attention implementation.\n", "flash_attn is not installed. Using PyTorch native attention implementation.\n", "flash_attn is not installed. Using PyTorch native attention implementation.\n", "flash_attn is not installed. Using PyTorch native attention implementation.\n", "flash_attn is not installed. Using PyTorch native attention implementation.\n", "flash_attn is not installed. Using PyTorch native attention implementation.\n", "flash_attn is not installed. Using PyTorch native attention implementation.\n", "flash_attn is not installed. Using PyTorch native attention implementation.\n", "flash_attn is not installed. Using PyTorch native attention implementation.\n" ] } ], "source": [ "from transformers import AutoModel\n", "\n", "# Initialize the model\n", "model = AutoModel.from_pretrained(\"jinaai/jina-embeddings-v3\", trust_remote_code=True).to(device=\"cuda:0\")\n" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [], "source": [ "\n", "embeddings = model.encode(\n", " [\"What is the weather like in Berlin today?\"],\n", " truncate_dim=256\n", ")" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(1, 256)" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "embeddings.shape" ] }, { "cell_type": "code", "execution_count": 44, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['./weather/new-york/fast_general_formal_forecast_2017.json',\n", " './weather/new-york/fast_general_formal_forecast_2018.json',\n", " './weather/new-york/fast_general_formal_forecast_2019.json',\n", " './weather/new-york/fast_general_formal_forecast_2020.json',\n", " './weather/new-york/fast_general_formal_forecast_2021.json',\n", " './weather/new-york/fast_general_formal_forecast_2022.json',\n", " './weather/new-york/fast_general_formal_forecast_2023.json',\n", " './weather/new-york/fast_general_formal_forecast_2024.json',\n", " './weather/new-york/fast_general_formal_forecast_2025.json',\n", " './weather/new-york/fast_general_weather_forecast_2017.json',\n", " './weather/new-york/fast_general_weather_forecast_2018.json',\n", " './weather/new-york/fast_general_weather_forecast_2019.json',\n", " './weather/new-york/fast_general_weather_forecast_2020.json',\n", " './weather/new-york/fast_general_weather_forecast_2021.json',\n", " './weather/new-york/fast_general_weather_forecast_2022.json',\n", " './weather/new-york/fast_general_weather_forecast_2023.json',\n", " './weather/new-york/fast_general_weather_forecast_2024.json',\n", " './weather/new-york/fast_general_weather_forecast_2025.json']" ] }, "execution_count": 44, "metadata": {}, "output_type": "execute_result" } ], "source": [ "files = glob.glob(\"./weather/new-york/fast_general_*.json\")\n", "files" ] }, { "cell_type": "code", "execution_count": 45, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Loaded 1460 records from ./weather/new-york/fast_general_formal_forecast_2017.json\n", "Processing batch 1/1\n", "Finished processing ./weather/new-york/fast_general_formal_forecast_2017.json\n", "Saved embeddings to ./weather/new-york/fast_general_formal_embeddings_2017.pkl\n", "Loaded 1460 records from ./weather/new-york/fast_general_formal_forecast_2018.json\n", "Processing batch 1/1\n", "Finished processing ./weather/new-york/fast_general_formal_forecast_2018.json\n", "Saved embeddings to ./weather/new-york/fast_general_formal_embeddings_2018.pkl\n", "Loaded 1460 records from ./weather/new-york/fast_general_formal_forecast_2019.json\n", "Processing batch 1/1\n", "Finished processing ./weather/new-york/fast_general_formal_forecast_2019.json\n", "Saved embeddings to ./weather/new-york/fast_general_formal_embeddings_2019.pkl\n", "Loaded 1464 records from ./weather/new-york/fast_general_formal_forecast_2020.json\n", "Processing batch 1/1\n", "Finished processing ./weather/new-york/fast_general_formal_forecast_2020.json\n", "Saved embeddings to ./weather/new-york/fast_general_formal_embeddings_2020.pkl\n", "Loaded 1460 records from ./weather/new-york/fast_general_formal_forecast_2021.json\n", "Processing batch 1/1\n", "Finished processing ./weather/new-york/fast_general_formal_forecast_2021.json\n", "Saved embeddings to ./weather/new-york/fast_general_formal_embeddings_2021.pkl\n", "Loaded 1460 records from ./weather/new-york/fast_general_formal_forecast_2022.json\n", "Processing batch 1/1\n", "Finished processing ./weather/new-york/fast_general_formal_forecast_2022.json\n", "Saved embeddings to ./weather/new-york/fast_general_formal_embeddings_2022.pkl\n", "Loaded 1459 records from ./weather/new-york/fast_general_formal_forecast_2023.json\n", "Processing batch 1/1\n", "Finished processing ./weather/new-york/fast_general_formal_forecast_2023.json\n", "Saved embeddings to ./weather/new-york/fast_general_formal_embeddings_2023.pkl\n", "Loaded 1464 records from ./weather/new-york/fast_general_formal_forecast_2024.json\n", "Processing batch 1/1\n", "Finished processing ./weather/new-york/fast_general_formal_forecast_2024.json\n", "Saved embeddings to ./weather/new-york/fast_general_formal_embeddings_2024.pkl\n", "Loaded 260 records from ./weather/new-york/fast_general_formal_forecast_2025.json\n", "Processing batch 1/1\n", "Finished processing ./weather/new-york/fast_general_formal_forecast_2025.json\n", "Saved embeddings to ./weather/new-york/fast_general_formal_embeddings_2025.pkl\n", "Loaded 365 records from ./weather/new-york/fast_general_weather_forecast_2017.json\n", "Processing batch 1/1\n", "Finished processing ./weather/new-york/fast_general_weather_forecast_2017.json\n", "Saved embeddings to ./weather/new-york/fast_general_weather_embeddings_2017.pkl\n", "Loaded 365 records from ./weather/new-york/fast_general_weather_forecast_2018.json\n", "Processing batch 1/1\n", "Finished processing ./weather/new-york/fast_general_weather_forecast_2018.json\n", "Saved embeddings to ./weather/new-york/fast_general_weather_embeddings_2018.pkl\n", "Loaded 365 records from ./weather/new-york/fast_general_weather_forecast_2019.json\n", "Processing batch 1/1\n", "Finished processing ./weather/new-york/fast_general_weather_forecast_2019.json\n", "Saved embeddings to ./weather/new-york/fast_general_weather_embeddings_2019.pkl\n", "Loaded 366 records from ./weather/new-york/fast_general_weather_forecast_2020.json\n", "Processing batch 1/1\n", "Finished processing ./weather/new-york/fast_general_weather_forecast_2020.json\n", "Saved embeddings to ./weather/new-york/fast_general_weather_embeddings_2020.pkl\n", "Loaded 365 records from ./weather/new-york/fast_general_weather_forecast_2021.json\n", "Processing batch 1/1\n", "Finished processing ./weather/new-york/fast_general_weather_forecast_2021.json\n", "Saved embeddings to ./weather/new-york/fast_general_weather_embeddings_2021.pkl\n", "Loaded 365 records from ./weather/new-york/fast_general_weather_forecast_2022.json\n", "Processing batch 1/1\n", "Finished processing ./weather/new-york/fast_general_weather_forecast_2022.json\n", "Saved embeddings to ./weather/new-york/fast_general_weather_embeddings_2022.pkl\n", "Loaded 365 records from ./weather/new-york/fast_general_weather_forecast_2023.json\n", "Processing batch 1/1\n", "Finished processing ./weather/new-york/fast_general_weather_forecast_2023.json\n", "Saved embeddings to ./weather/new-york/fast_general_weather_embeddings_2023.pkl\n", "Loaded 366 records from ./weather/new-york/fast_general_weather_forecast_2024.json\n", "Processing batch 1/1\n", "Finished processing ./weather/new-york/fast_general_weather_forecast_2024.json\n", "Saved embeddings to ./weather/new-york/fast_general_weather_embeddings_2024.pkl\n", "Loaded 65 records from ./weather/new-york/fast_general_weather_forecast_2025.json\n", "Processing batch 1/1\n", "Finished processing ./weather/new-york/fast_general_weather_forecast_2025.json\n", "Saved embeddings to ./weather/new-york/fast_general_weather_embeddings_2025.pkl\n" ] } ], "source": [ "step = 1500\n", "for file in files:\n", " with open(file, \"r\") as f:\n", " data = json.load(f)\n", " print(f\"Loaded {len(data)} records from {file}\")\n", " timestamps = list(data.keys())\n", " emb_dict = {}\n", " for i in range(0, len(timestamps), step):\n", " if i + step > len(timestamps):\n", " batch = timestamps[i:]\n", " else:\n", " batch = timestamps[i:i + step]\n", " print(f\"Processing batch {i // step + 1}/{len(timestamps) // step + 1}\")\n", " batch_list= []\n", " len_list= [0]\n", " for timestamp in batch:\n", " _ = list(data[timestamp].values())\n", " batch_list += _\n", " len_list.append(len(batch_list))\n", " batch_list = [f'New York City: {x}' for x in batch_list]\n", " embeddings = model.encode(\n", " batch_list,\n", " truncate_dim=256\n", " )\n", " for j in range(len(batch)):\n", " timestamp = batch[j]\n", " emb_dict[timestamp] = embeddings[len_list[j]:len_list[j + 1],:]\n", " print(f\"Finished processing {file}\")\n", " # Save the embeddings\n", " output_file = file.replace(\"forecast\", \"embeddings\")\n", " output_file = output_file.replace(\".json\", \".pkl\")\n", "\n", " with open(output_file, \"wb\") as f:\n", " joblib.dump(emb_dict, f)\n", " print(f\"Saved embeddings to {output_file}\")\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## create static info" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "87" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "id_info = json.load(open('../id_info_imputed.json', 'r'))\n", "len(id_info)" ] }, { "cell_type": "code", "execution_count": 32, "metadata": {}, "outputs": [], "source": [ "static_info = {}\n", "\n", "static_info['general_info'] = 'This dataset contains Average Speed of a Vehicle Traveled Between End Points data in km/h collected from various locations in New York City by sensors. The sampling rate is every 5 minutes. When no car is detected in the period, the speed is set to 0.'\n", "static_info['downtime_prompt'] = \"The sensor is down for unknown reasons, readings set to 0. \"\n", "static_info['channel_info'] = {}\n", "for channel in id_info.keys():\n", " static_info['channel_info'][channel] = f\"Sensor {channel} is located at {id_info[channel]['borough']}, with segment of {id_info[channel]['link']}.\"" ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "dict_keys(['general_info', 'downtime_prompt', 'channel_info'])" ] }, "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ "json.dump(static_info, open(\"../static_info.json\", 'w'))\n", "static_info.keys()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# load static_info from json file\n", "# static_info = json.load(open(\"../static_info.json\", 'r'))" ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['This dataset contains Average Speed of a Vehicle Traveled Between End Points data in km/h collected from various locations in New York City by sensors. The sampling rate is every 5 minutes. When no car is detected in the period, the speed is set to 0.',\n", " 'The sensor is down for unknown reasons, readings set to 0. ',\n", " 'Sensor 204 is located at Queens, with segment of CIP N TNB - Whitestone Expwy S Exit 14 (Linden Pl).',\n", " 'Sensor 184 is located at Bronx, with segment of CBE E TAYLOR AVENUE - CASTLE HILL AVENUE.',\n", " 'Sensor 217 is located at Manhattan, with segment of FDR N Catherine Slip - 25th St.',\n", " 'Sensor 221 is located at Manhattan, with segment of FDR S 25th St - Catherine Slip.',\n", " 'Sensor 149 is located at Manhattan, with segment of BQE N Atlantic Ave - BKN Bridge Manhattan Side.',\n", " 'Sensor 223 is located at Manhattan, with segment of FDR S Catherine Slip - BKN Bridge Manhattan Side.',\n", " 'Sensor 145 is located at Manhattan, with segment of BKN Bridge Manhattan Side - FDR N Catherine Slip.',\n", " 'Sensor 208 is located at Queens, with segment of CIP S LIE - Hempstead Tpk.',\n", " 'Sensor 207 is located at Queens, with segment of CIP S Hempstead Tpk - Laurelton Pkwy @ SSP.',\n", " 'Sensor 332 is located at Queens, with segment of Laurelton Pkwy S @ SSP - Belt Pkwy W 182nd St.',\n", " 'Sensor 169 is located at Queens, with segment of Belt Pkwy E 182nd St - Laurelton Pkwy N @ SSP.',\n", " 'Sensor 170 is located at Queens, with segment of Belt Pkwy W 182nd St - JFK Expressway.',\n", " 'Sensor 171 is located at Queens, with segment of Belt Pkwy W JFK Expressway - VWE N Jamaica Ave.',\n", " 'Sensor 315 is located at Queens, with segment of LIE W 108TH ST - 84TH ST.',\n", " 'Sensor 330 is located at Manhattan, with segment of LINCOLN TUNNEL W NORTH TUBE NY - NJ.',\n", " 'Sensor 345 is located at Bronx, with segment of MDE S HARLEM RIVER PARK - GWB W AMSTERDAM AVENUE UPPER LEVEL.',\n", " 'Sensor 344 is located at Bronx, with segment of MDE S HARLEM RIVER PARK - GWB W AMSTERDAM AVENUE LOWER LEVEL.',\n", " 'Sensor 191 is located at Bronx, with segment of CBE W MORRIS AVE - GWB W AMSTERDAM AVE (U/LVL).',\n", " 'Sensor 213 is located at Manhattan, with segment of FDR N - TBB E 116TH STREET - MANHATTAN TRUSS.',\n", " 'Sensor 399 is located at Manhattan, with segment of TBB W - FDR S MANHATTAN TRUSS - E116TH STREET.',\n", " 'Sensor 395 is located at Queens, with segment of TBB N QUEENS ANCHORAGE - MANHATTAN LIFT SPAN.',\n", " 'Sensor 410 is located at Brooklyn, with segment of VNB E SI GANTRY LOWER LEVEL - BROOLKYN GANTRY LOWER LEVEL.',\n", " 'Sensor 347 is located at Queens, with segment of MDE S TBB EXIT RAMP - QUEENS ANCHORAGE.',\n", " 'Sensor 140 is located at Queens, with segment of BE S TBB EXIT RAMP - MANHATTAN LIFT SPAN.',\n", " 'Sensor 398 is located at Queens, with segment of TBB S MANHATTAN LIFT SPAN - QUEENS ANCHORAGE.',\n", " 'Sensor 202 is located at Queens, with segment of CIP N ramp to TNB - TNB Queens Anchorage.',\n", " 'Sensor 168 is located at Bronx, with segment of BWB S Toll Plaza - Queens Anchorage.',\n", " 'Sensor 298 is located at Bronx, with segment of HRP S Lafayette Ave - BWB S Toll Plaza.',\n", " 'Sensor 451 is located at Queens, with segment of Whitestone Expwy N Exit 14 (Linden Pl) - BWB N Queens Anchorage.',\n", " 'Sensor 416 is located at Brooklyn, with segment of VNB W BROOKLYN GANTRY LOWER LEVEL - SI GANTRY LOWER LEVEL.',\n", " 'Sensor 190 is located at Bronx, with segment of CBE W MORRIS AVE - GWB W AMSTERDAM AVE (L/LVL).',\n", " 'Sensor 212 is located at Queens, with segment of CVE NB LIE - WILLETS PT BLVD.',\n", " 'Sensor 318 is located at Queens, with segment of LIE WB LITTLE NECK PKWY - NB CIP.',\n", " 'Sensor 211 is located at Queens, with segment of CVE NB GCP - WILLETS PT BLVD.',\n", " 'Sensor 319 is located at Queens, with segment of LIE WB LITTLE NECK PKWY - NB CVE.',\n", " 'Sensor 311 is located at Queens, with segment of LIE E 84TH ST - 108TH ST.',\n", " 'Sensor 419 is located at Staten island, with segment of VNB W-SIE W SI GANTRY UPPER LEVEL - FINGERBOARD ROAD.',\n", " 'Sensor 418 is located at Staten Island, with segment of VNB W-SIE W SI GANTRY LOWER LEVEL - FINGERBOARD ROAD.',\n", " 'Sensor 387 is located at Staten Island, with segment of SIE W FINGERBOARD ROAD - CLOVE ROAD.',\n", " 'Sensor 385 is located at Staten Island, with segment of SIE W BRADLEY AVENUE - WOOLEY AVENUE.',\n", " 'Sensor 390 is located at Staten Island, with segment of SIE W WOOLEY AVENUE - RICHMOND AVENUE.',\n", " 'Sensor 388 is located at Staten Island, with segment of SIE W RICHMOND AVENUE - SOUTH AVENUE.',\n", " 'Sensor 412 is located at Brooklyn, with segment of VNB E-GOWANUS N BROOKLYN GANTRY LOWER LEVEL - 92ND STREET.',\n", " 'Sensor 413 is located at Brooklyn, with segment of VNB E-GOWANUS N BROOKLYN GANTRY UPPER LEVEL - 92ND STREET.',\n", " 'Sensor 258 is located at Brooklyn, with segment of GOW N 92ND STREET - 7TH AVENUE.',\n", " 'Sensor 259 is located at Brooklyn, with segment of GOW N 9TH STREET - ATLANTIC AVENUE.',\n", " 'Sensor 394 is located at Queens, with segment of TBB N QUEENS ANCHORAGE - BE N.',\n", " 'Sensor 261 is located at Brooklyn, with segment of GOW S 7TH AVENUE - 92ND STREET.',\n", " 'Sensor 154 is located at Brooklyn, with segment of BQE S - GOW S ALTANTIC AVENUE - 9TH STREET.',\n", " 'Sensor 155 is located at Brooklyn, with segment of BQE S 46TH STREET - LEONARD STREET.',\n", " 'Sensor 153 is located at Brooklyn, with segment of BQE N LEONARD STREET - 46TH STREET.',\n", " 'Sensor 453 is located at Queens, with segment of Whitestone Expwy S Exit 14 (Linden Pl) - VWE S MP8.65 (Exit 13 Northern Blvd).',\n", " 'Sensor 428 is located at Queens, with segment of VWE S MP8.65 (Exit 13 Northern Blvd) - MP6.39 (Exit 11 Jewel Ave).',\n", " 'Sensor 129 is located at Bronx, with segment of BE N STRATFORD AVENUE - CASTLE HILL AVE.',\n", " 'Sensor 126 is located at Bronx, with segment of BE N Castle Hill Avenue - Griswold Ave.',\n", " 'Sensor 295 is located at Bronx, with segment of HRP N LAFAYETTE AVENUE - E TREMONT AVENUE.',\n", " 'Sensor 427 is located at Queens, with segment of VWE S MP6.39 (Exit 11 Jewel Ave) - MP4.63 (Exit 6 Jamaica Ave).',\n", " 'Sensor 142 is located at Bronx, with segment of BE S Griswold - Castle Hill Avenue.',\n", " 'Sensor 185 is located at Bronx, with segment of CBE W CASTLE HILL AVENUE - TAYLOR AVENUE.',\n", " 'Sensor 426 is located at Queens, with segment of VWE S MP4.63 (Exit 6 Jamaica Ave) - MP2.66 (Exit 2 Roackaway Blvd).',\n", " 'Sensor 425 is located at Queens, with segment of VWE S MP2.66 (Exit 2 Rockaway Blvd) - Belt Pkwy E 182nd St.',\n", " 'Sensor 178 is located at Bronx, with segment of CBE E CASTLE HILL AVE - BE N WATERBURY AVE.',\n", " 'Sensor 422 is located at Queens, with segment of VWE N MP4.63 (Exit 6 - Jamaica Ave) - MP6.39 (Exit 11 Jewel Ave).',\n", " 'Sensor 423 is located at Queens, with segment of VWE N MP6.39 (Exit 11 Jewel Ave) - MP8.65 (Exit 13 Northern Blvd).',\n", " 'Sensor 424 is located at Queens, with segment of VWE N MP8.64 (Exit 13 Northern Blvd) - Whitestone Expwy Exit 14 (Linden Pl).',\n", " 'Sensor 165 is located at Bronx, with segment of BWB N Toll Plaza - HRP N Lafayatte Ave.',\n", " 'Sensor 177 is located at Bronx, with segment of CBE E AMSTERDAM AVE(U/LVL) - MORRIS AVE.',\n", " 'Sensor 172 is located at Bronx, with segment of CBE AMSTERDAM AVE (L/LVL) - MORRIS AVE.',\n", " 'Sensor 167 is located at Queens, with segment of BWB S Queens Anchorage - WSE S Exit 14 (Linden Pl).',\n", " 'Sensor 257 is located at Brooklyn, with segment of GOW N 7TH AVENUE - 9TH STREET.',\n", " 'Sensor 222 is located at Manhattan, with segment of FDR S 63rd - 25th St.',\n", " 'Sensor 215 is located at Manhattan, with segment of FDR N 25th - 63rd St.',\n", " 'Sensor 265 is located at Manhattan, with segment of GWB E LOWER LEVEL PLAZA - CBE E LOWER LEVEL AMSTERDAM AVE.',\n", " 'Sensor 380 is located at Staten Island, with segment of SIE E VNB E FINGERBOARD ROAD - SI GANTRY UPPER LEVEL.',\n", " 'Sensor 137 is located at Bronx, with segment of BE S CASTLE HILL AVENUE - STRATFORD AVENUE.',\n", " 'Sensor 124 is located at Manhattan, with segment of BBT W Toll Plaza - Manhattan Portal.',\n", " 'Sensor 205 is located at Queens, with segment of CIP NB GCP - TNB.',\n", " 'Sensor 206 is located at Queens, with segment of CIP N LIE ramp - TNB.',\n", " 'Sensor 405 is located at Queens, with segment of TNB S Qns Anchorage - CIP S @ TNB.',\n", " 'Sensor 376 is located at Staten Island, with segment of SIE E CLOVE ROAD - FINGERBOARD ROAD.',\n", " 'Sensor 375 is located at Staten Island, with segment of SIE E BRADLEY AVENUE - CLOVE ROAD.',\n", " 'Sensor 381 is located at Staten Island, with segment of SIE E WOOLEY AVENUE - BRADLEY AVENUE.',\n", " 'Sensor 377 is located at Staten Island, with segment of SIE E RICHMOND AVENUE - WOOLEY AVENUE.',\n", " 'Sensor 378 is located at Staten Island, with segment of SIE E SOUTH AVENUE - RICHMOND AVENUE.',\n", " 'Sensor 435 is located at Staten Island, with segment of WSE N-SIE E SOUTH AVENUE - SOUTH AVENUE.',\n", " 'Sensor 384 is located at Staten Island, with segment of SIE W - WSE S SOUTH AVENUE - SOUTH AVENUE.',\n", " 'Sensor 157 is located at Brooklyn, with segment of BQE S LEONARD STREET - ATLANTIC AVENUE.']" ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "channels = list(static_info['channel_info'].keys())\n", "\n", "text_to_emb = [static_info['general_info'], static_info['downtime_prompt']] + [static_info['channel_info'][i] for i in channels]\n", "text_to_emb" ] }, { "cell_type": "code", "execution_count": 35, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "89" ] }, "execution_count": 35, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(text_to_emb)" ] }, { "cell_type": "code", "execution_count": 36, "metadata": {}, "outputs": [], "source": [ "embeddings = model.encode(\n", " text_to_emb,\n", " truncate_dim=256\n", ")" ] }, { "cell_type": "code", "execution_count": 37, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(89, 256)" ] }, "execution_count": 37, "metadata": {}, "output_type": "execute_result" } ], "source": [ "embeddings.shape" ] }, { "cell_type": "code", "execution_count": 38, "metadata": {}, "outputs": [], "source": [ "static_info['general_info'] = embeddings[0:1,:]\n", "static_info['downtime_prompt'] = embeddings[1:2,:]\n", "for i in range(len(channels)):\n", " static_info['channel_info'][channels[i]] = embeddings[i+2:i+3,:]" ] }, { "cell_type": "code", "execution_count": 39, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['../static_info.pkl']" ] }, "execution_count": 39, "metadata": {}, "output_type": "execute_result" } ], "source": [ "joblib.dump(static_info, \"../static_info.pkl\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "--------------\n", "## Merge embeddings" ] }, { "cell_type": "code", "execution_count": 49, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['./weather/queens/fast_general_formal_embeddings_2017.pkl',\n", " './weather/queens/fast_general_formal_embeddings_2018.pkl',\n", " './weather/queens/fast_general_formal_embeddings_2019.pkl',\n", " './weather/queens/fast_general_formal_embeddings_2020.pkl',\n", " './weather/queens/fast_general_formal_embeddings_2021.pkl',\n", " './weather/queens/fast_general_formal_embeddings_2022.pkl',\n", " './weather/queens/fast_general_formal_embeddings_2023.pkl',\n", " './weather/queens/fast_general_formal_embeddings_2024.pkl',\n", " './weather/queens/fast_general_formal_embeddings_2025.pkl',\n", " './weather/queens/fast_general_weather_embeddings_2017.pkl',\n", " './weather/queens/fast_general_weather_embeddings_2018.pkl',\n", " './weather/queens/fast_general_weather_embeddings_2019.pkl',\n", " './weather/queens/fast_general_weather_embeddings_2020.pkl',\n", " './weather/queens/fast_general_weather_embeddings_2021.pkl',\n", " './weather/queens/fast_general_weather_embeddings_2022.pkl',\n", " './weather/queens/fast_general_weather_embeddings_2023.pkl',\n", " './weather/queens/fast_general_weather_embeddings_2024.pkl',\n", " './weather/queens/fast_general_weather_embeddings_2025.pkl']" ] }, "execution_count": 49, "metadata": {}, "output_type": "execute_result" } ], "source": [ "files = glob.glob(\"./weather/queens/fast_general_*.pkl\")\n", "files" ] }, { "cell_type": "code", "execution_count": 51, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Processing ./weather/queens/fast_general_formal_embeddings_2017.pkl\n", "Finished processing ./weather/queens/fast_general_formal_embeddings_2017.pkl\n", "Saved embeddings to ./weather/fast_general_formal_embeddings_2017.pkl\n", "Processing ./weather/queens/fast_general_formal_embeddings_2018.pkl\n", "Finished processing ./weather/queens/fast_general_formal_embeddings_2018.pkl\n", "Saved embeddings to ./weather/fast_general_formal_embeddings_2018.pkl\n", "Processing ./weather/queens/fast_general_formal_embeddings_2019.pkl\n", "Finished processing ./weather/queens/fast_general_formal_embeddings_2019.pkl\n", "Saved embeddings to ./weather/fast_general_formal_embeddings_2019.pkl\n", "Processing ./weather/queens/fast_general_formal_embeddings_2020.pkl\n", "Finished processing ./weather/queens/fast_general_formal_embeddings_2020.pkl\n", "Saved embeddings to ./weather/fast_general_formal_embeddings_2020.pkl\n", "Processing ./weather/queens/fast_general_formal_embeddings_2021.pkl\n", "Finished processing ./weather/queens/fast_general_formal_embeddings_2021.pkl\n", "Saved embeddings to ./weather/fast_general_formal_embeddings_2021.pkl\n", "Processing ./weather/queens/fast_general_formal_embeddings_2022.pkl\n", "Finished processing ./weather/queens/fast_general_formal_embeddings_2022.pkl\n", "Saved embeddings to ./weather/fast_general_formal_embeddings_2022.pkl\n", "Processing ./weather/queens/fast_general_formal_embeddings_2023.pkl\n", "Finished processing ./weather/queens/fast_general_formal_embeddings_2023.pkl\n", "Saved embeddings to ./weather/fast_general_formal_embeddings_2023.pkl\n", "Processing ./weather/queens/fast_general_formal_embeddings_2024.pkl\n", "Finished processing ./weather/queens/fast_general_formal_embeddings_2024.pkl\n", "Saved embeddings to ./weather/fast_general_formal_embeddings_2024.pkl\n", "Processing ./weather/queens/fast_general_formal_embeddings_2025.pkl\n", "Finished processing ./weather/queens/fast_general_formal_embeddings_2025.pkl\n", "Saved embeddings to ./weather/fast_general_formal_embeddings_2025.pkl\n", "Processing ./weather/queens/fast_general_weather_embeddings_2017.pkl\n", "Finished processing ./weather/queens/fast_general_weather_embeddings_2017.pkl\n", "Saved embeddings to ./weather/fast_general_weather_embeddings_2017.pkl\n", "Processing ./weather/queens/fast_general_weather_embeddings_2018.pkl\n", "Finished processing ./weather/queens/fast_general_weather_embeddings_2018.pkl\n", "Saved embeddings to ./weather/fast_general_weather_embeddings_2018.pkl\n", "Processing ./weather/queens/fast_general_weather_embeddings_2019.pkl\n", "Finished processing ./weather/queens/fast_general_weather_embeddings_2019.pkl\n", "Saved embeddings to ./weather/fast_general_weather_embeddings_2019.pkl\n", "Processing ./weather/queens/fast_general_weather_embeddings_2020.pkl\n", "Finished processing ./weather/queens/fast_general_weather_embeddings_2020.pkl\n", "Saved embeddings to ./weather/fast_general_weather_embeddings_2020.pkl\n", "Processing ./weather/queens/fast_general_weather_embeddings_2021.pkl\n", "Finished processing ./weather/queens/fast_general_weather_embeddings_2021.pkl\n", "Saved embeddings to ./weather/fast_general_weather_embeddings_2021.pkl\n", "Processing ./weather/queens/fast_general_weather_embeddings_2022.pkl\n", "Finished processing ./weather/queens/fast_general_weather_embeddings_2022.pkl\n", "Saved embeddings to ./weather/fast_general_weather_embeddings_2022.pkl\n", "Processing ./weather/queens/fast_general_weather_embeddings_2023.pkl\n", "Finished processing ./weather/queens/fast_general_weather_embeddings_2023.pkl\n", "Saved embeddings to ./weather/fast_general_weather_embeddings_2023.pkl\n", "Processing ./weather/queens/fast_general_weather_embeddings_2024.pkl\n", "Finished processing ./weather/queens/fast_general_weather_embeddings_2024.pkl\n", "Saved embeddings to ./weather/fast_general_weather_embeddings_2024.pkl\n", "Processing ./weather/queens/fast_general_weather_embeddings_2025.pkl\n", "Finished processing ./weather/queens/fast_general_weather_embeddings_2025.pkl\n", "Saved embeddings to ./weather/fast_general_weather_embeddings_2025.pkl\n" ] } ], "source": [ "a = {}\n", "for i in files:\n", " print(f\"Processing {i}\")\n", " with open(i, \"rb\") as f:\n", " data1 = joblib.load(f)\n", " with open(i.replace(\"queens\", 'brooklyn'), \"rb\") as f:\n", " data2 = joblib.load(f)\n", " with open(i.replace(\"queens\", 'new-york'), \"rb\") as f:\n", " data3 = joblib.load(f)\n", "\n", " for k in data1.keys():\n", " b = []\n", " b.append(data1[k])\n", " b.append(data2[k])\n", " b.append(data3[k])\n", " b = np.concatenate(b, axis=0)\n", " a[k] = b\n", " print(f\"Finished processing {i}\")\n", " # Save the embeddings\n", " output_file = i.replace(\"queens/\", \"\")\n", " joblib.dump(a, output_file)\n", " print(f\"Saved embeddings to {output_file}\")\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "--------\n", "## test fake dynamic data" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "application/vnd.microsoft.datawrangler.viewer.v0+json": { "columns": [ { "name": "index", "rawType": "object", "type": "string" }, { "name": "0", "rawType": "int64", "type": "integer" } ], "conversionMethod": "pd.DataFrame", "ref": "230da4ee-0271-483a-a2a8-be1983bd03d1", "rows": [ [ "20250101", "0" ], [ "20250102", "0" ], [ "20250103", "0" ], [ "20250104", "0" ], [ "20250105", "0" ], [ "20250106", "0" ], [ "20250107", "0" ], [ "20250108", "0" ], [ "20250109", "0" ], [ "20250110", "0" ], [ "20250111", "0" ], [ "20250112", "0" ], [ "20250113", "0" ], [ "20250114", "0" ], [ "20250115", "0" ], [ "20250116", "0" ], [ "20250117", "0" ], [ "20250118", "0" ], [ "20250119", "0" ], [ "20250120", "0" ], [ "20250121", "0" ], [ "20250122", "0" ], [ "20250123", "0" ], [ "20250124", "0" ], [ "20250125", "0" ], [ "20250126", "0" ], [ "20250127", "0" ], [ "20250128", "0" ], [ "20250129", "0" ], [ "20250130", "0" ], [ "20250131", "0" ], [ "20250201", "0" ], [ "20250202", "0" ], [ "20250203", "0" ], [ "20250204", "0" ], [ "20250205", "0" ], [ "20250206", "0" ], [ "20250207", "0" ], [ "20250208", "0" ], [ "20250209", "0" ], [ "20250210", "0" ], [ "20250211", "0" ], [ "20250212", "0" ], [ "20250213", "0" ], [ "20250214", "0" ], [ "20250215", "0" ], [ "20250216", "0" ], [ "20250217", "0" ], [ "20250218", "0" ], [ "20250219", "0" ] ], "shape": { "columns": 1, "rows": 76 } }, "text/html": [ "
| \n", " | 0 | \n", "
|---|---|
| 20250101 | \n", "0 | \n", "
| 20250102 | \n", "0 | \n", "
| 20250103 | \n", "0 | \n", "
| 20250104 | \n", "0 | \n", "
| 20250105 | \n", "0 | \n", "
| ... | \n", "... | \n", "
| 20250313 | \n", "0 | \n", "
| 20250314 | \n", "0 | \n", "
| 20250315 | \n", "0 | \n", "
| 20250316 | \n", "0 | \n", "
| 20250317 | \n", "0 | \n", "
76 rows × 1 columns
\n", "