Sentence Similarity
sentence-transformers
Safetensors
bert
feature-extraction
Generated from Trainer
dataset_size:100231
loss:MultipleNegativesRankingLoss
text-embeddings-inference
Instructions to use srinivasanAI/bge-small-my-qna-model with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use srinivasanAI/bge-small-my-qna-model with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("srinivasanAI/bge-small-my-qna-model") sentences = [ "Represent this sentence for searching relevant passages: where do the chances live on raising hope", "Raising Hope James \"Jimmy\" Chance is a 23-year old, living in the surreal fictional town of Natesville, who impregnates a serial killer during a one-night stand. Earning custody of his daughter, Hope, after the mother is sentenced to death, Jimmy relies on his oddball but well-intentioned family for support in raising the child.", "Quadripoint A quadripoint is a point on the Earth that touches the border of four distinct territories.[1][2] The term has never been in common use—it may not have been used before 1964 when it was possibly invented by the Office of the Geographer of the United States Department of State.[3][n 1] The word does not appear in the Oxford English Dictionary or Merriam-Webster Online dictionary, but it does appear in the Encyclopædia Britannica,[4] as well as in the World Factbook articles on Botswana, Namibia, Zambia, and Zimbabwe, dating as far back as 1990.[5]", "Show Me the Way to Go Home The song was recorded by several artists in the 1920s, including radio personalities The Happiness Boys,[2] Vincent Lopez and his Orchestra,[2] and the California Ramblers.[3] Throughout the twentieth into the twenty-first century it has been recorded by numerous artists." ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [4, 4] - Notebooks
- Google Colab
- Kaggle
updated
Browse files
README.md
CHANGED
|
@@ -175,30 +175,35 @@ SentenceTransformer(
|
|
| 175 |
|
| 176 |
First install the Sentence Transformers library:
|
| 177 |
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 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 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
<!--
|