asi commited on
Commit
e23bd90
·
1 Parent(s): 9dfa477

:books: add documentation

Browse files
Files changed (1) hide show
  1. README.md +61 -2
README.md CHANGED
@@ -4,8 +4,67 @@ tags:
4
  - sentence-transformers
5
  - feature-extraction
6
  - sentence-similarity
 
7
  ---
8
 
9
- # reddit_single-context_mpnet-base
10
 
11
- This is a microsoft/mpnet-base model trained on about 700M (context, response) pairs from Reddit 2015-2018. See data_config.json and train_script.py in this respository how the model was trained and which datasets have been used.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  - sentence-transformers
5
  - feature-extraction
6
  - sentence-similarity
7
+ language: en
8
  ---
9
 
10
+ # Model description
11
 
12
+ The project aims to train sentence embedding models on very large sentence level datasets using a self-supervised
13
+ contrastive learning objective. We used the pretrained ['mpnet-base'](https://huggingface.co/microsoft/mpnet-base) model and fine-tuned in on a
14
+ 700M sentence pairs dataset. We use a contrastive learning objective: given a sentence from the pair, the model should predict which out of a set of randomly sampled other sentences, was actually paired with it in our dataset.
15
+
16
+ We developped this model during the
17
+ [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),
18
+ organized by Hugging Face. We developped this model as part of the project:
19
+ [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
20
+ as intervention from Google’s Flax, JAX, and Cloud team member about efficient deep learning frameworks.
21
+
22
+ ## Intended uses
23
+
24
+ Our model is intented to be used as a sentence encoder. Given an input sentence, it ouptuts a vector which captures
25
+ the sentence semantic information. The sentence vector may be used for information retrieval, clustering or sentence
26
+ similarity tasks.
27
+
28
+ ## How to use
29
+
30
+ Here is how to use this model to get the features of a given text using [SentenceTransformers](https://github.com/UKPLab/sentence-transformers) library:
31
+
32
+ ```python
33
+ from sentence_transformers import SentenceTransformer
34
+
35
+ model = SentenceTransformer('flax-sentence-embeddings/all_datasets_v4_mpnet-base')
36
+ text = "Replace me by any text you'd like."
37
+ text_embbedding = model.encode(text)
38
+ # array([-0.01559514, 0.04046123, 0.1317083 , 0.00085931, 0.04585106,
39
+ # -0.05607086, 0.0138078 , 0.03569756, 0.01420381, 0.04266302 ...],
40
+ # dtype=float32)
41
+ ```
42
+
43
+ # Training procedure
44
+
45
+ ## Pre-training
46
+
47
+ We use the pretrained ['mpnet-base'](https://huggingface.co/microsoft/mpnet-base).
48
+ Please refer to the model card for more detailed information about the pre-training procedure.
49
+
50
+ ## Fine-tuning
51
+
52
+ We fine-tune the model using a contrastive objective. Formally, we compute the cosine similarity from each possible sentence pairs from the batch.
53
+ We then apply the cross entropy loss by comparing with true pairs.
54
+
55
+ ### Hyper parameters
56
+
57
+ We trained ou model on a TPU v3-8. We train the model during 540k steps using a batch size of 1024 (128 per TPU core).
58
+ We use a learning rate warm up of 500. The sequence length was limited to 128 tokens. We used the AdamW optimizer with
59
+ a 2e-5 learning rate. The full training script is accessible in this current repository.
60
+
61
+ ### Training data
62
+
63
+ We use the concatenation from multiple datasets to fine-tune our model. The total number of sentence pairs is above 700M sentences.
64
+ We sampled each dataset given a weighted probability which configuration is detailed in the `data_config.json` file.
65
+ We only use the first context response when building the dataset.
66
+
67
+
68
+ | Dataset | Paper | Number of training tuples |
69
+ |:--------------------------------------------------------:|:----------------------------------------:|:--------------------------:|
70
+ | [Reddit conversationnal](https://github.com/PolyAI-LDN/conversational-datasets/tree/master/reddit) | [paper](https://arxiv.org/abs/1904.06472) | 726,484,430 |