Shitao commited on
Commit
a239e99
1 Parent(s): b00e34d

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +27 -35
README.md CHANGED
@@ -2604,7 +2604,6 @@ language:
2604
  pipeline_tag: sentence-similarity
2605
  ---
2606
 
2607
-
2608
  <h1 align="center">FlagEmbedding</h1>
2609
 
2610
 
@@ -2614,22 +2613,20 @@ pipeline_tag: sentence-similarity
2614
  <a href=#usage>Usage</a> |
2615
  <a href="#evaluation">Evaluation</a> |
2616
  <a href="#train">Train</a> |
2617
- <a href="#contact">Contact</a> |
2618
  <a href="#license">License</a>
2619
  <p>
2620
  </h4>
 
2621
 
2622
- More details please refer to our github: [FlagEmbedding](https://github.com/FlagOpen/FlagEmbedding).
2623
-
2624
- [English](README.md) | [中文](README_zh.md)
2625
 
2626
  FlagEmbedding can map any text to a low-dimensional dense vector which can be used for tasks like retrieval, classification, clustering, or semantic search.
2627
- And it also can be used in vector database for LLMs.
2628
 
2629
  ************* 🌟**Updates**🌟 *************
2630
  - 08/05/2023: Release base-scale and small-scale models, **best performance among the models of the same size 🤗**
2631
- - 08/02/2023: Release `bge-large-*`(short for BAAI General Embedding) Models, **rank 1st on MTEB and C-MTEB benchmark!**
2632
- - 08/01/2023: We release the Chinese Massive Text Embedding Benchmark (**C-MTEB**), consisting of 31 test dataset.
2633
 
2634
 
2635
  ## Model List
@@ -2638,12 +2635,12 @@ And it also can be used in vector database for LLMs.
2638
 
2639
  | Model | Language | Description | query instruction for retrieval |
2640
  |:-------------------------------|:--------:| :--------:| :--------:|
2641
- | [BAAI/bge-large-en](https://huggingface.co/BAAI/bge-large-en) | English | **rank 1st** in [MTEB](https://huggingface.co/spaces/mteb/leaderboard) leaderboard | `Represent this sentence for searching relevant passages: ` |
2642
- | [BAAI/bge-base-en](https://huggingface.co/BAAI/bge-base-en) | English | **rank 2nd** in [MTEB](https://huggingface.co/spaces/mteb/leaderboard) leaderboard | `Represent this sentence for searching relevant passages: ` |
2643
  | [BAAI/bge-small-en](https://huggingface.co/BAAI/bge-small-en) | English | a small-scale model but with competitive performance | `Represent this sentence for searching relevant passages: ` |
2644
- | [BAAI/bge-large-zh](https://huggingface.co/BAAI/bge-large-zh) | Chinese | **rank 1st** in [C-MTEB](https://github.com/FlagOpen/FlagEmbedding/tree/master/benchmark) benchmark | `为这个句子生成表示以用于检索相关文章:` |
2645
- | [BAAI/bge-large-zh-noinstruct](https://huggingface.co/BAAI/bge-large-zh-noinstruct) | Chinese | This model is trained without instruction, and **rank 2nd** in [C-MTEB](https://github.com/FlagOpen/FlagEmbedding/tree/master/benchmark) benchmark | |
2646
- | [BAAI/bge-base-zh](https://huggingface.co/BAAI/bge-base-zh) | Chinese | a base-scale model but with competitive performance | `为这个句子生成表示以用于检索相关文章:` |
2647
  | [BAAI/bge-small-zh](https://huggingface.co/BAAI/bge-small-zh) | Chinese | a small-scale model but with competitive performance | `为这个句子生成表示以用于检索相关文章:` |
2648
 
2649
 
@@ -2652,15 +2649,16 @@ And it also can be used in vector database for LLMs.
2652
 
2653
  * **Using FlagEmbedding**
2654
  ```
2655
- pip install flag_embedding
2656
  ```
 
 
2657
  ```python
2658
- from flag_embedding import FlagModel
2659
  sentences = ["样例数据-1", "样例数据-2"]
2660
  model = FlagModel('BAAI/bge-large-zh', query_instruction_for_retrieval="为这个句子生成表示以用于检索相关文章:")
2661
  embeddings = model.encode(sentences)
2662
  print(embeddings)
2663
-
2664
  # for retrieval task, please use encode_queries() which will automatically add the instruction to each query
2665
  # corpus in retrieval task can still use encode() or encode_corpus()
2666
  queries = ['query_1', 'query_2']
@@ -2689,13 +2687,12 @@ embeddings = model.encode(sentences, normalize_embeddings=True)
2689
  print(embeddings)
2690
  ```
2691
  For retrieval task,
2692
- each query should start with a instruction (instructions see [Model List](https://github.com/FlagOpen/FlagEmbedding/tree/master#model-list)).
2693
  ```python
2694
  from sentence_transformers import SentenceTransformer
2695
  queries = ["手机开不了机怎么办?"]
2696
  passages = ["样例段落-1", "样例段落-2"]
2697
  instruction = "为这个句子生成表示以用于检索相关文章:"
2698
-
2699
  model = SentenceTransformer('BAAI/bge-large-zh')
2700
  q_embeddings = model.encode([instruction+q for q in queries], normalize_embeddings=True)
2701
  p_embeddings = model.encode(passages, normalize_embeddings=True)
@@ -2711,16 +2708,13 @@ from transformers import AutoTokenizer, AutoModel
2711
  import torch
2712
  # Sentences we want sentence embeddings for
2713
  sentences = ["样例数据-1", "样例数据-2"]
2714
-
2715
  # Load model from HuggingFace Hub
2716
  tokenizer = AutoTokenizer.from_pretrained('BAAI/bge-large-zh')
2717
  model = AutoModel.from_pretrained('BAAI/bge-large-zh')
2718
-
2719
  # Tokenize sentences
2720
  encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
2721
- # for retrieval task, add a instruction to query
2722
  # encoded_input = tokenizer([instruction + q for q in queries], padding=True, truncation=True, return_tensors='pt')
2723
-
2724
  # Compute token embeddings
2725
  with torch.no_grad():
2726
  model_output = model(**encoded_input)
@@ -2734,7 +2728,7 @@ print("Sentence embeddings:", sentence_embeddings)
2734
 
2735
  ## Evaluation
2736
  `baai-general-embedding` models achieve **state-of-the-art performance on both MTEB and C-MTEB leaderboard!**
2737
- More details and evaluation scripts see [benchemark](benchmark/README.md).
2738
 
2739
  - **MTEB**:
2740
 
@@ -2763,7 +2757,7 @@ More details and evaluation scripts see [benchemark](benchmark/README.md).
2763
 
2764
  - **C-MTEB**:
2765
  We create a benchmark C-MTEB for Chinese text embedding which consists of 31 datasets from 6 tasks.
2766
- Please refer to [benchemark](benchmark/README.md) for a detailed introduction.
2767
 
2768
  | Model | Embedding dimension | Avg | Retrieval | STS | PairClassification | Classification | Reranking | Clustering |
2769
  |:-------------------------------|:--------:|:--------:|:--------:|:--------:|:--------:|:--------:|:--------:|:--------:|
@@ -2780,18 +2774,17 @@ Please refer to [benchemark](benchmark/README.md) for a detailed introduction.
2780
 
2781
 
2782
 
2783
-
2784
  ## Train
2785
  This section will introduce the way we used to train the general embedding.
2786
- The training scripts are in [flag_embedding](https://github.com/FlagOpen/FlagEmbedding/tree/master/flag_embedding/baai_general_embedding/),
2787
- and we provide some examples to do [pre-train](https://github.com/FlagOpen/FlagEmbedding/tree/master/examples/pretrain/) and [fine-tune](https://github.com/FlagOpen/FlagEmbedding/tree/master/examples/finetune).
2788
 
2789
 
2790
  **1. RetroMAE Pre-train**
2791
  We pre-train the model following the method [retromae](https://github.com/staoxiao/RetroMAE),
2792
  which shows promising improvement in retrieval task ([paper](https://aclanthology.org/2022.emnlp-main.35.pdf)).
2793
  The pre-training was conducted on 24 A100(40G) GPUs with a batch size of 720.
2794
- In retromae, the mask ratio of the encoder and decoder are 0.3, and 0.5 respectively.
2795
  We used the AdamW optimizer and the learning rate is 2e-5.
2796
 
2797
  **Pre-training data**:
@@ -2815,26 +2808,25 @@ We trained our model on 48 A100(40G) GPUs with a large batch size of 32,768 (so
2815
  We used the AdamW optimizer and the learning rate is 1e-5.
2816
  The temperature for contrastive loss is 0.01.
2817
 
2818
- For the version with `*-instrcution`, we add instruction to the query for the retrieval task in the training.
2819
- For English, the instruction is `Represent this sentence for searching relevant passages: `;
2820
- For Chinese, the instruction is `为这个句子生成表示以用于检索相关文章:`.
2821
  In the evaluation, the instruction should be added for sentence to passages retrieval task, not be added for other tasks.
2822
 
2823
 
2824
- The finetune script is accessible in this repository: [flag_embedding](https://github.com/FlagOpen/FlagEmbedding/tree/master/flag_embedding/baai_general_embedding/README.md).
2825
  You can easily finetune your model with it.
2826
 
2827
  **Training data**:
2828
 
2829
  - For English, we collect 230M text pairs from [wikipedia](https://huggingface.co/datasets/wikipedia), [cc-net](https://github.com/facebookresearch/cc_net), and so on.
2830
 
2831
- - For Chinese, we collect 120M text pairs from [wudao](https://github.com/BAAI-WuDao/Data), [simclue](https://github.com/CLUEbenchmark/SimCLUE) and so on.
2832
 
2833
  **The data collection is to be released in the future.**
2834
 
2835
  We will continually update the embedding models and training codes,
2836
  hoping to promote the development of the embedding model community.
2837
 
2838
-
2839
  ## License
2840
- FlagEmbedding is licensed under [MIT License](). The released models can be used for commercial purposes free of charge.
 
2604
  pipeline_tag: sentence-similarity
2605
  ---
2606
 
 
2607
  <h1 align="center">FlagEmbedding</h1>
2608
 
2609
 
 
2613
  <a href=#usage>Usage</a> |
2614
  <a href="#evaluation">Evaluation</a> |
2615
  <a href="#train">Train</a> |
 
2616
  <a href="#license">License</a>
2617
  <p>
2618
  </h4>
2619
+ For more details please refer to our GitHub repo: [FlagEmbedding](https://github.com/FlagOpen/FlagEmbedding).
2620
 
2621
+ [English](README.md) | [中文](https://github.com/FlagOpen/FlagEmbedding/blob/master/README_zh.md)
 
 
2622
 
2623
  FlagEmbedding can map any text to a low-dimensional dense vector which can be used for tasks like retrieval, classification, clustering, or semantic search.
2624
+ And it also can be used in vector databases for LLMs.
2625
 
2626
  ************* 🌟**Updates**🌟 *************
2627
  - 08/05/2023: Release base-scale and small-scale models, **best performance among the models of the same size 🤗**
2628
+ - 08/02/2023: Release `bge-large-*`(short for BAAI General Embedding) Models, **rank 1st on MTEB and C-MTEB benchmark!** :tada: :tada:
2629
+ - 08/01/2023: We release the [Chinese Massive Text Embedding Benchmark](https://github.com/FlagOpen/FlagEmbedding/blob/master/C_MTEB) (**C-MTEB**), consisting of 31 test dataset.
2630
 
2631
 
2632
  ## Model List
 
2635
 
2636
  | Model | Language | Description | query instruction for retrieval |
2637
  |:-------------------------------|:--------:| :--------:| :--------:|
2638
+ | [BAAI/bge-large-en](https://huggingface.co/BAAI/bge-large-en) | English | :trophy: rank **1st** in [MTEB](https://huggingface.co/spaces/mteb/leaderboard) leaderboard | `Represent this sentence for searching relevant passages: ` |
2639
+ | [BAAI/bge-base-en](https://huggingface.co/BAAI/bge-base-en) | English | rank **2nd** in [MTEB](https://huggingface.co/spaces/mteb/leaderboard) leaderboard | `Represent this sentence for searching relevant passages: ` |
2640
  | [BAAI/bge-small-en](https://huggingface.co/BAAI/bge-small-en) | English | a small-scale model but with competitive performance | `Represent this sentence for searching relevant passages: ` |
2641
+ | [BAAI/bge-large-zh](https://huggingface.co/BAAI/bge-large-zh) | Chinese | :trophy: rank **1st** in [C-MTEB](https://github.com/FlagOpen/FlagEmbedding/tree/master/C_MTEB) benchmark | `为这个句子生成表示以用于检索相关文章:` |
2642
+ | [BAAI/bge-large-zh-noinstruct](https://huggingface.co/BAAI/bge-large-zh-noinstruct) | Chinese | This model is trained without instruction, and rank **2nd** in [C-MTEB](https://github.com/FlagOpen/FlagEmbedding/tree/master/C_MTEB) benchmark | |
2643
+ | [BAAI/bge-base-zh](https://huggingface.co/BAAI/bge-base-zh) | Chinese | a base-scale model but has similar ability with `bge-large-zh` | `为这个句子生成表示以用于检索相关文章:` |
2644
  | [BAAI/bge-small-zh](https://huggingface.co/BAAI/bge-small-zh) | Chinese | a small-scale model but with competitive performance | `为这个句子生成表示以用于检索相关文章:` |
2645
 
2646
 
 
2649
 
2650
  * **Using FlagEmbedding**
2651
  ```
2652
+ pip install FlagEmbedding
2653
  ```
2654
+ See [FlagEmbedding](https://github.com/FlagOpen/FlagEmbedding/blob/master/FlagEmbedding/baai_general_embedding/README.md) for more methods to install FlagEmbedding.
2655
+
2656
  ```python
2657
+ from FlagEmbedding import FlagModel
2658
  sentences = ["样例数据-1", "样例数据-2"]
2659
  model = FlagModel('BAAI/bge-large-zh', query_instruction_for_retrieval="为这个句子生成表示以用于检索相关文章:")
2660
  embeddings = model.encode(sentences)
2661
  print(embeddings)
 
2662
  # for retrieval task, please use encode_queries() which will automatically add the instruction to each query
2663
  # corpus in retrieval task can still use encode() or encode_corpus()
2664
  queries = ['query_1', 'query_2']
 
2687
  print(embeddings)
2688
  ```
2689
  For retrieval task,
2690
+ each query should start with an instruction (instructions see [Model List](https://github.com/FlagOpen/FlagEmbedding/tree/master#model-list)).
2691
  ```python
2692
  from sentence_transformers import SentenceTransformer
2693
  queries = ["手机开不了机怎么办?"]
2694
  passages = ["样例段落-1", "样例段落-2"]
2695
  instruction = "为这个句子生成表示以用于检索相关文章:"
 
2696
  model = SentenceTransformer('BAAI/bge-large-zh')
2697
  q_embeddings = model.encode([instruction+q for q in queries], normalize_embeddings=True)
2698
  p_embeddings = model.encode(passages, normalize_embeddings=True)
 
2708
  import torch
2709
  # Sentences we want sentence embeddings for
2710
  sentences = ["样例数据-1", "样例数据-2"]
 
2711
  # Load model from HuggingFace Hub
2712
  tokenizer = AutoTokenizer.from_pretrained('BAAI/bge-large-zh')
2713
  model = AutoModel.from_pretrained('BAAI/bge-large-zh')
 
2714
  # Tokenize sentences
2715
  encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
2716
+ # for retrieval task, add an instruction to query
2717
  # encoded_input = tokenizer([instruction + q for q in queries], padding=True, truncation=True, return_tensors='pt')
 
2718
  # Compute token embeddings
2719
  with torch.no_grad():
2720
  model_output = model(**encoded_input)
 
2728
 
2729
  ## Evaluation
2730
  `baai-general-embedding` models achieve **state-of-the-art performance on both MTEB and C-MTEB leaderboard!**
2731
+ More details and evaluation tools see our [scripts](https://github.com/FlagOpen/FlagEmbedding/blob/master/C_MTEB/README.md).
2732
 
2733
  - **MTEB**:
2734
 
 
2757
 
2758
  - **C-MTEB**:
2759
  We create a benchmark C-MTEB for Chinese text embedding which consists of 31 datasets from 6 tasks.
2760
+ Please refer to [C_MTEB](https://github.com/FlagOpen/FlagEmbedding/blob/master/C_MTEB/README.md) for a detailed introduction.
2761
 
2762
  | Model | Embedding dimension | Avg | Retrieval | STS | PairClassification | Classification | Reranking | Clustering |
2763
  |:-------------------------------|:--------:|:--------:|:--------:|:--------:|:--------:|:--------:|:--------:|:--------:|
 
2774
 
2775
 
2776
 
 
2777
  ## Train
2778
  This section will introduce the way we used to train the general embedding.
2779
+ The training scripts are in [FlagEmbedding](https://github.com/FlagOpen/FlagEmbedding/blob/master/FlagEmbedding/baai_general_embedding/README.md),
2780
+ and we provide some examples to do [pre-train](https://github.com/FlagOpen/FlagEmbedding/blob/master/examples/pretrain/README.md) and [fine-tune](https://github.com/FlagOpen/FlagEmbedding/blob/master/examples/finetune/README.md).
2781
 
2782
 
2783
  **1. RetroMAE Pre-train**
2784
  We pre-train the model following the method [retromae](https://github.com/staoxiao/RetroMAE),
2785
  which shows promising improvement in retrieval task ([paper](https://aclanthology.org/2022.emnlp-main.35.pdf)).
2786
  The pre-training was conducted on 24 A100(40G) GPUs with a batch size of 720.
2787
+ In retromae, the mask ratio of encoder and decoder are 0.3, and 0.5 respectively.
2788
  We used the AdamW optimizer and the learning rate is 2e-5.
2789
 
2790
  **Pre-training data**:
 
2808
  We used the AdamW optimizer and the learning rate is 1e-5.
2809
  The temperature for contrastive loss is 0.01.
2810
 
2811
+ For the version with `*-instrcution`, we add instruction to the query for retrieval task in the training.
2812
+ For english, the instruction is `Represent this sentence for searching relevant passages: `;
2813
+ For chinese, the instruction is `为这个句子生成表示以用于检索相关文章:`.
2814
  In the evaluation, the instruction should be added for sentence to passages retrieval task, not be added for other tasks.
2815
 
2816
 
2817
+ The finetune script is accessible in this repository: [FlagEmbedding](https://github.com/FlagOpen/FlagEmbedding/blob/master/FlagEmbedding/baai_general_embedding/README.md).
2818
  You can easily finetune your model with it.
2819
 
2820
  **Training data**:
2821
 
2822
  - For English, we collect 230M text pairs from [wikipedia](https://huggingface.co/datasets/wikipedia), [cc-net](https://github.com/facebookresearch/cc_net), and so on.
2823
 
2824
+ - For chinese, we collect 120M text pairs from [wudao](https://github.com/BAAI-WuDao/Data), [simclue](https://github.com/CLUEbenchmark/SimCLUE) and so on.
2825
 
2826
  **The data collection is to be released in the future.**
2827
 
2828
  We will continually update the embedding models and training codes,
2829
  hoping to promote the development of the embedding model community.
2830
 
 
2831
  ## License
2832
+ FlagEmbedding is licensed under [MIT License](https://github.com/FlagOpen/FlagEmbedding/blob/master/LICENSE). The released models can be used for commercial purposes free of charge.