Sentence Similarity
PyTorch
English
taylor-m1
constructai commited on
Commit
224b9ef
·
verified ·
1 Parent(s): 36a9dd1

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +61 -1
README.md CHANGED
@@ -41,4 +41,64 @@ On a small test set, the model achieves:
41
 
42
  * Margin: 0.44
43
 
44
- # Usage is coming soon!
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
 
42
  * Margin: 0.44
43
 
44
+ # Usage
45
+
46
+ **Option 1: Via custom Python package (recommended)**
47
+
48
+ Install the package directly from GitHub:
49
+
50
+ ```bash
51
+ pip install git+https://github.com/PSYCHOxSPEED/constructai-taylor-model
52
+ ```
53
+
54
+ **Then load the model and get embeddings:**
55
+
56
+ ```python
57
+ from taylor_model import load_taylor_model, embed_texts
58
+ import torch
59
+
60
+ device = "cuda" if torch.cuda.is_available() else "cpu"
61
+ model, tokenizer, _ = load_taylor_model("constructai/taylor-m1-38m-128", device=device)
62
+
63
+ texts = ["What is a neural network?", "How to make pizza at home?"]
64
+ embeddings = embed_texts(model, tokenizer, texts, device=device)
65
+ print(embeddings.shape) # (2, 384)
66
+ ```
67
+
68
+ **Compute similarity between queries and documents:**
69
+
70
+ ```python
71
+ from taylor_model import load_taylor_model, embed_texts
72
+ import torch
73
+
74
+ device = "cuda" if torch.cuda.is_available() else "cpu"
75
+ model, tokenizer, _ = load_taylor_model("constructai/taylor-v1-128-emb", device=device)
76
+
77
+ queries = [
78
+ "What is a neural network?",
79
+ "How to make pizza at home?"
80
+ ]
81
+ documents = [
82
+ "A neural network is a computing system inspired by biological neural networks.",
83
+ "For pizza you need dough, tomato sauce, mozzarella cheese and toppings."
84
+ ]
85
+
86
+ q_emb = embed_texts(model, tokenizer, queries, device=device)
87
+ d_emb = embed_texts(model, tokenizer, documents, device=device)
88
+
89
+ similarities = q_emb @ d_emb.T
90
+ print("Similarity matrix:")
91
+ print(similarities)
92
+ ```
93
+
94
+ **Requirements:**
95
+
96
+ * Python ≥ 3.9
97
+ * transformers ≥ 4.30.0
98
+ * torch ≥ 2.0.0
99
+ * huggingface_hub ≥ 0.20.0
100
+ * numpy
101
+
102
+ # License
103
+
104
+ This model is released under the **Apache 2.0** License.