You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I' ve just tried to start using embeddings I am on an archlinux with rtx3060. Everything works but results are strange. I have splitted sherlock novel A Study in Scarlet. I am asking for a war Here is the code I use:
import re
def split_text_sntc(text, max_length=500):
sentences = re.split(r'(?<=[.!?])\s', text)
chunks, current_chunk = [], ''
for sentence in sentences:
if len(current_chunk) + len(sentence) <= max_length:
current_chunk += sentence
else:
chunks.append(current_chunk)
current_chunk = sentence
if current_chunk:
chunks.append(current_chunk)
return chunks
import os
f=open('Sherlock-A-Study-in-Scarlet.txt')
novel=f.read()
f.close()
for i in range(1):
#novel=novel.replace('\n\n','\n')
novel=novel.replace('\n','')
#novel=novel.replace("'","\'")
#novel=novel.replace('"','\\"')
novel=novel.replace(' ',' ')
novel_split=split_text_sntc(novel,max_length=400)
from langchain.embeddings import LlamaCppEmbeddings
llama = LlamaCppEmbeddings(model_path="text-generation-webui/models/llama-2-13b-chat.Q6_K.gguf",n_gpu_layers=30,)
embeddings=[]
cnt=0
for i in novel_split:
print('Processed %'+str(cnt/len(novel_split)))
embeddings.append(llama.embed_query(i))
if cnt==250:
break
cnt+=1
import numpy as np
dim=len(embeddings[0])
embeddings_np=[]
for i in embeddings:
embeddings_np.append(np.asarray(i, dtype=np.float32))
import faiss
index=faiss.IndexFlatL2(dim)
index.add(np.asarray(embeddings_np))
querystr='A character looking for housing, who is also came back from war in Afghanistan'
queryvec=llama.embed_query(querystr)
k=5
D,I = index.search(np.array([queryvec]),k)
for i in I[0]:
print(novel_split[i].replace('\\"','"'))
print('#########################################################')
Results are so unrelated I cant belive my eyes.
What am I doing wrong ?
Please help me out. Thank you.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I' ve just tried to start using embeddings I am on an archlinux with rtx3060. Everything works but results are strange. I have splitted sherlock novel A Study in Scarlet. I am asking for a war Here is the code I use:
Results are so unrelated I cant belive my eyes.
What am I doing wrong ?
Please help me out. Thank you.
Beta Was this translation helpful? Give feedback.
All reactions