tmskss commited on
Commit
99a4862
1 Parent(s): dd61626

Update semantic search and output format

Browse files
Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -72,9 +72,9 @@ def get_results_from_pinecone(query, top_k=3, re_rank=True, verbose=True):
72
  return final_results
73
 
74
  def semantic_search(prompt):
75
- final_results = get_results_from_pinecone(prompt, top_k=3, re_rank=True, verbose=True)
76
 
77
- return 'First result:\n' + final_results[0]['metadata']['text'].replace('\n', ' ') + '\n' + 'Second result:\n' + final_results[1]['metadata']['text'].replace('\n', ' ') + '\n' + 'Third result:\n' + final_results[2]['metadata']['text'].replace('\n', ' ')
78
 
79
  cross_encoder = CrossEncoder('cross-encoder/ms-marco-MiniLM-L-12-v2')
80
  sentencetransformer_model = SentenceTransformer('sentence-transformers/multi-qa-mpnet-base-cos-v1')
@@ -129,7 +129,7 @@ stop_terms=["</s>", "#End"]
129
  eos_token_ids_custom = [torch.tensor(tokenizer.encode(term, add_special_tokens=False)).to("cuda") for term in stop_terms]
130
 
131
  category_terms=["</s>", "\n"]
132
- category_eos_token_ids_custom = [torch.tensor(tokenizer.encode(term, add_special_tokens=False)).to("cuda") for term in stop_terms]
133
 
134
 
135
  class EvalStopCriterion(StoppingCriteria):
@@ -184,7 +184,7 @@ def text_to_text_generation(prompt):
184
  print(f'[INST] You are an assistant who summarizes results retrieved from a book about Kubernetes. This summary should answer the question. If the answer is not in the retrieved results, use your general knowledge. [/INST] Question: {prompt}\nRetrieved results:\n{retrieved_results}\nResponse:')
185
  prompt = f'[INST] You are an assistant who summarizes results retrieved from a book about Kubernetes. This summary should answer the question. If the answer is not in the retrieved results, use your general knowledge. [/INST] Question: {prompt}\nRetrieved results:\n{retrieved_results}\nResponse:'
186
  else:
187
- prompt = f'[INST] {prompt} [/INST]'
188
 
189
  # Generate output
190
  model_input = tokenizer(prompt, return_tensors="pt").to("cuda")
 
72
  return final_results
73
 
74
  def semantic_search(prompt):
75
+ final_results = get_results_from_pinecone(prompt, top_k=9, re_rank=True, verbose=True)
76
 
77
+ return '\n\n'.join(res['metadata']['text'].strip() for res in final_results[:3])
78
 
79
  cross_encoder = CrossEncoder('cross-encoder/ms-marco-MiniLM-L-12-v2')
80
  sentencetransformer_model = SentenceTransformer('sentence-transformers/multi-qa-mpnet-base-cos-v1')
 
129
  eos_token_ids_custom = [torch.tensor(tokenizer.encode(term, add_special_tokens=False)).to("cuda") for term in stop_terms]
130
 
131
  category_terms=["</s>", "\n"]
132
+ category_eos_token_ids_custom = [torch.tensor(tokenizer.encode(term, add_special_tokens=False)).to("cuda") for term in category_terms]
133
 
134
 
135
  class EvalStopCriterion(StoppingCriteria):
 
184
  print(f'[INST] You are an assistant who summarizes results retrieved from a book about Kubernetes. This summary should answer the question. If the answer is not in the retrieved results, use your general knowledge. [/INST] Question: {prompt}\nRetrieved results:\n{retrieved_results}\nResponse:')
185
  prompt = f'[INST] You are an assistant who summarizes results retrieved from a book about Kubernetes. This summary should answer the question. If the answer is not in the retrieved results, use your general knowledge. [/INST] Question: {prompt}\nRetrieved results:\n{retrieved_results}\nResponse:'
186
  else:
187
+ prompt = f'[INST] {prompt} [/INST]'
188
 
189
  # Generate output
190
  model_input = tokenizer(prompt, return_tensors="pt").to("cuda")