srinivasanAI commited on
Commit
7fae551
·
verified ·
1 Parent(s): 8c54e93
Files changed (1) hide show
  1. README.md +27 -22
README.md CHANGED
@@ -175,30 +175,35 @@ SentenceTransformer(
175
 
176
  First install the Sentence Transformers library:
177
 
178
- ```bash
179
- pip install -U sentence-transformers
180
- ```
 
 
 
 
 
 
 
 
181
 
182
- Then you can load this model and run inference.
183
- ```python
184
- from sentence_transformers import SentenceTransformer
185
-
186
- # Download from the 🤗 Hub
187
- model = SentenceTransformer("srinivasanAI/bge-small-my-qna-model")
188
- # Run inference
189
- sentences = [
190
- 'Represent this sentence for searching relevant passages: what topic do all scientific questions have in common',
191
- 'List of topics characterized as pseudoscience Criticism of pseudoscience, generally by the scientific community or skeptical organizations, involves critiques of the logical, methodological, or rhetorical bases of the topic in question.[1] Though some of the listed topics continue to be investigated scientifically, others were only subject to scientific research in the past, and today are considered refuted but resurrected in a pseudoscientific fashion. Other ideas presented here are entirely non-scientific, but have in one way or another infringed on scientific domains or practices.',
192
- 'Jane Wyatt Wyatt portrayed Amanda Grayson, Spock\'s mother and Ambassador Sarek\'s (Mark Lenard) wife, in the 1967 episode "Journey to Babel" of the original NBC series, Star Trek, and the 1986 film Star Trek IV: The Voyage Home.[9] Wyatt was once quoted as saying her fan mail for these two appearances in this role exceeded that of Lost Horizon. In 1969, she made a guest appearance on Here Come the Brides, but did not have any scenes with Mark Lenard, who was starring on the show as sawmill owner Aaron Stemple.',
193
  ]
194
- embeddings = model.encode(sentences)
195
- print(embeddings.shape)
196
- # [3, 384]
197
-
198
- # Get the similarity scores for the embeddings
199
- similarities = model.similarity(embeddings, embeddings)
200
- print(similarities.shape)
201
- # [3, 3]
 
 
 
 
202
  ```
203
 
204
  <!--
 
175
 
176
  First install the Sentence Transformers library:
177
 
178
+ from sentence_transformers import SentenceTransformer, util
179
+
180
+ # Load the fine-tuned model from the Hub
181
+ model_id = "srinivasanAI/bge-small-my-qna-model" # Replace with your model ID
182
+ model = SentenceTransformer(model_id)
183
+
184
+ # The BGE model requires a specific instruction for retrieval queries
185
+ instruction = "Represent this sentence for searching relevant passages: "
186
+
187
+ # 1. Define your query and your potential answers (passages)
188
+ query = instruction + "What is the powerhouse of the cell?"
189
 
190
+ passages = [
191
+ "Mitochondria are organelles that act like a digestive system and are often called the powerhouse of the cell.",
192
+ "The cell wall is a rigid layer that provides structural support to plant cells.",
193
+ "The sun is a star at the center of the Solar System."
 
 
 
 
 
 
 
194
  ]
195
+
196
+ # 2. Encode the single query and the list of passages separately
197
+ query_embedding = model.encode(query)
198
+ passage_embeddings = model.encode(passages)
199
+
200
+ # 3. Calculate the similarity between the single query and all passages
201
+ similarities = util.cos_sim(query_embedding, passage_embeddings)
202
+
203
+ # 4. Print the results
204
+ print(f"Query: {query.replace(instruction, '')}\n")
205
+ for i, passage in enumerate(passages):
206
+ print(f"Similarity: {similarities[0][i]:.4f} | Passage: {passage}")
207
  ```
208
 
209
  <!--