kst23 commited on
Commit
54bcb13
·
verified ·
1 Parent(s): d5b357c

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +110 -0
README.md CHANGED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: en
3
+ license: apache-2.0
4
+ library_name: sentence-transformers
5
+ tags:
6
+ - sentence-transformers
7
+ - feature-extraction
8
+ - sentence-similarity
9
+ - transformers
10
+ pipeline_tag: sentence-similarity
11
+
12
+ ---
13
+
14
+ # SLX-v0.1
15
+
16
+ **SLX-v0.1** is an advanced model developed by [BRAHMAI Research](https://brahmai.in), specifically designed for mapping sentences and paragraphs into a 384-dimensional dense vector space. This model is ideal for tasks such as clustering, semantic search, and sentence similarity.
17
+
18
+ ## Usage with Sentence-Transformers
19
+
20
+ Using SLX-v0.1 is straightforward with the [Sentence-Transformers](https://www.SBERT.net) library. Follow the instructions below to get started:
21
+
22
+ ### Installation
23
+
24
+ ```bash
25
+ pip install -U sentence-transformers
26
+ ```
27
+
28
+ ### Example
29
+
30
+ ```python
31
+ from sentence_transformers import SentenceTransformer
32
+
33
+ sentences = ["This is an example sentence", "Each sentence is converted"]
34
+ model = SentenceTransformer('brahmairesearch/slx-v0.1')
35
+ embeddings = model.encode(sentences)
36
+
37
+ print(embeddings)
38
+ ```
39
+
40
+ ## Usage with Hugging Face Transformers
41
+
42
+ If you prefer to use Hugging Face Transformers without the Sentence-Transformers library, you can still utilize the SLX-v0.1 model. Below is a guide on how to process input and apply mean pooling to obtain sentence embeddings:
43
+
44
+ ```python
45
+ from transformers import AutoTokenizer, AutoModel
46
+ import torch
47
+ import torch.nn.functional as F
48
+
49
+ # Mean Pooling - Takes attention mask into account for correct averaging
50
+ def mean_pooling(model_output, attention_mask):
51
+ token_embeddings = model_output[0] # Token embeddings from the model output
52
+ input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
53
+ return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
54
+
55
+ # Sentences for embedding
56
+ sentences = ['This is an example sentence', 'Each sentence is converted']
57
+
58
+ # Load model from Hugging Face Hub
59
+ tokenizer = AutoTokenizer.from_pretrained('brahmairesearch/slx-v0.1')
60
+ model = AutoModel.from_pretrained('brahmairesearch/slx-v0.1')
61
+
62
+ # Tokenize sentences
63
+ encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
64
+
65
+ # Compute token embeddings
66
+ with torch.no_grad():
67
+ model_output = model(**encoded_input)
68
+
69
+ # Perform pooling
70
+ sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
71
+
72
+ # Normalize embeddings
73
+ sentence_embeddings = F.normalize(sentence_embeddings, p=2, dim=1)
74
+
75
+ print("Sentence embeddings:")
76
+ print(sentence_embeddings)
77
+ ```
78
+
79
+ ## Evaluation Results
80
+
81
+ For an automated evaluation of SLX-v0.1, please refer to the [Sentence Embeddings Benchmark](https://seb.sbert.net?model_name=brahmairesearch/slx-v0.1).
82
+
83
+ ## Intended Use Cases
84
+
85
+ SLX-v0.1 is designed for encoding sentences and short paragraphs into dense vectors that capture their semantic information. These embeddings can be used for:
86
+
87
+ - Information retrieval
88
+ - Clustering
89
+ - Sentence similarity tasks
90
+
91
+ Please note that input text longer than 256 word pieces will be truncated by default.
92
+
93
+ ## Training Procedure
94
+
95
+ ### Pre-training
96
+
97
+ SLX-v0.1 is based on the pre-trained model [`nreimers/MiniLM-L6-H384-uncased`](https://huggingface.co/nreimers/MiniLM-L6-H384-uncased). For more information on the pre-training process, please refer to the original model card.
98
+
99
+ ### Fine-tuning
100
+
101
+ The model was fine-tuned using a contrastive learning objective. Cosine similarity is computed between all possible sentence pairs within a batch, and cross-entropy loss is applied using the true pairs.
102
+
103
+ Following fine-tuning, the model underwent transfer learning using the [`dunzhang/stella_en_400M_v5`](https://huggingface.co/dunzhang/stella_en_400M_v5) model with an internally curated dataset, optimizing it for English language tasks.
104
+
105
+ ## Contact
106
+
107
+ For inquiries or feedback, feel free to reach out to us at [email protected].
108
+
109
+ Best regards,
110
+ The [BRAHMAI](https://brahmai.in) Team