{ "cells": [ { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "from gpt3_function import *" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "import random\n", "import numpy as np\n", "\n", "def generate_weighted_list(weighted_list, length, verbose=False):\n", " if verbose : print(weighted_list)\n", " items = [*weighted_list.keys()]\n", " weights = [*weighted_list.values()]\n", " weights = np.array(weights)\n", " output = list(np.random.choice(items, length, p=weights/sum(weights)))\n", " return output\n", "\n", "#simple\n", "def kapuhala_list(weighted_list, length):\n", "\n", " def generate_weighted_list(weighted_list, length, verbose=False):\n", " if verbose : print(weighted_list)\n", " items = [*weighted_list.keys()]\n", " weights = [*weighted_list.values()]\n", " weights = np.array(weights)\n", " output = list(np.random.choice(items, length, p=weights/sum(weights)))\n", " return output\n", "\n", " list1 = list()\n", " for index in range(0, length):\n", " weighted_list_ = weighted_list.copy()\n", " if index == 1:\n", " #look 1 position back \n", " del weighted_list_[list1[index-1][0]]\n", " list1.append(generate_weighted_list(weighted_list_, 1))\n", " elif index >= 2:\n", " #look 2 positions back\n", " del weighted_list_[list1[index-2][0]]\n", " del weighted_list_[list1[index-1][0]]\n", " list1.append(generate_weighted_list(weighted_list_, 1))\n", " else:\n", " #we cannot look back otherwise throws error\n", " list1.append(generate_weighted_list(weighted_list_, 1))\n", "\n", " list1 = [x[0] for x in list1] \n", " return list1\n", "\n", "#includes weekdays\n", "def kapuhala_list(weighted_list, weekday_list, length):\n", "\n", " def generate_weighted_list(weighted_list, length, verbose=False):\n", " if verbose : print(weighted_list)\n", " items = [*weighted_list.keys()]\n", " weights = [*weighted_list.values()]\n", " weights = np.array(weights)\n", " output = list(np.random.choice(items, length, p=weights/sum(weights)))\n", " return output\n", "\n", " list1 = list()\n", " for index in range(0, length):\n", " weighted_list_ = weighted_list.copy()\n", " #weekday sequence\n", " current = weekday_list[index] \n", " if (current == 'Saturday') or (current == 'Sunday'):\n", " del weighted_list_['weekend']\n", " #avoid repetitions\n", " if index == 1:\n", " #look 1 position back \n", " try:\n", " del weighted_list_[list1[index-1][0]]\n", " except:\n", " pass\n", " list1.append(generate_weighted_list(weighted_list_, 1))\n", " elif index >= 2:\n", " #look 2 positions back\n", " try:\n", " del weighted_list_[list1[index-12][0]]\n", " except:\n", " pass\n", " try:\n", " del weighted_list_[list1[index-1][0]]\n", " except:\n", " pass\n", " list1.append(generate_weighted_list(weighted_list_, 1))\n", " else:\n", " #we cannot look back otherwise throws error\n", " list1.append(generate_weighted_list(weighted_list_, 1))\n", "\n", " list1 = [x[0] for x in list1] \n", " return list1" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "C:\\Users\\ardit\\AppData\\Local\\Temp\\ipykernel_21100\\3657193565.py:78: SettingWithCopyWarning: \n", "A value is trying to be set on a copy of a slice from a DataFrame.\n", "Try using .loc[row_indexer,col_indexer] = value instead\n", "\n", "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n", " df_['prompt'] = df_['vertical'].apply(lambda x : prompt+dict1[x])\n", "C:\\Users\\ardit\\AppData\\Local\\Temp\\ipykernel_21100\\3657193565.py:82: SettingWithCopyWarning: \n", "A value is trying to be set on a copy of a slice from a DataFrame.\n", "Try using .loc[row_indexer,col_indexer] = value instead\n", "\n", "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n", " df_['post'] = df_['prompt'].apply(lambda x : gpt3(x, model='gpt-3.5-turbo', service='azure'))\n" ] }, { "data": { "text/html": [ "
\n", " | date | \n", "weekday | \n", "vertical | \n", "post | \n", "
---|---|---|---|---|
0 | \n", "2023-11-01 | \n", "Wednesday | \n", "happyHour | \n", "πΉπΉ It's time to unwind and enjoy happy hour at... | \n", "
1 | \n", "2023-11-02 | \n", "Thursday | \n", "wedding | \n", "π°ππ΄ Get ready to say \"I do\" or fall even more ... | \n", "