!pip install getenv openai==1.12.0
Requirement already satisfied: getenv in /usr/local/python/3.10.13/lib/python3.10/site-packages (0.2.0) Requirement already satisfied: openai==1.12.0 in /usr/local/python/3.10.13/lib/python3.10/site-packages (1.12.0) Requirement already satisfied: anyio<5,>=3.5.0 in /home/codespace/.local/lib/python3.10/site-packages (from openai==1.12.0) (4.2.0) Requirement already satisfied: distro<2,>=1.7.0 in /usr/local/python/3.10.13/lib/python3.10/site-packages (from openai==1.12.0) (1.9.0) Requirement already satisfied: httpx<1,>=0.23.0 in /home/codespace/.local/lib/python3.10/site-packages (from openai==1.12.0) (0.26.0) Requirement already satisfied: pydantic<3,>=1.9.0 in /usr/local/python/3.10.13/lib/python3.10/site-packages (from openai==1.12.0) (2.6.1) Requirement already satisfied: sniffio in /home/codespace/.local/lib/python3.10/site-packages (from openai==1.12.0) (1.3.0) Requirement already satisfied: tqdm>4 in /usr/local/python/3.10.13/lib/python3.10/site-packages (from openai==1.12.0) (4.64.0) Requirement already satisfied: typing-extensions<5,>=4.7 in /home/codespace/.local/lib/python3.10/site-packages (from openai==1.12.0) (4.9.0) Requirement already satisfied: idna>=2.8 in /home/codespace/.local/lib/python3.10/site-packages (from anyio<5,>=3.5.0->openai==1.12.0) (3.6) Requirement already satisfied: exceptiongroup>=1.0.2 in /home/codespace/.local/lib/python3.10/site-packages (from anyio<5,>=3.5.0->openai==1.12.0) (1.2.0) Requirement already satisfied: certifi in /home/codespace/.local/lib/python3.10/site-packages (from httpx<1,>=0.23.0->openai==1.12.0) (2024.2.2) Requirement already satisfied: httpcore==1.* in /home/codespace/.local/lib/python3.10/site-packages (from httpx<1,>=0.23.0->openai==1.12.0) (1.0.2) Requirement already satisfied: h11<0.15,>=0.13 in /home/codespace/.local/lib/python3.10/site-packages (from httpcore==1.*->httpx<1,>=0.23.0->openai==1.12.0) (0.14.0) Requirement already satisfied: annotated-types>=0.4.0 in /usr/local/python/3.10.13/lib/python3.10/site-packages (from pydantic<3,>=1.9.0->openai==1.12.0) (0.6.0) Requirement already satisfied: pydantic-core==2.16.2 in /usr/local/python/3.10.13/lib/python3.10/site-packages (from pydantic<3,>=1.9.0->openai==1.12.0) (2.16.2)
import os
import pandas as pd
import numpy as np
import openai
Creating a Azure Cosmos DB database
pip install azure-cosmos
Requirement already satisfied: azure-cosmos in /usr/local/python/3.10.13/lib/python3.10/site-packages (4.5.1) Requirement already satisfied: azure-core<2.0.0,>=1.23.0 in /usr/local/python/3.10.13/lib/python3.10/site-packages (from azure-cosmos) (1.30.0) Requirement already satisfied: requests>=2.21.0 in /home/codespace/.local/lib/python3.10/site-packages (from azure-core<2.0.0,>=1.23.0->azure-cosmos) (2.31.0) Requirement already satisfied: six>=1.11.0 in /home/codespace/.local/lib/python3.10/site-packages (from azure-core<2.0.0,>=1.23.0->azure-cosmos) (1.16.0) Requirement already satisfied: typing-extensions>=4.6.0 in /home/codespace/.local/lib/python3.10/site-packages (from azure-core<2.0.0,>=1.23.0->azure-cosmos) (4.9.0) Requirement already satisfied: charset-normalizer<4,>=2 in /home/codespace/.local/lib/python3.10/site-packages (from requests>=2.21.0->azure-core<2.0.0,>=1.23.0->azure-cosmos) (3.3.2) Requirement already satisfied: idna<4,>=2.5 in /home/codespace/.local/lib/python3.10/site-packages (from requests>=2.21.0->azure-core<2.0.0,>=1.23.0->azure-cosmos) (3.6) Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/python/3.10.13/lib/python3.10/site-packages (from requests>=2.21.0->azure-core<2.0.0,>=1.23.0->azure-cosmos) (2.0.7) Requirement already satisfied: certifi>=2017.4.17 in /home/codespace/.local/lib/python3.10/site-packages (from requests>=2.21.0->azure-core<2.0.0,>=1.23.0->azure-cosmos) (2024.2.2) Note: you may need to restart the kernel to use updated packages.
## create your cosmoss db on Azure CLI using the following commands
## az login
## az group create -n <resource-group-name> -l <location>
## az cosmosdb create -n <cosmos-db-name> -r <resource-group-name>
## az cosmosdb list-keys -n <cosmos-db-name> -g <resource-group-name>
## Once done navigate to data explorer and create a new database and a new container
from azure.cosmos import CosmosClient
# Initialize Cosmos Client
url = os.getenv('COSMOS_DB_ENDPOINT')
key = os.getenv('COSMOS_DB_KEY')
client = CosmosClient(url, credential=key)
# Select database
database_name = 'rag-cosmos-db'
database = client.get_database_client(database_name)
# Select container
container_name = 'data'
container = database.get_container_client(container_name)
import pandas as pd
# Initialize an empty DataFrame
df = pd.DataFrame(columns=['path', 'text'])
# splitting our data into chunks
data_paths= ["data/frameworks.md?WT.mc_id=academic-105485-koreyst", "data/own_framework.md?WT.mc_id=academic-105485-koreyst", "data/perceptron.md?WT.mc_id=academic-105485-koreyst"]
for path in data_paths:
with open(path, 'r', encoding='utf-8') as file:
file_content = file.read()
# Append the file path and text to the DataFrame
df = df.append({'path': path, 'text': file_content}, ignore_index=True)
df.head()
/tmp/ipykernel_25612/20051717.py:15: FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead. df = df.append({'path': path, 'text': file_content}, ignore_index=True) /tmp/ipykernel_25612/20051717.py:15: FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead. df = df.append({'path': path, 'text': file_content}, ignore_index=True) /tmp/ipykernel_25612/20051717.py:15: FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead. df = df.append({'path': path, 'text': file_content}, ignore_index=True)
path | text | |
---|---|---|
0 | data/frameworks.md | # Neural Network Frameworks\n\nAs we have lear... |
1 | data/own_framework.md | # Introduction to Neural Networks. Multi-Layer... |
2 | data/perceptron.md | # Introduction to Neural Networks: Perceptron\... |
def split_text(text, max_length, min_length):
words = text.split()
chunks = []
current_chunk = []
for word in words:
current_chunk.append(word)
if len(' '.join(current_chunk)) < max_length and len(' '.join(current_chunk)) > min_length:
chunks.append(' '.join(current_chunk))
current_chunk = []
# If the last chunk didn't reach the minimum length, add it anyway
if current_chunk:
chunks.append(' '.join(current_chunk))
return chunks
# Assuming analyzed_df is a pandas DataFrame and 'output_content' is a column in that DataFrame
splitted_df = df.copy()
splitted_df['chunks'] = splitted_df['text'].apply(lambda x: split_text(x, 400, 300))
splitted_df
path | text | chunks | |
---|---|---|---|
0 | data/frameworks.md | # Neural Network Frameworks\n\nAs we have lear... | [# Neural Network Frameworks As we have learne... |
1 | data/own_framework.md | # Introduction to Neural Networks. Multi-Layer... | [# Introduction to Neural Networks. Multi-Laye... |
2 | data/perceptron.md | # Introduction to Neural Networks: Perceptron\... | [# Introduction to Neural Networks: Perceptron... |
# Assuming 'chunks' is a column of lists in the DataFrame splitted_df, we will split the chunks into different rows
flattened_df = splitted_df.explode('chunks')
flattened_df.head()
path | text | chunks | |
---|---|---|---|
0 | data/frameworks.md | # Neural Network Frameworks\n\nAs we have lear... | # Neural Network Frameworks As we have learned... |
0 | data/frameworks.md | # Neural Network Frameworks\n\nAs we have lear... | descent optimization While the `numpy` library... |
0 | data/frameworks.md | # Neural Network Frameworks\n\nAs we have lear... | should give us the opportunity to compute grad... |
0 | data/frameworks.md | # Neural Network Frameworks\n\nAs we have lear... | those computations on GPUs is very important. ... |
0 | data/frameworks.md | # Neural Network Frameworks\n\nAs we have lear... | API, there is also higher-level API, called Ke... |
Converting out text to embeddings, and storing them in our database in chunks
openai.api_type = "azure"
openai.api_key = os.getenv("AZURE_OPENAI_KEY")
openai.api_base = os.getenv("AZURE_OPENAI_ENDPOINT")
openai.api_version = "2023-07-01-preview"
from openai import OpenAI
client = OpenAI(api_key=os.getenv("AZURE_OPENAI_EMBEDDINGS_DEPLOYMENT"))
def create_embeddings(text, model="text-embedding-ada-002-2"):
# Create embeddings for each document chunk
embeddings = openai.embeddings.create(input = text, model=model).data[0].embedding
return embeddings
#embeddings for the first chunk
create_embeddings(flattened_df['chunks'][0])
[-0.016977494582533836, 0.0028917337767779827, 0.025520483031868935, -0.03886381536722183, 0.006847951095551252, 0.003939266782253981, -0.006163155660033226, -0.0032409115228801966, -0.002920549362897873, -0.029344486072659492, 0.034931328147649765, 0.020408250391483307, 0.0015382464043796062, 0.003086663084104657, -0.014618001878261566, -0.010983842425048351, 0.02225244976580143, 0.009017598815262318, -0.02931736595928669, -0.02063877508044243, -0.03550086170434952, -0.003715521888807416, 0.01288906391710043, -0.034226194024086, -0.030429311096668243, -0.0014907853910699487, 0.015296016819775105, -0.04358280077576637, -0.007553086616098881, -0.014156951569020748, 0.01970311440527439, 0.01257039699703455, -0.012665319256484509, -0.015553662553429604, -0.004668132867664099, 0.011058423668146133, 0.0012356822844594717, 0.00818364042788744, -0.0005224952474236488, -0.00196624337695539, 0.04032832756638527, 0.011255048215389252, -0.009871897287666798, -0.00762766832485795, -0.0052071548998355865, 0.010685515590012074, -0.02524927631020546, -0.03335833549499512, -0.006258077919483185, 0.004135891329497099, 0.013024667277932167, 0.02397460862994194, -0.044043850153684616, -0.03303288668394089, -0.02108626440167427, 0.012129687704145908, -0.026347661390900612, 0.012760241515934467, 0.0245983824133873, -0.025845929980278015, 0.0023594920057803392, 0.019825156778097153, -0.021316789090633392, 0.003123953938484192, -0.0074107032269239426, -0.019499709829688072, -0.0014772251015529037, 0.025764567777514458, 0.003351088846102357, -0.016421521082520485, 0.0035663587041199207, 0.013248411938548088, -0.02557472325861454, 0.00017797891632653773, 0.015323137864470482, 0.00425115367397666, -0.013668781146407127, 0.0017543636495247483, -0.01627235859632492, 0.002678158925846219, 0.002840882632881403, -0.03026658669114113, -0.01352639775723219, 0.0014560370473191142, 0.0004065970715600997, -0.00403757905587554, 0.012068665586411953, 0.009912578389048576, 0.008475187234580517, -0.0051529137417674065, 0.04401673004031181, -0.0017255480634048581, 0.025127233937382698, 0.008570108562707901, 0.0071259369142353535, 0.010773657821118832, -0.012665319256484509, 0.006230957340449095, -0.004396927077323198, -0.010000720620155334, -0.012482254765927792, 0.017926715314388275, -0.014767165295779705, -0.01936410740017891, -0.02236093208193779, 0.0006835238309577107, 0.00395960733294487, 0.0005110537749715149, 0.010224465280771255, -0.001116182073019445, 0.019025098532438278, 0.02257789671421051, -0.009892238304018974, -0.024476340040564537, -0.01257039699703455, -0.009932918474078178, 0.04116906598210335, -0.008475187234580517, -0.007932774722576141, -0.016231678426265717, 0.012434793636202812, 0.024110211059451103, 0.03720945864915848, -0.006383510772138834, 0.01756058633327484, -0.0012060190783813596, 0.027147717773914337, 0.0016255407826974988, -0.018062317743897438, -0.02481534704566002, -0.01177711971104145, 0.008698931895196438, 0.0028052867855876684, 0.021330349147319794, -0.01547230128198862, 0.00404096907004714, 0.015187534503638744, 0.010502451099455357, -0.03102596290409565, 0.005342757795006037, 0.01156015507876873, 0.007471724878996611, -0.027147717773914337, -0.013119589537382126, -0.014943449757993221, 0.03693825379014015, 0.03061915561556816, 0.02716127783060074, 0.013858625665307045, -0.009919358417391777, -0.008380264975130558, -0.010814337991178036, -0.013770483434200287, -0.02021840587258339, 0.006678447127342224, 0.0002608238719403744, -0.00422403309494257, 0.03384650498628616, -0.011688977479934692, 0.014997690916061401, 0.017411423847079277, 0.01284160278737545, -0.01692325249314308, -0.0025781518779695034, 0.01593335159122944, 0.012333091348409653, 0.04537275806069374, -0.0018357255030423403, 0.02419157326221466, -0.0015789272729307413, 0.013817944563925266, -0.0016721542924642563, -0.005529211834073067, 0.013865405693650246, 0.02066589519381523, 0.0075869872234761715, 0.027459604665637016, 0.005525821819901466, -0.03447027876973152, -0.014767165295779705, 0.018008077517151833, 0.018455566838383675, 0.03029370680451393, 0.01181780081242323, -0.0005953818908892572, -0.012868723832070827, 0.023798324167728424, -0.009810876101255417, 0.00454948004335165, -0.03276168182492256, -0.011255048215389252, 0.005078332033008337, -0.0027985067572444677, 0.005902119912207127, -0.6274621486663818, -0.0018628460820764303, 0.03704673796892166, -0.03390074893832207, -0.0060411132872104645, -0.013431476429104805, -0.013180610723793507, 0.005593623500317335, -0.0088345343247056, 0.034741487354040146, -0.0027188400272279978, 0.012482254765927792, 0.0006004669703543186, -0.01692325249314308, 0.010000720620155334, -0.022442294284701347, 0.009180322289466858, -0.03395498916506767, -0.015553662553429604, 0.0008771818247623742, -0.008631129749119282, 0.0235542394220829, -0.021113384515047073, 0.020516732707619667, 0.0024442437570542097, 0.013390795327723026, -0.0029832657892256975, 0.003837564494460821, 0.023594919592142105, 0.029154643416404724, -0.014278994873166084, 0.005786857567727566, 0.014278994873166084, 8.54934478411451e-05, 0.040626656264066696, -0.008861655369400978, -0.019092900678515434, 0.03780611231923103, 0.009654932655394077, 0.03501269221305847, -0.030049622058868408, -0.013953547924757004, 0.02526283636689186, 0.011214367114007473, -0.009804096072912216, 0.02996825985610485, 0.011960183270275593, 0.00473254406824708, 0.004854586906731129, -0.013011106289923191, 0.009105741046369076, 0.00035447467234916985, 0.012536495923995972, 0.023377954959869385, 0.004366416018456221, -0.0022798252757638693, 0.006766588892787695, -0.02237449400126934, 0.006749638821929693, 0.005980091635137796, 0.010732976719737053, -0.008705711923539639, -0.04935948923230171, -0.013329774141311646, -0.018916616216301918, 0.007037795148789883, -0.021791400387883186, 0.029073281213641167, -0.02280842326581478, -0.010895700193941593, 0.019743794575333595, 0.02484246715903282, 0.019526829943060875, 0.006383510772138834, 0.0073564620688557625, 0.02203548513352871, 0.016340160742402077, -0.003174804849550128, 0.0022137188352644444, 0.011092324741184711, 0.002408648142591119, 0.003939266782253981, -0.018903056159615517, -0.014197632670402527, 0.005871609319001436, 0.00835314393043518, -0.016448643058538437, -0.007946334779262543, 0.007593767251819372, 4.547467324300669e-05, 0.007437823805958033, 0.02267281897366047, -0.01722157932817936, -0.06964569538831711, -0.00041549603338353336, 0.010760096833109856, 0.00765478890389204, 0.013302653096616268, 0.01776399090886116, -0.01295008510351181, -0.008861655369400978, -0.006037723273038864, 0.02130322903394699, -0.00401723850518465, -0.010461770929396152, 0.016855452209711075, -0.014414597302675247, 0.04699999466538429, 0.03219214826822281, -0.025615405291318893, -0.03145989403128624, -0.027676569297909737, -0.010651614516973495, 0.02246941439807415, 0.0001386752410326153, -0.030998842790722847, -0.008149739354848862, 0.00818364042788744, -0.008149739354848862, -0.019214943051338196, 0.00904471892863512, 0.013451816514134407, -0.006810660008341074, -0.0005280041368678212, 0.018048757687211037, 0.006268247961997986, -0.03102596290409565, -0.018225042149424553, -0.02687651291489601, -0.012265290133655071, -0.003701961599290371, -0.02280842326581478, 0.0007165770512074232, -0.018048757687211037, 0.02610357478260994, 0.010699075646698475, 0.01753346621990204, -0.021465953439474106, 0.0011017742799594998, -0.033656660467386246, -0.0016780869336798787, -0.02108626440167427, 0.024435658007860184, -0.02149307355284691, -0.015051932074129581, 0.005488530732691288, -0.018130119889974594, -0.0056444741785526276, 0.00861078966408968, 0.003969777375459671, 0.0012085615890100598, 0.010360068641602993, -4.751401502289809e-05, 0.0037867133505642414, 0.01636728085577488, -0.01992007903754711, -0.017709750682115555, -0.034280434250831604, -0.004712203983217478, -0.03346681594848633, -0.027459604665637016, 0.028612229973077774, -0.029019039124250412, 0.01798095554113388, -0.025656085461378098, -0.028313903138041496, -0.019621752202510834, 0.004630842246115208, 0.004786785691976547, -0.02428649552166462, -0.013085688464343548, -0.03908077999949455, -0.0011017742799594998, 0.014794286340475082, 0.010244805365800858, 0.006590305361896753, -0.011078763753175735, -0.01616387628018856, 0.016950374469161034, -0.018482686951756477, 0.007302220910787582, -0.0160553939640522, -0.0256967656314373, -0.010007500648498535, 0.03655856475234032, -0.006583524867892265, 0.009865117259323597, 0.0012543275952339172, -0.046376220881938934, -0.013451816514134407, -0.005413949489593506, 0.0246119424700737, -0.02858510985970497, 0.010102422907948494, -0.012116126716136932, 0.00023794086882844567, -0.0025815418921411037, 0.019540389999747276, -0.021872762590646744, 0.006773369386792183, 0.0028764784801751375, -0.015228215605020523, 0.01257717702537775, -0.019865836948156357, 0.012767021544277668, 0.002637478057295084, 0.019621752202510834, -0.026184936985373497, -0.016109634190797806, 0.002761215902864933, 0.006319099105894566, -0.016177436336874962, -0.009837997145950794, -0.013675561174750328, -0.017492786049842834, 0.03200230374932289, 0.02085573971271515, 0.0071259369142353535, -0.007844632491469383, -0.006786929443478584, -0.012556836940348148, -0.005000360310077667, 0.02484246715903282, -0.004864757414907217, -0.0030307266861200333, 0.021045584231615067, -0.015770627185702324, 0.009187102317810059, -0.011695757508277893, -0.04835602641105652, -0.0017933495109900832, 0.0181843601167202, -0.0021594776771962643, 0.014224753715097904, 0.028341025114059448, 0.0029120740946382284, 0.0034273655619472265, 0.001641643699258566, 0.06405885517597198, -0.0035866990219801664, -0.00039642685442231596, 0.009431187994778156, 0.010109202936291695, -0.01347893662750721, 0.01841488666832447, 0.01363488007336855, 0.04762376844882965, 0.014767165295779705, -0.0181843601167202, -0.012082226574420929, -0.009648152627050877, 0.002545946044847369, -0.00409182021394372, 0.013445036485791206, 0.007166618015617132, -0.015214655548334122, 0.009010818786919117, 0.0176419485360384, 0.015906229615211487, 0.025167914107441902, 0.017248699441552162, 0.006454702466726303, 0.0020103142596781254, -0.024462779983878136, -0.003459571162238717, -0.006383510772138834, 0.013804384507238865, -0.014306114986538887, -0.016014713793992996, -0.0036002593114972115, -0.013289093039929867, -0.020150603726506233, 0.012753461487591267, -0.018062317743897438, -0.00012998818419873714, 0.014170512557029724, -0.003539237892255187, 0.007695469539612532, -0.004685083404183388, 0.01594691164791584, -0.011214367114007473, -0.009492209181189537, 0.01316704973578453, 0.0181843601167202, 0.004952899180352688, -0.014170512557029724, -0.00808193814009428, 0.004498629365116358, 0.003993507940322161, -0.0069225323386490345, 0.006756418850272894, -0.005993652157485485, -0.011302509345114231, -0.008326023817062378, 0.0026866341941058636, -0.0004135891213081777, 0.029724175110459328, -0.009973599575459957, 0.008481967262923717, -0.027418924495577812, 0.03400922939181328, 0.010699075646698475, -0.011160125955939293, -0.015038371086120605, 0.036856893450021744, 0.011322849430143833, -0.023486437276005745, -0.009966819547116756, 0.0224829763174057, -0.026930753141641617, 0.0088277542963624, -0.00797345582395792, 0.012394113466143608, 0.005105452612042427, 0.018021637573838234, -0.011078763753175735, 0.009722733870148659, 0.005488530732691288, 0.008414165116846561, 0.014360356144607067, 0.01193306315690279, -0.013811164535582066, -0.016435083001852036, 0.019282745197415352, 0.03219214826822281, 0.02503231167793274, -0.020096363499760628, 0.016353720799088478, -0.02173715829849243, -0.01182458084076643, -0.017723310738801956, -0.025018751621246338, 0.01830640435218811, -0.009688833728432655, 0.009709173813462257, 0.009526110254228115, 0.015051932074129581, -0.0256967656314373, 0.017397863790392876, 0.029073281213641167, -0.007648008409887552, -0.0015696046175435185, 0.004454558249562979, -0.002530690748244524, 0.019187822937965393, 0.009546450339257717, 0.014251873828470707, -0.002032349817454815, 0.004807125777006149, 0.014468838460743427, 0.00032269273651763797, 0.025317078456282616, -0.00904471892863512, -0.023472877219319344, -0.02737824246287346, 0.01583842933177948, 0.010163444094359875, 0.018875936046242714, -0.029588572680950165, 0.04868147149682045, 0.0187132116407156, 0.036965373903512955, 0.006268247961997986, -0.007275100331753492, 0.014156951569020748, 0.00866503082215786, -0.0016840195748955011, -0.002395087853074074, -0.019757354632019997, 0.00812939926981926, 0.00839382503181696, 0.00892945658415556, -0.0028256273362785578, -0.0058377087116241455, 0.013519617728888988, -0.006390290800482035, -0.054431039839982986, -0.003501947270706296, 0.000861078966408968, 0.006871681660413742, 0.01776399090886116, -0.0035934792831540108, 0.015228215605020523, -0.04407097026705742, -0.019282745197415352, 0.0010585507843643427, 0.017682630568742752, 0.004969849716871977, 0.028530869632959366, 0.005529211834073067, -0.0023357614409178495, 0.012061885558068752, -0.01337045431137085, -0.003230741247534752, -0.029914019629359245, -0.017492786049842834, -0.037073858082294464, 0.008590449579060078, 0.032490476965904236, 0.02782573364675045, 0.011275388300418854, 0.0011890686582773924, -0.016652047634124756, 0.0071801780723035336, -0.0006750486209057271, -0.03167685866355896, -0.017099536955356598, -0.02899191901087761, 0.0090921800583601, -0.017804672941565514, 0.003298542695119977, -0.02397460862994194, 0.005308857187628746, 0.006675057113170624, 0.014699364081025124, -0.02610357478260994, -0.003820614190772176, 0.005081722047179937, 0.01616387628018856, 0.03978591784834862, 0.014902768656611443, -0.00016251170018222183, 0.020299768075346947, -0.015879109501838684, -0.00452235946431756, 0.0053936089389026165, 8.464592974632978e-05, -0.03403634950518608, 0.013845064677298069, -0.014590881764888763, 0.016407961025834084, 0.013695902191102505, 0.0025408610235899687, -0.016014713793992996, 0.03723657876253128, 0.014807846397161484, 0.029832657426595688, 0.0077836113050580025, 0.03767051175236702, 0.00430539483204484, 0.006295368541032076, 0.01722157932817936, -0.0007818359881639481, 0.007573426701128483, 0.010400748811662197, 0.0006148748216219246, 0.04271494224667549, 0.003220570972189307, 0.005502091255038977, -0.0003678231150843203, -0.0014984130393713713, -0.029832657426595688, -0.014455278404057026, 0.02001500129699707, 0.010319387540221214, 0.044667623937129974, -0.011343189515173435, -0.022103287279605865, -0.02759520895779133, -0.0012000864371657372, -0.03268032148480415, 0.013939986936748028, -0.0010424479842185974, -0.02227957174181938, 0.02344575710594654, 0.007275100331753492, 0.012129687704145908, -0.022754181176424026, 0.009498989209532738, -0.03720945864915848, -0.0021035412792116404, -0.0025103504303842783, 0.00785819347947836, 0.04184708371758461, -0.02610357478260994, 0.012767021544277668, -0.04304038733243942, -0.007051355205476284, -0.015540102496743202, -0.004112160764634609, 0.0008047189912758768, -0.02097778208553791, 0.026062894612550735, 0.05112232640385628, 0.03693825379014015, -0.002800201764330268, 0.003125648945569992, 0.02172359824180603, -0.0032765071373432875, 0.002986655803397298, 0.02000144124031067, -0.0015950301894918084, 0.008373484946787357, -0.0042579337023198605, 0.0010695685632526875, -0.01743854396045208, 0.016977494582533836, 0.0077836113050580025, 0.02653750404715538, -0.0007441213820129633, -0.0007928537088446319, -0.009180322289466858, -0.005434289574623108, -0.03384650498628616, -0.0024018678814172745, 0.039731673896312714, -0.005613963585346937, 0.03452451899647713, -0.022618578746914864, 0.004871537443250418, 0.010346507653594017, 0.021126946434378624, 0.009370166808366776, -0.002212023828178644, 0.02032688818871975, 0.011702537536621094, -0.007444603834301233, 0.027988456189632416, 0.00454948004335165, -0.02386612631380558, -0.028286783024668694, -0.034741487354040146, -0.026157816872000694, 0.01831996440887451, 0.0069225323386490345, 0.011119444854557514, 0.02331015281379223, 0.017208019271492958, -0.022727061063051224, -0.004590161144733429, -0.02363560162484646, -0.014889207668602467, -0.014414597302675247, -0.020313328132033348, -0.03048355132341385, -0.03102596290409565, -0.010326167568564415, 0.0018391155172139406, 0.004125720821321011, 0.00417318195104599, -0.02097778208553791, 0.005478360690176487, -0.029127521440386772, -0.009105741046369076, 0.01734362170100212, -0.014902768656611443, 0.03989439830183983, -0.019621752202510834, 0.023296592757105827, 0.014821406453847885, 0.0052003744058310986, -0.010916040278971195, -0.00861756969243288, 0.00866503082215786, -0.0016263882862403989, 0.029669933021068573, 0.00823788158595562, -0.023283032700419426, -0.016950374469161034, 0.0025137404445558786, -3.151710188831203e-05, 0.01257717702537775, -0.020408250391483307, 0.025967972353100777, 0.005217324942350388, 0.003166329814121127, 0.0023103358689695597, -0.010407529771327972, -0.02063877508044243, 0.03799595683813095, -0.02214396744966507, -0.007824292406439781, -0.02066589519381523, -0.034605883061885834, -0.018482686951756477, 0.011146565899252892, -0.013458596542477608, 0.031514134258031845, 0.014428158290684223, 0.003868075320497155, -0.0015721471281722188, -0.0024476340040564537, -0.0035222875885665417, 0.004373196512460709, 0.000404054531827569, 0.03273456171154976, -0.0020391298457980156, 0.02107270434498787, 0.02206260710954666, -0.009485429152846336, -0.013350114226341248, 0.0005991957150399685, 0.008163300342857838, 0.037182338535785675, -0.033656660467386246, -0.010746536776423454, 0.011160125955939293, -0.010448209941387177, 0.01283482275903225, -0.008326023817062378, -0.003052762243896723, -0.016231678426265717, -0.013031447306275368, -0.0080344770103693, 0.02439497783780098, 0.011811019852757454, -0.01648932322859764, 0.0065123336389660835, 0.008536208420991898, -0.009471869096159935, -0.013953547924757004, -0.01198052428662777, 0.005041040945798159, -0.023825444281101227, -0.030022501945495605, 0.018808133900165558, -0.005390218924731016, 0.0018086048075929284, -0.006983553990721703, -0.017357181757688522, 0.008109058253467083, 0.03468724340200424, -0.015187534503638744, 0.01777755096554756, 0.014658682979643345, 0.00888199545443058, -0.01667916774749756, 0.02162867598235607, -0.020923541858792305, -0.027486726641654968, 0.011282168328762054, -0.03710097819566727, -0.01198730431497097, -0.007146277464926243, 0.0024306834675371647, -0.0005890254979021847, 0.006305539049208164, -0.015282456763088703, -0.01272634044289589, 0.017913155257701874, 0.01916070282459259, -0.006664887070655823, 0.014794286340475082, 0.005559722427278757, 0.00840738508850336, -0.01187204197049141, 0.018686091527342796, -0.03517541661858559, -0.0004763054894283414, 0.0028764784801751375, -0.013885745778679848, 8.284494833787903e-05, -0.016841890290379524, 0.012109346687793732, -0.019987881183624268, 0.008142959326505661, -0.005247835535556078, 0.012339872308075428, 0.005532601848244667, 0.004237593617290258, -0.002756130648776889, 0.009756634943187237, 0.009119301103055477, -0.001601810334250331, -0.0064953831024467945, 0.001803519786335528, 0.014631562866270542, 0.005241055507212877, -0.030130984261631966, -0.028747834265232086, -0.005095282103866339, -0.015974031761288643, -0.03246335685253143, 0.003539237892255187, -0.013200950808823109, 0.048003457486629486, 0.03018522448837757, 0.000754715409129858, -0.004179961979389191, -0.011200807057321072, -0.030022501945495605, -0.00866503082215786, 0.0003540509205777198, 0.021221866831183434, -0.0010254975641146302, 0.03091748058795929, -0.00446811830624938, 0.01593335159122944, -0.008475187234580517, 0.017140217125415802, 0.009580351412296295, 0.006688617169857025, -0.017723310738801956, 0.0064580924808979034, -0.014889207668602467, -0.015011250972747803, -0.020177723839879036, -0.015079052187502384, 0.03368378058075905, -0.0240695308893919, -0.017302941530942917, 0.02288978360593319, 0.003015471389517188, -0.007241199724376202, -0.00395960733294487, 0.011200807057321072, 0.0027544356416910887, -0.004240983631461859, 0.019947199150919914, -0.01733006164431572, -0.015173974446952343, 0.0013984058750793338, -0.011329629458487034, -0.010109202936291695, -0.00023243199393618852, 0.002318811137229204, 0.0009899018332362175, 0.010217685252428055, -0.007064915727823973, 0.0009237953345291317, -0.003300237702205777, -0.015350257977843285, 0.021465953439474106, 0.011410991661250591, 0.01849624700844288, 0.02793421596288681, 0.01242123357951641, 0.015065492130815983, -0.016543565317988396, -0.021004902198910713, -0.0176690686494112, 0.018997978419065475, 0.026727348566055298, -0.026090014725923538, -0.023296592757105827, 0.002742570359259844, 0.022605018690228462, -0.03091748058795929, -0.03186670318245888, 0.006593695376068354, 0.009756634943187237, -0.0171266570687294, -0.007648008409887552, -0.008631129749119282, -0.022333811968564987, 0.011478792876005173, -0.011797459796071053, 0.013594199903309345, -0.015567222610116005, -0.02034044824540615, 0.02759520895779133, -0.0022357541602104902, -0.009892238304018974, 0.0012729730224236846, 0.0036951813381165266, -0.017682630568742752, -0.014753605239093304, 0.03159549459815025, -0.02291690558195114, -0.006356390193104744, 0.1991736739873886, -0.023377954959869385, 0.008922676555812359, -0.006756418850272894, 0.010271926410496235, -0.007193738594651222, 0.013289093039929867, -0.006769979372620583, -0.0004133772454224527, 0.005030870903283358, -0.005139353219419718, 0.010021060705184937, -0.035799190402030945, -0.0028493579011410475, 0.005705495830625296, -0.021547315642237663, -0.03669416904449463, -0.010380408726632595, 0.00034536386374384165, 0.011200807057321072, 0.027134157717227936, 0.010651614516973495, -0.004630842246115208, -0.03864685073494911, 0.029263125732541084, -0.0010678735561668873, -0.010800777934491634, 0.019350547343492508, 0.023676281794905663, 0.0035460181534290314, -0.019879398867487907, 0.011919503100216389, -0.007905654609203339, 0.009180322289466858, -0.03170397877693176, -0.004817296285182238, 0.04518291726708412, -0.0071327174082398415, -0.010793997906148434, -0.00925490353256464, 0.01209578663110733, 0.004190132487565279, -0.020286206156015396, 0.00026993470964953303, 0.0018560659373179078, 0.009492209181189537, ...]
cat = create_embeddings("cat")
cat
[-0.0070945825427770615, -0.017328109592199326, -0.009644086472690105, -0.03070768155157566, -0.012548675760626793, 0.003105211304500699, -0.005113212391734123, -0.04121817275881767, -0.014629469253122807, -0.021376069635152817, 0.019231360405683517, 0.05087646469473839, -0.0012907310156151652, 0.0024855893570929766, -0.03840590640902519, -0.006089693866670132, 0.0355084203183651, -0.004697763826698065, 0.0023630852811038494, -0.01342928409576416, -0.01891888678073883, 0.009019138291478157, 0.015893569216132164, -0.008713766001164913, -0.014672079123556614, 0.007233065087348223, 0.013031589798629284, -0.013365369290113449, 0.002858427818864584, 0.004861102905124426, 0.0040266546420753, -0.01677417755126953, -0.015850959345698357, -0.04306461289525032, -0.027242060750722885, -0.004278764594346285, 0.0080533092841506, -0.009984967298805714, 0.022015219554305077, -0.009040444158017635, 0.004900162108242512, 0.00031890999525785446, -0.012221998535096645, 0.013038692064583302, -0.0038775193970650434, 0.0070661758072674274, -0.022185660898685455, -0.004410145804286003, 0.0013573094038292766, 0.013912199065089226, 0.002606318099424243, 0.008266360498964787, -0.01138399913907051, 0.0103471539914608, -0.005084805656224489, 0.0029045888222754, 0.007960988208651543, -0.012697811238467693, 0.013265945948660374, 0.0023417803458869457, 0.015865162014961243, 0.004239705391228199, -0.0018144802888855338, 0.022753795608878136, 0.011163847520947456, -0.003371524391695857, -0.007265022955834866, 0.00042521333671174943, -0.004175790119916201, 0.005191330797970295, 0.03238368034362793, 0.028080059215426445, 0.023634403944015503, -0.005677796434611082, -0.00954466313123703, -0.0072082094848155975, -0.00857173278927803, 0.011312982998788357, -0.0005739048356190324, -0.005237491801381111, 0.03587770834565163, -0.03255411982536316, -0.016461703926324844, 0.0057701184414327145, 0.019742680713534355, 0.006501591764390469, -0.009374222718179226, 0.009580171667039394, -0.01024772971868515, 0.010574407875537872, 0.021049391478300095, 0.026375655084848404, -0.012399540282785892, 0.037553705275058746, -0.010375560261309147, 0.019572241231799126, -0.01681678742170334, 0.02505474165081978, -0.0068637775257229805, -0.059824585914611816, 0.005819830112159252, 0.005251695401966572, -0.04292257875204086, -0.007755038794130087, -0.0037248332519084215, -0.009097257629036903, 0.01852119155228138, 0.0009285451960749924, 0.017455939203500748, -0.0026471526362001896, -0.007506479974836111, 0.05746682733297348, 0.011909523978829384, -0.018208717927336693, 0.005986719857901335, -0.005255246069282293, -0.004868204239755869, -0.024372979998588562, -0.0060648382641375065, -0.015950381755828857, 0.010943694971501827, 0.00939552765339613, 0.039030853658914566, 0.007392853032797575, 0.018847869709134102, 0.019032513722777367, -0.00791837740689516, 0.013720453716814518, -0.013564216904342175, 0.017186075448989868, 0.02900327742099762, 0.0006746599683538079, 0.013912199065089226, 0.009878442622721195, 0.0008570844656787813, 0.0276255514472723, -0.04161586984992027, -0.0026933136396110058, -0.004722619894891977, -0.06277889013290405, -0.002331127878278494, 0.019330784678459167, -0.019600648432970047, 0.015652110800147057, -0.010759050957858562, 0.02367701381444931, 0.024799080565571785, 0.003817155258730054, 0.012101269327104092, 0.0021997466683387756, 0.005184229463338852, -0.009168273769319057, 0.02722785621881485, -0.017768412828445435, -0.007399954833090305, 0.030253173783421516, 0.003541964804753661, 0.014828315936028957, -0.0021198526956140995, -0.020182985812425613, -0.00025677026133053005, -0.004807840101420879, 0.016802584752440453, -0.014331198297441006, 0.005699101369827986, 0.027000602334737778, 0.020807934924960136, 0.004374637268483639, -0.013734657317399979, 0.004829145036637783, -0.019643258303403854, 0.02300945669412613, -0.00685667572543025, 0.0072366162203252316, -0.0037638924550265074, 0.00927479937672615, -0.0009099032613448799, -0.005194881930947304, -0.01339377649128437, -0.02705741673707962, -0.013642335310578346, 0.011064423248171806, 0.01562370453029871, 0.03269615396857262, 0.0009871340589597821, 0.004992483649402857, 0.02394687943160534, -0.007968089543282986, -0.009175376035273075, -0.004573484417051077, 0.005535762757062912, 0.02685856819152832, 0.020381832495331764, -0.023392947390675545, -0.6567637324333191, -0.024131521582603455, -0.009331612847745419, -0.012939268723130226, 0.012555777095258236, 0.024088911712169647, 0.0021163017954677343, 0.0026755593717098236, 0.006476735696196556, -0.014615265652537346, -0.016788380220532417, 0.009033341892063618, 0.003275651717558503, -0.010411068797111511, -0.01095079630613327, -0.0031939824111759663, -0.0044243489392101765, -0.01864902302622795, -0.01822292059659958, 0.023321930319070816, -0.0021961957681924105, 0.0052730003371834755, 0.0018890479113906622, -0.013003183528780937, 0.004651602823287249, -0.00982873048633337, 0.006870879326015711, -0.03295181319117546, 0.025097351521253586, 0.015311230905354023, -0.012236201204359531, 0.03053724206984043, -0.005425686482340097, -0.013571318238973618, 0.04672908037900925, 0.022824812680482864, -7.094748980307486e-06, 0.02715683914721012, 0.015112383291125298, 0.04062163084745407, -0.018265530467033386, -0.02005515620112419, 0.016759974882006645, 0.0025814620312303305, -0.02538141794502735, -0.012094167992472649, -0.0009125663782469928, -0.0005219737649895251, 0.010936593636870384, -0.005628084763884544, 0.0163054671138525, -0.0072934296913445, 0.0019476368324831128, -0.007364446297287941, 0.00833737663924694, 0.0045095691457390785, 0.024756470695137978, -0.02384745515882969, 0.003002236830070615, 0.012988979928195477, -0.0034531939309090376, 0.005280102137476206, -0.008188242092728615, -0.020268205553293228, -0.016234450042247772, 0.007204658351838589, -0.01533963717520237, -0.003845561994239688, 0.023762235417962074, 0.01095079630613327, 0.00572750810533762, 0.005745262373238802, -0.034741438925266266, 0.003944985568523407, 0.0037816467229276896, 0.022143051028251648, 0.008713766001164913, -0.012818539515137672, -0.0010750173823907971, -0.01190242264419794, -0.007648513652384281, 0.004133180249482393, -0.026205213740468025, -0.008110122755169868, 0.01573733240365982, -0.011731982231140137, -0.02123403549194336, -0.0013493199367076159, 0.01423177495598793, 0.011391101405024529, 0.007165599148720503, 0.024358775466680527, -0.017399126663804054, 0.014274384826421738, -0.009168273769319057, 0.009466544725000858, -0.006313397083431482, 0.0036538164131343365, 0.010588610544800758, -0.03812183812260628, -0.007960988208651543, -0.004964076913893223, 0.006522896699607372, -0.006746599916368723, 0.022214068099856377, 0.023819047957658768, -0.014757299795746803, 0.018663225695490837, 0.036587875336408615, -0.02153230644762516, 0.005365322344005108, -0.00474747596308589, -0.010027578100562096, 0.00015490548685193062, 0.013926402665674686, -0.03150307014584541, 0.012285913340747356, 0.004761679098010063, 0.018776852637529373, -0.022895829752087593, -0.010283238254487514, 0.02083634026348591, 0.013017387129366398, -0.008479410782456398, 0.003817155258730054, 0.0031318427063524723, -0.01674577035009861, 0.0011069750180467963, -0.005986719857901335, -0.0021997466683387756, 0.008401292376220226, -0.020353427156805992, 0.014558452181518078, -0.016191840171813965, 0.003360871924087405, 0.002217500936239958, 0.02505474165081978, 0.016064008697867393, 0.018407564610242844, -0.004495366010814905, -0.025466639548540115, -0.0004334246623329818, 0.010702237486839294, 0.006455430760979652, 0.018265530467033386, 0.002895711688324809, -0.006785659119486809, -0.024358775466680527, 0.0024127971846610308, 0.009573070332407951, -0.014885129407048225, -0.010695136152207851, 0.02759714424610138, 0.01644749939441681, 0.03465621918439865, -0.02239871211349964, -0.010091492906212807, -0.015424857847392559, -0.019245563074946404, -0.008181139826774597, 0.00573460990563035, 0.03420171141624451, -0.004296518862247467, -0.013692046515643597, -0.017100855708122253, -0.023250913247466087, 0.009480748325586319, 0.03309384733438492, -0.02535301260650158, -0.03329269587993622, -0.004612543620169163, -0.021546509116888046, -0.005713304970413446, 0.022029424086213112, 0.007932581007480621, 0.004385289736092091, 0.008685359731316566, -0.02782439813017845, 0.008216648362576962, 0.0034958040341734886, 0.02940097264945507, -0.0048540011048316956, -0.011660965159535408, -0.006508693564683199, 0.0010510492138564587, 0.016490111127495766, 0.03442896530032158, 0.01832234486937523, -0.018606411293148994, 0.01637648418545723, -0.017356514930725098, 0.0060932449996471405, -0.0009014700190164149, 0.011064423248171806, 0.0009853586088865995, -0.011014712043106556, 0.0055677201598882675, 0.022412914782762527, 0.017796820029616356, 0.021787965670228004, -0.0006249481812119484, 0.013166522607207298, 0.010503390803933144, -0.0024465301539748907, 0.019685868173837662, -0.036048147827386856, -0.013834080658853054, -0.00813852995634079, 0.03746848553419113, 0.025977959856390953, -0.00014170078793540597, -0.00833737663924694, -0.016234450042247772, -0.01257708203047514, 0.007336039561778307, 0.028491957113146782, -0.010453678667545319, -0.002373737981542945, -0.009225087240338326, 0.0002352432784391567, -0.007456768304109573, -0.003309384686872363, -0.005812728311866522, 0.01995573192834854, 0.006270787212997675, 0.011597050353884697, 0.020850544795393944, 0.0359061136841774, 0.004040858242660761, -0.026631314307451248, -0.02468545362353325, 0.0003808278124779463, 0.009622781537473202, 0.010943694971501827, 0.004513120278716087, -0.001350207719951868, 0.027668161317706108, -0.020268205553293228, 0.03363357484340668, 0.01309550553560257, 0.0001785407803254202, 0.025168368592858315, 0.014182062819600105, -0.024429792538285255, 0.011802999302744865, -0.003314710920676589, 0.023733828216791153, 0.015453264117240906, -0.0037958500906825066, 0.015183400362730026, -0.013372470624744892, 0.004861102905124426, -0.018237125128507614, 0.018734242767095566, 0.00446340860798955, -0.015921976417303085, 0.016830991953611374, 0.0065406509675085545, 0.027043212205171585, 0.03150307014584541, 0.02283901534974575, -0.0006870879442431033, 0.0042929681949317455, 0.0004001354973297566, 0.010474983602762222, 0.018364954739809036, 0.01975688524544239, -0.016319669783115387, 0.01563790813088417, 0.005848236847668886, -0.012712014839053154, -0.009416832588613033, 0.010780355893075466, -0.017668990418314934, 0.013152319006621838, 0.012207794934511185, -0.0007913939189165831, -0.0056600421667099, 0.0232367105782032, -0.0035526175051927567, -0.018066683784127235, -0.05124575272202492, 0.027682363986968994, -0.004662255756556988, -0.00870666466653347, -0.0017807473195716739, -0.04116136208176613, -0.017058245837688446, -0.0021145264618098736, 0.011724879965186119, 0.00024434231454506516, 0.01342928409576416, 0.022256677970290184, 0.01918875053524971, 0.013564216904342175, -0.0022565601393580437, 0.030224766582250595, -0.013131014071404934, 0.008948122151196003, 0.010972102172672749, 0.001673334278166294, -0.0270290095359087, -0.009459443390369415, -0.026517687365412712, 0.009722205810248852, -0.015992991626262665, -0.016064008697867393, -0.023861657828092575, -0.004545077681541443, 0.0031922070775181055, -0.019898919388651848, 0.017356514930725098, -0.023066269233822823, -0.010276136919856071, -0.014167859219014645, -0.008060411550104618, -0.03400286287069321, -0.0019582894165068865, 0.049143653362989426, -0.0012472332455217838, -0.011866914108395576, -0.012491862289607525, -0.03468462452292442, -0.01744173653423786, 0.07084640115499496, 0.008103021420538425, -0.009026240557432175, 0.01075194962322712, 0.002008001087233424, -0.019046716392040253, -0.029486192390322685, 0.0008411057060584426, 0.026872772723436356, 0.012548675760626793, -0.009715103544294834, 0.0060080247931182384, 0.009487849660217762, -0.0035100074019283056, -0.0020967721939086914, 0.017498549073934555, -0.019316580146551132, 0.0016094191232696176, 0.010460780933499336, -0.01357841957360506, 0.0022654372733086348, 0.0019068021792918444, 0.017129261046648026, 0.0030466224998235703, -0.004491815343499184, -0.005901499651372433, 0.005333364475518465, 0.03371879458427429, 0.018194515258073807, -0.02940097264945507, 0.005255246069282293, 0.018038276582956314, -0.015694722533226013, -0.0034034820273518562, 0.011788795702159405, 0.009068850427865982, -0.004729721695184708, 0.008614342659711838, 0.024600233882665634, -0.018194515258073807, 0.020949967205524445, 0.023293523117899895, -0.015921976417303085, -0.019316580146551132, 0.009942357428371906, -0.007091031409800053, 0.0012374684447422624, 0.021418679505586624, 0.011810100637376308, -0.004726170562207699, 0.03843431547284126, 0.02940097264945507, -0.007747937459498644, 0.005038644652813673, -0.016362279653549194, -0.01009859424084425, 0.014061334542930126, -0.00939552765339613, -0.002189094200730324, -0.01607821322977543, -0.008103021420538425, -0.012385336682200432, 0.012058659456670284, 0.0023488819133490324, -0.01366364024579525, -0.022895829752087593, 0.0013510953867807984, -0.022029424086213112, -0.031190596520900726, -0.013564216904342175, -0.013755962252616882, -0.016518516466021538, -0.0185495987534523, 0.007726632058620453, 0.006632972974330187, 0.023364540189504623, 0.021986814215779305, -0.023463964462280273, -0.0007123876712284982, 0.021546509116888046, -0.015396450646221638, -0.026247823610901833, 0.004612543620169163, -0.042212408035993576, -0.021844780072569847, 0.006590362638235092, -0.006867328658699989, -0.014459028840065002, -0.004935670178383589, -0.0002561044821050018, 0.019600648432970047, 0.0007816291181370616, 0.03465621918439865, -0.017597973346710205, -0.0038668669294565916, 0.013770164921879768, 0.014451926574110985, -0.009161172434687614, 0.0035827995743602514, -0.03369038924574852, 0.014118148013949394, -0.02424514852464199, -0.01323043741285801, 0.0020310815889388323, 0.01053179707378149, 0.000174435117514804, 0.019969934597611427, 0.03462781012058258, 0.002070140792056918, -0.01778261736035347, 0.009665392339229584, -0.0226401686668396, -0.009537561796605587, -0.010361356660723686, 0.01593617908656597, 0.01508397702127695, -0.022498134523630142, 0.024841690436005592, 0.024500809609889984, -0.007442564703524113, -0.02688697539269924, -0.01982790231704712, 0.01898990385234356, 0.030792901292443275, -0.011653863824903965, 0.002577911363914609, 0.0013235763181000948, 0.00800359807908535, -0.006299193948507309, 0.007541988510638475, 0.004289417061954737, 0.011980541050434113, -0.012143880128860474, -0.0460757240653038, -0.022782202810049057, -0.013258843682706356, -0.01315942034125328, 0.01024772971868515, -0.006739498116075993, -0.019785292446613312, -0.04510989785194397, 0.0060080247931182384, 0.0012880678987130523, -0.02042444236576557, -0.01859220862388611, -0.04232603684067726, -0.032838188111782074, -0.004562831949442625, 0.004640950355678797, 0.029315751045942307, -0.009622781537473202, 0.010695136152207851, -0.009175376035273075, -0.01684519462287426, -0.015751535072922707, -0.02320830337703228, -0.016632143408060074, -0.0017461265670135617, 0.03386082872748375, 0.020637493580579758, -0.0019156793132424355, 0.008884206414222717, 0.011312982998788357, -0.007478073239326477, -0.008500715717673302, 0.009182477369904518, 0.012207794934511185, 0.011270372197031975, -0.027270466089248657, 0.011526033282279968, 0.017285499721765518, -0.0038704178296029568, -0.0009977866429835558, -0.0016103069065138698, -0.022057831287384033, 0.020211393013596535, 0.0036644688807427883, -0.023080473765730858, 0.0030075632967054844, -0.007613005116581917, 0.014210470020771027, -0.0032206138130277395, 0.01583675481379032, 0.014913536608219147, 0.000739906681701541, -0.0022689879406243563, 0.01664634793996811, 0.002963177626952529, -0.008365783840417862, 0.004704865626990795, 0.014416418969631195, -0.01009859424084425, 0.010446577332913876, -0.02592114731669426, 0.014395113103091717, -0.030565647408366203, -0.016248652711510658, -0.0025086698587983847, 0.0015206481330096722, -0.013436386361718178, 0.011945032514631748, 0.03968420997262001, 0.0037283841520547867, 0.008884206414222717, 5.808955756947398e-05, -0.007218861952424049, -0.0002911690389737487, -0.01644749939441681, 0.0034176853951066732, -0.016234450042247772, -0.009381324984133244, -0.008394190110266209, -0.058347437530756, -0.026347247883677483, -0.006764354184269905, 0.0015446163015440106, -0.0016626818105578423, 0.0077124289236962795, -0.011078626848757267, -0.00813852995634079, -0.012079964391887188, 0.0025619324296712875, 0.026404060423374176, -0.026134196668863297, 0.029230531305074692, 0.02631884068250656, -0.018336547538638115, -0.00524104293435812, 0.007300531025975943, -0.015098180621862411, -0.04883117973804474, 0.008237953297793865, 0.0031797790434211493, -0.012910861521959305, 0.015566891059279442, -0.006735947448760271, 0.005116763524711132, -0.01487092673778534, -0.024600233882665634, 0.020779527723789215, 0.03215642645955086, -0.00953045953065157, -0.028989074751734734, 0.010595712810754776, -0.010865576565265656, 0.018024073913693428, -0.008500715717673302, -0.0021429331973195076, -0.0314178504049778, -0.006728845648467541, -0.018663225695490837, 0.016830991953611374, -0.018805259838700294, 0.01587936468422413, 0.007176251616328955, -0.0033679737243801355, 0.02217145822942257, 0.014025826007127762, -0.013841181993484497, -0.012562879361212254, -0.031219003722071648, 0.020111968740820885, -0.01938759721815586, 0.032298460602760315, 0.018734242767095566, 0.004211298655718565, -0.01965746097266674, 0.0011486973380669951, -0.017811022698879242, 0.03212801739573479, -0.0072934296913445, -0.010340051725506783, 0.012797234579920769, -0.022512339055538177, 0.015850959345698357, -0.01999834179878235, -0.020310815423727036, 0.002814042381942272, -0.01906091906130314, -0.04025234654545784, 0.016404889523983, 0.0075703952461481094, -0.012122574262320995, 0.0035348632372915745, -0.006590362638235092, -0.022143051028251648, -0.004047960042953491, -0.007478073239326477, -0.02173115313053131, -0.005013789050281048, -0.013173623941838741, -0.003916578833013773, 0.010013374499976635, 0.00166179402731359, 0.017470141872763634, -0.0005712417187169194, -0.0017771964194253087, 0.035451605916023254, -0.012364031746983528, 0.0245860293507576, -0.033065441995859146, 0.014572655782103539, -0.02106359414756298, -0.004736823029816151, -0.003902375465258956, 0.009672493673861027, 0.006640074774622917, -0.018677428364753723, -0.008351580239832401, -0.0009059085859917104, -0.006618769373744726, 0.0023843904491513968, -0.0020097766537219286, 0.00335732102394104, 0.0058624399825930595, 0.009736408479511738, 0.006284990347921848, -0.00897652842104435, -0.016064008697867393, 0.013826978392899036, -0.01026193331927061, 0.011021813377737999, 0.006192668341100216, -0.0017372494330629706, 0.008948122151196003, -0.01995573192834854, 0.026503484696149826, 0.012655201368033886, -0.01562370453029871, -0.013585521839559078, -0.01952963136136532, 0.00927479937672615, -0.003494028467684984, -0.035110726952552795, -0.014885129407048225, -0.03445737063884735, -0.021219830960035324, 0.02239871211349964, -0.01329435221850872, -0.010624119080603123, 0.01190242264419794, 0.005901499651372433, -0.0114692198112607, 0.003527761436998844, -0.022597558796405792, -0.024870097637176514, -0.010858475230634212, 0.008735070936381817, -0.025665486231446266, -0.006025779061019421, -0.021418679505586624, 0.0179530568420887, 0.009047545492649078, -0.040195532143116, -0.018762649968266487, 0.008905511349439621, -0.025566061958670616, -0.004484713543206453, -0.00136086018756032, 0.009423934854567051, 0.010560204274952412, -0.018393361940979958, 0.013656537979841232, 0.0003519772144500166, -0.0031069868709892035, 0.019898919388651848, -0.014842519536614418, -0.013599724508821964, 0.01898990385234356, 0.0038242568261921406, 0.024657046422362328, -0.016362279653549194, -0.01975688524544239, -0.024941114708781242, 0.01408263947814703, 0.01593617908656597, 0.0005401718663051724, 0.026262028142809868, 0.0007292541558854282, -0.014444825239479542, 0.0009214435121975839, 0.008514919318258762, 0.02401789464056492, -0.004907263442873955, 0.012122574262320995, 0.005649389699101448, -0.012917962856590748, 0.012598387897014618, -0.008067512884736061, 0.003375075291842222, -0.007826055400073528, -0.01109993178397417, -0.012761726044118404, -0.0023613099474459887, -0.012981878593564034, -0.0015952157555148005, -0.003110537538304925, -0.05516588315367699, -0.018166108056902885, 0.01985630765557289, 9.393086656928062e-05, 0.023265117779374123, -0.011085729114711285, -0.013684945181012154, -0.015779942274093628, 0.01925976760685444, -0.01647590659558773, -0.022725388407707214, 0.026162603870034218, 0.015581094659864902, 0.01958644390106201, -0.008628546260297298, -0.01239243894815445, -0.030082734301686287, -0.008948122151196003, 0.00030049000633880496, -0.006348905619233847, 0.00828766543418169, 0.0037638924550265074, 0.009161172434687614, -0.029258938506245613, 0.0019831452518701553, -0.0015490548685193062, -0.02498372457921505, 0.006853125058114529, -0.012648099102079868, 0.0017718701856210828, -0.0034017066936939955, -0.006238829344511032, 0.01952963136136532, 0.0028939361218363047, -0.0003040408482775092, -0.002572585130110383, -0.0006338253151625395, 0.01580834947526455, 0.004303620662540197, 0.18339388072490692, -0.00328985508531332, 0.002549504628404975, 0.032270051538944244, 0.007698225323110819, -0.023336132988333702, 0.03164510428905487, 0.019913122057914734, 0.00815273355692625, 0.0185495987534523, -0.005003136582672596, 0.0020967721939086914, -0.0026666822377592325, 0.008081716485321522, 0.0031975333113223314, 0.008465207181870937, -0.027909617871046066, -0.012094167992472649, -0.031900763511657715, -0.015779942274093628, 0.023151488974690437, 0.013202030211687088, -0.025665486231446266, -6.097461664467119e-05, 0.039428550750017166, 0.020268205553293228, -0.02555185928940773, -0.009551765397191048, 0.0124421501532197, 0.0035916767083108425, -0.019103530794382095, -0.009807425551116467, -0.008237953297793865, -0.009935256093740463, -0.004282315261662006, -0.011646761558949947, -0.015552688390016556, 0.022824812680482864, 0.0012667628470808268, 0.018194515258073807, -0.03556523472070694, 0.005738160572946072, -0.00924639217555523, -0.009835832752287388, -0.017228685319423676, 0.03363357484340668, ...]
# create embeddings for the whole data chunks and store them in a list
embeddings = []
for chunk in flattened_df['chunks']:
embeddings.append(create_embeddings(chunk))
# store the embeddings in the dataframe
flattened_df['embeddings'] = embeddings
flattened_df.head()
path | text | chunks | embeddings | |
---|---|---|---|---|
0 | data/frameworks.md | # Neural Network Frameworks\n\nAs we have lear... | # Neural Network Frameworks As we have learned... | [-0.016977494582533836, 0.0028917337767779827,... |
0 | data/frameworks.md | # Neural Network Frameworks\n\nAs we have lear... | descent optimization While the `numpy` library... | [-0.014787919819355011, 0.0016925617819651961,... |
0 | data/frameworks.md | # Neural Network Frameworks\n\nAs we have lear... | should give us the opportunity to compute grad... | [-0.03673850744962692, -0.02062208764255047, 0... |
0 | data/frameworks.md | # Neural Network Frameworks\n\nAs we have lear... | those computations on GPUs is very important. ... | [-0.03166744112968445, -0.011117876507341862, ... |
0 | data/frameworks.md | # Neural Network Frameworks\n\nAs we have lear... | API, there is also higher-level API, called Ke... | [-0.007904806174337864, -0.03335562348365784, ... |
Vector search and similiarity between our prompt and the database
from sklearn.neighbors import NearestNeighbors
embeddings = flattened_df['embeddings'].to_list()
# Create the search index
nbrs = NearestNeighbors(n_neighbors=5, algorithm='ball_tree').fit(embeddings)
# To query the index, you can use the kneighbors method
distances, indices = nbrs.kneighbors(embeddings)
# Store the indices and distances in the DataFrame
flattened_df['indices'] = indices.tolist()
flattened_df['distances'] = distances.tolist()
flattened_df.head()
path | text | chunks | embeddings | indices | distances | |
---|---|---|---|---|---|---|
0 | data/frameworks.md | # Neural Network Frameworks\n\nAs we have lear... | # Neural Network Frameworks As we have learned... | [-0.016977494582533836, 0.0028917337767779827,... | [0, 2, 11, 3, 1] | [0.0, 0.5220072028343841, 0.5281003720111753, ... |
0 | data/frameworks.md | # Neural Network Frameworks\n\nAs we have lear... | descent optimization While the `numpy` library... | [-0.014787919819355011, 0.0016925617819651961,... | [1, 0, 32, 2, 50] | [0.0, 0.5689486562368801, 0.5917805129945245, ... |
0 | data/frameworks.md | # Neural Network Frameworks\n\nAs we have lear... | should give us the opportunity to compute grad... | [-0.03673850744962692, -0.02062208764255047, 0... | [2, 3, 0, 5, 1] | [0.0, 0.5052294707599493, 0.5220072028343841, ... |
0 | data/frameworks.md | # Neural Network Frameworks\n\nAs we have lear... | those computations on GPUs is very important. ... | [-0.03166744112968445, -0.011117876507341862, ... | [3, 2, 0, 10, 11] | [0.0, 0.5052294707599493, 0.5456879720601056, ... |
0 | data/frameworks.md | # Neural Network Frameworks\n\nAs we have lear... | API, there is also higher-level API, called Ke... | [-0.007904806174337864, -0.03335562348365784, ... | [4, 12, 10, 9, 8] | [0.0, 0.5192304344185765, 0.5523440479637329, ... |
# Your text question
question = "what is a perceptron?"
# Convert the question to a query vector
query_vector = create_embeddings(question) # You need to define this function
# Find the most similar documents
distances, indices = nbrs.kneighbors([query_vector])
index = []
# Print the most similar documents
for i in range(3):
index = indices[0][i]
for index in indices[0]:
print(flattened_df['chunks'].iloc[index])
print(flattened_df['path'].iloc[index])
print(flattened_df['distances'].iloc[index])
else:
print(f"Index {index} not found in DataFrame")
in our model, in which case the input vector would be a vector of size N. A perceptron is a **binary classification** model, i.e. it can distinguish between two classes of input data. We will assume that for each input vector x the output of our perceptron would be either +1 or -1, depending on the class. data/perceptron.md [0.0, 0.5349479188905069, 0.5355415711920977, 0.5439405604626569, 0.5535213920359319] # Introduction to Neural Networks: Perceptron One of the first attempts to implement something similar to a modern neural network was done by Frank Rosenblatt from Cornell Aeronautical Laboratory in 1957. It was a hardware implementation called "Mark-1", designed to recognize primitive geometric figures, data/perceptron.md [0.0, 0.4573465617700431, 0.5237117623258072, 0.5634745620918584, 0.5671484849463262] user to adjust the resistance of a circuit. > The New York Times wrote about perceptron at that time: *the embryo of an electronic computer that [the Navy] expects will be able to walk, talk, see, write, reproduce itself and be conscious of its existence.* ## Perceptron Model Suppose we have N features data/perceptron.md [0.0, 0.5237117623258072, 0.5439405604626569, 0.5640031504355143, 0.5743401185082532] and to continue learning - go to Perceptron notebook. Here's an interesting article about perceptrons as well. ## Assignment In this lesson, we have implemented a perceptron for binary classification task, and we have used it to classify between two handwritten digits. In this lab, you are asked to solve data/perceptron.md [0.0, 0.5106881050096326, 0.5142147678862024, 0.5291398797084144, 0.5355415711920977] # Introduction to Neural Networks. Multi-Layered Perceptron In the previous section, you learned about the simplest neural network model - one-layered perceptron, a linear two-class classification model. In this section we will extend this model into a more flexible framework, allowing us to: * perform data/own_framework.md [0.0, 0.4573465617700431, 0.5049903392874557, 0.5142147678862024, 0.5158709620578505] Index 25 not found in DataFrame in our model, in which case the input vector would be a vector of size N. A perceptron is a **binary classification** model, i.e. it can distinguish between two classes of input data. We will assume that for each input vector x the output of our perceptron would be either +1 or -1, depending on the class. data/perceptron.md [0.0, 0.5349479188905069, 0.5355415711920977, 0.5439405604626569, 0.5535213920359319] # Introduction to Neural Networks: Perceptron One of the first attempts to implement something similar to a modern neural network was done by Frank Rosenblatt from Cornell Aeronautical Laboratory in 1957. It was a hardware implementation called "Mark-1", designed to recognize primitive geometric figures, data/perceptron.md [0.0, 0.4573465617700431, 0.5237117623258072, 0.5634745620918584, 0.5671484849463262] user to adjust the resistance of a circuit. > The New York Times wrote about perceptron at that time: *the embryo of an electronic computer that [the Navy] expects will be able to walk, talk, see, write, reproduce itself and be conscious of its existence.* ## Perceptron Model Suppose we have N features data/perceptron.md [0.0, 0.5237117623258072, 0.5439405604626569, 0.5640031504355143, 0.5743401185082532] and to continue learning - go to Perceptron notebook. Here's an interesting article about perceptrons as well. ## Assignment In this lesson, we have implemented a perceptron for binary classification task, and we have used it to classify between two handwritten digits. In this lab, you are asked to solve data/perceptron.md [0.0, 0.5106881050096326, 0.5142147678862024, 0.5291398797084144, 0.5355415711920977] # Introduction to Neural Networks. Multi-Layered Perceptron In the previous section, you learned about the simplest neural network model - one-layered perceptron, a linear two-class classification model. In this section we will extend this model into a more flexible framework, allowing us to: * perform data/own_framework.md [0.0, 0.4573465617700431, 0.5049903392874557, 0.5142147678862024, 0.5158709620578505] Index 25 not found in DataFrame in our model, in which case the input vector would be a vector of size N. A perceptron is a **binary classification** model, i.e. it can distinguish between two classes of input data. We will assume that for each input vector x the output of our perceptron would be either +1 or -1, depending on the class. data/perceptron.md [0.0, 0.5349479188905069, 0.5355415711920977, 0.5439405604626569, 0.5535213920359319] # Introduction to Neural Networks: Perceptron One of the first attempts to implement something similar to a modern neural network was done by Frank Rosenblatt from Cornell Aeronautical Laboratory in 1957. It was a hardware implementation called "Mark-1", designed to recognize primitive geometric figures, data/perceptron.md [0.0, 0.4573465617700431, 0.5237117623258072, 0.5634745620918584, 0.5671484849463262] user to adjust the resistance of a circuit. > The New York Times wrote about perceptron at that time: *the embryo of an electronic computer that [the Navy] expects will be able to walk, talk, see, write, reproduce itself and be conscious of its existence.* ## Perceptron Model Suppose we have N features data/perceptron.md [0.0, 0.5237117623258072, 0.5439405604626569, 0.5640031504355143, 0.5743401185082532] and to continue learning - go to Perceptron notebook. Here's an interesting article about perceptrons as well. ## Assignment In this lesson, we have implemented a perceptron for binary classification task, and we have used it to classify between two handwritten digits. In this lab, you are asked to solve data/perceptron.md [0.0, 0.5106881050096326, 0.5142147678862024, 0.5291398797084144, 0.5355415711920977] # Introduction to Neural Networks. Multi-Layered Perceptron In the previous section, you learned about the simplest neural network model - one-layered perceptron, a linear two-class classification model. In this section we will extend this model into a more flexible framework, allowing us to: * perform data/own_framework.md [0.0, 0.4573465617700431, 0.5049903392874557, 0.5142147678862024, 0.5158709620578505] Index 25 not found in DataFrame
import os
import openai
openai.api_type = "azure"
openai.api_base = os.getenv("AZURE_OPENAI_ENDPOINT")
openai.api_version = "2023-07-01-preview"
openai.api_key = os.getenv("AZURE_OPENAI_KEY")
user_input = "what is a perceptron?"
def chatbot(user_input):
# Convert the question to a query vector
query_vector = create_embeddings(user_input)
# Find the most similar documents
distances, indices = nbrs.kneighbors([query_vector])
# add documents to query to provide context
history = []
for index in indices[0]:
history.append(flattened_df['chunks'].iloc[index])
# combine the history and the user input
history.append(user_input)
# create a message object
messages=[
{"role": "system", "content": "You are an AI assiatant that helps with AI questions."},
{"role": "user", "content": history[-1]}
]
# use chat completion to generate a response
response = openai.chat.completions.create(
model="gpt-35-turbo-1106",
temperature=0.7,
max_tokens=800,
messages=messages
)
return response.choices[0].message
chatbot(user_input)
ChatCompletionMessage(content='A perceptron is a type of artificial neural network model, which is a fundamental unit of a neural network. It is a simple algorithm used for binary classification tasks. The perceptron takes multiple input values, applies weights to these inputs, and produces a single output value. The output is determined by applying a step function to the weighted sum of the inputs. Perceptrons are often used as building blocks for more complex neural network architectures.', role='assistant', function_call=None, tool_calls=None)
A basic example of how you can use Mean Average Precision (MAP) to evaluate the responses of your model based on their relevance.
from sklearn.metrics import average_precision_score
# Define your test cases
test_cases = [
{
"query": "What is a perceptron?",
"relevant_responses": ["A perceptron is a type of artificial neuron.", "It's a binary classifier used in machine learning."],
"irrelevant_responses": ["A perceptron is a type of fruit.", "It's a type of car."]
},
{
"query": "What is machine learning?",
"relevant_responses": ["Machine learning is a method of data analysis that automates analytical model building.", "It's a branch of artificial intelligence based on the idea that systems can learn from data, identify patterns and make decisions with minimal human intervention."],
"irrelevant_responses": ["Machine learning is a type of fruit.", "It's a type of car."]
},
{
"query": "What is deep learning?",
"relevant_responses": ["Deep learning is a subset of machine learning in artificial intelligence (AI) that has networks capable of learning unsupervised from data that is unstructured or unlabeled.", "It's a type of machine learning."],
"irrelevant_responses": ["Deep learning is a type of fruit.", "It's a type of car."]
},
{
"query": "What is a neural network?",
"relevant_responses": ["A neural network is a series of algorithms that endeavors to recognize underlying relationships in a set of data through a process that mimics the way the human brain operates.", "It's a type of machine learning."],
"irrelevant_responses": ["A neural network is a type of fruit.", "It's a type of car."]
}
]
# Initialize the total average precision
total_average_precision = 0
# Test the RAG application
for test_case in test_cases:
query = test_case["query"]
relevant_responses = test_case["relevant_responses"]
irrelevant_responses = test_case["irrelevant_responses"]
# Generate a response using your RAG application
response = chatbot(query)
# Create a list of all responses and a list of true binary labels
all_responses = relevant_responses + irrelevant_responses
true_labels = [1] * len(relevant_responses) + [0] * len(irrelevant_responses)
# Create a list of predicted scores based on whether the response is the generated response
predicted_scores = [1 if resp == response else 0 for resp in all_responses]
# Calculate the average precision for this query
average_precision = average_precision_score(true_labels, predicted_scores)
# Add the average precision to the total average precision
total_average_precision += average_precision
# Calculate the mean average precision
mean_average_precision = total_average_precision / len(test_cases)
mean_average_precision
0.5