Trent Oh commited on
Commit
ac6dc66
·
1 Parent(s): 11d76df

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +61 -4
README.md CHANGED
@@ -8,9 +8,66 @@ tags:
8
 
9
  # mpnet_stackexchange_v1
10
 
11
- This is mpnet-base model trained on 6M stackexchange title - answer data using Siamese network setup.
12
 
13
- ## Usage
14
 
15
- The model can be used for semantic-search.
16
- Output vectors are normalized and mean pooling used during training.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
  # mpnet_stackexchange_v1
10
 
11
+ ## Model Description
12
 
13
+ SentenceTransformers is a set of models and frameworks that enable training and generating sentence embeddings from given data. The generated sentence embeddings can be utilized for Clustering, Semantic Search and other tasks. We used a pretrained [mpnet-base](https://huggingface.co/microsoft/mpnet-base) model and trained it using Siamese Network setup and contrastive learning objective. Question and answer pairs from StackExchange was used as training data to make the model robust to Question / Answer embedding similarity.
14
 
15
+ We developped this model during the
16
+ [Community week using JAX/Flax for NLP & CV](https://discuss.huggingface.co/t/open-to-the-community-community-week-using-jax-flax-for-nlp-cv/7104),
17
+ organized by Hugging Face. We developped this model as part of the project:
18
+ [Train the Best Sentence Embedding Model Ever with 1B Training Pairs](https://discuss.huggingface.co/t/train-the-best-sentence-embedding-model-ever-with-1b-training-pairs/7354). We benefited from efficient hardware infrastructure to run the project: 7 TPUs v3-8, as well
19
+ as intervention from Google’s Flax, JAX, and Cloud team member about efficient deep learning frameworks.
20
+
21
+ ## Intended uses
22
+
23
+ Our model is intended to be used as a sentence encoder for a search engine. Given an input sentence, it ouptuts a vector which captures
24
+ the sentence semantic information. The sentence vector may be used for semantic-search, clustering or sentence similarity tasks.
25
+
26
+ ## How to use
27
+
28
+ Here is how to use this model to get the features of a given text using [SentenceTransformers](https://github.com/UKPLab/sentence-transformers) library:
29
+
30
+ ```python
31
+ from sentence_transformers import SentenceTransformer
32
+
33
+ model = SentenceTransformer('flax-sentence-embeddings/mpnet_stackexchange_v1')
34
+ text = "Replace me by any question / answer you'd like."
35
+ text_embbedding = model.encode(text)
36
+ # array([-0.01559514, 0.04046123, 0.1317083 , 0.00085931, 0.04585106,
37
+ # -0.05607086, 0.0138078 , 0.03569756, 0.01420381, 0.04266302 ...],
38
+ # dtype=float32)
39
+ ```
40
+
41
+ # Training procedure
42
+
43
+ ## Pre-training
44
+
45
+ We use the pretrained [`Mpnet-base`](https://huggingface.co/microsoft/mpnet-base). Please refer to the model
46
+ card for more detailed information about the pre-training procedure.
47
+
48
+ ## Fine-tuning
49
+
50
+ We fine-tune the model using a contrastive objective. Formally, we compute the cosine similarity from each possible sentence pairs from the batch.
51
+ We then apply the cross entropy loss by comparing with true pairs.
52
+
53
+ ### Hyper parameters
54
+
55
+ We trained on model on a TPU v3-8. We train the model during 80k steps using a batch size of 1024 (128 per TPU core).
56
+ We use a learning rate warm up of 500. The sequence length was limited to 128 tokens. We used the AdamW optimizer with
57
+ a 2e-5 learning rate. The full training script is accessible in this current repository.
58
+
59
+ ### Training data
60
+
61
+ We used the concatenation from multiple Stackexchange Question-Answer datasets to fine-tune our model.
62
+ We sampled each StackExchange given a weighted probability of following equation.
63
+
64
+ ```
65
+ int((stackexchange_length[path] / total_stackexchange_length) * total_weight)
66
+ ```
67
+
68
+ MSMARCO, NQ & other question-answer datasets were also used. Sampling ratio for StackExchange vs remaining : 2 vs 1.
69
+
70
+
71
+ | Dataset | Paper | Number of training tuples |
72
+ |:--------------------------------------------------------:|:----------------------------------------:|:--------------------------:|
73
+ | [Stack Exchange QA - Title & Answer](https://huggingface.co/datasets/flax-sentence-embeddings/stackexchange_title_best_voted_answer_jsonl) | - | 4,750,619 |