Mihaiii commited on
Commit
3188597
1 Parent(s): f26dd05

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +76 -0
README.md CHANGED
@@ -1,4 +1,80 @@
1
  ---
2
  license: mit
 
3
  pipeline_tag: sentence-similarity
 
 
 
 
 
 
 
 
4
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: mit
3
+ library_name: sentence-transformers
4
  pipeline_tag: sentence-similarity
5
+ tags:
6
+ - sentence-transformers
7
+ - feature-extraction
8
+ - sentence-similarity
9
+ - gte
10
+ - mteb
11
+ datasets:
12
+ - Mihaiii/qa-assistant
13
  ---
14
+ # Bulbasaur
15
+
16
+ This is a distill of [gte-tiny](https://huggingface.co/TaylorAI/gte-tiny) trained using [qa-assistant](https://huggingface.co/datasets/Mihaiii/qa-assistant).
17
+
18
+ ## Intended purpose
19
+
20
+ <span style="color:blue">This model is designed for use in semantic-autocomplete ([click here for demo](https://mihaiii.github.io/semantic-autocomplete/)).</span>
21
+
22
+ ## Usage (Sentence-Transformers) (same as [gte-tiny](https://huggingface.co/TaylorAI/gte-tiny))
23
+
24
+ Using this model becomes easy when you have [sentence-transformers](https://www.SBERT.net) installed:
25
+
26
+ ```
27
+ pip install -U sentence-transformers
28
+ ```
29
+
30
+ Then you can use the model like this:
31
+
32
+ ```python
33
+ from sentence_transformers import SentenceTransformer
34
+ sentences = ["This is an example sentence", "Each sentence is converted"]
35
+
36
+ model = SentenceTransformer('Mihaiii/Bulbasaur')
37
+ embeddings = model.encode(sentences)
38
+ print(embeddings)
39
+ ```
40
+
41
+
42
+
43
+ ## Usage (HuggingFace Transformers) (same as [gte-tiny](https://huggingface.co/TaylorAI/gte-tiny))
44
+ Without [sentence-transformers](https://www.SBERT.net), you can use the model like this: First, you pass your input through the transformer model, then you have to apply the right pooling-operation on-top of the contextualized word embeddings.
45
+
46
+ ```python
47
+ from transformers import AutoTokenizer, AutoModel
48
+ import torch
49
+
50
+
51
+ #Mean Pooling - Take attention mask into account for correct averaging
52
+ def mean_pooling(model_output, attention_mask):
53
+ token_embeddings = model_output[0] #First element of model_output contains all token embeddings
54
+ input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
55
+ return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
56
+
57
+
58
+ # Sentences we want sentence embeddings for
59
+ sentences = ['This is an example sentence', 'Each sentence is converted']
60
+
61
+ # Load model from HuggingFace Hub
62
+ tokenizer = AutoTokenizer.from_pretrained('Mihaiii/Bulbasaur')
63
+ model = AutoModel.from_pretrained('Mihaiii/Bulbasaur')
64
+
65
+ # Tokenize sentences
66
+ encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
67
+
68
+ # Compute token embeddings
69
+ with torch.no_grad():
70
+ model_output = model(**encoded_input)
71
+
72
+ # Perform pooling. In this case, mean pooling.
73
+ sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
74
+
75
+ print("Sentence embeddings:")
76
+ print(sentence_embeddings)
77
+ ```
78
+
79
+ ### Limitation (same as [gte-small](https://huggingface.co/thenlper/gte-small))
80
+ This model exclusively caters to English texts, and any lengthy texts will be truncated to a maximum of 512 tokens.