Ashishkr commited on
Commit
bf6ac79
1 Parent(s): fba5599

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +33 -2
README.md CHANGED
@@ -51,6 +51,36 @@ for i in range(len(sample_outputs)):
51
 
52
 
53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  # to select the top n results:
55
 
56
  from sentence_transformers import SentenceTransformer, util
@@ -63,8 +93,9 @@ corpus_embeddings = embedder.encode(corpus, convert_to_tensor=True)
63
  query = input_query.lower()
64
  query_embedding = embedder.encode(query, convert_to_tensor=True)
65
  cos_scores = util.pytorch_cos_sim(query_embedding, corpus_embeddings)[0]
66
- top_results = torch.topk(cos_scores, k=1)
67
- for score, idx in zip(top_results[0], top_results[3]):
 
68
  print(corpus[idx], "(Score: {:.4f})".format(score))
69
 
70
  ```
 
51
 
52
 
53
 
54
+ # to select the top n results:
55
+
56
+ from transformers import AutoTokenizer, AutoModelWithLMHead
57
+ tokenizer = AutoTokenizer.from_pretrained("salesken/clariq_gpt2")
58
+ model = AutoModelWithLMHead.from_pretrained("salesken/clariq_gpt2")
59
+
60
+
61
+
62
+ input_query="Serve your models directly from Hugging Face infrastructure and run large scale NLP models in milliseconds with just a few lines of code"
63
+
64
+ query= input_query + " ~~ "
65
+
66
+
67
+ input_ids = tokenizer.encode(query.lower(), return_tensors='pt')
68
+ sample_outputs = model.generate(input_ids,
69
+ do_sample=True,
70
+ num_beams=1,
71
+ max_length=128,
72
+ temperature=0.9,
73
+ top_k = 40,
74
+ num_return_sequences=10)
75
+ clarifications_gen = []
76
+ for i in range(len(sample_outputs)):
77
+ r = tokenizer.decode(sample_outputs[i], skip_special_tokens=True).split('||')[0]
78
+ r = r.split(' ~~ ~~')[1]
79
+ if r not in clarifications_gen:
80
+ clarifications_gen.append(r)
81
+
82
+ print(clarifications_gen)
83
+
84
  # to select the top n results:
85
 
86
  from sentence_transformers import SentenceTransformer, util
 
93
  query = input_query.lower()
94
  query_embedding = embedder.encode(query, convert_to_tensor=True)
95
  cos_scores = util.pytorch_cos_sim(query_embedding, corpus_embeddings)[0]
96
+ top_results = torch.topk(cos_scores, k=5)
97
+ print("Top clarifications generated :")
98
+ for score, idx in zip(top_results[0], top_results[1]):
99
  print(corpus[idx], "(Score: {:.4f})".format(score))
100
 
101
  ```