intfloat commited on
Commit
7454e05
1 Parent(s): 1985ce9

update README.md

Browse files
Files changed (1) hide show
  1. README.md +213 -2
README.md CHANGED
@@ -2,7 +2,7 @@
2
  tags:
3
  - mteb
4
  model-index:
5
- - name: mteb
6
  results:
7
  - task:
8
  type: Classification
@@ -5280,4 +5280,215 @@ model-index:
5280
  value: 87.11747055081017
5281
  - type: max_f1
5282
  value: 80.13002540726349
5283
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  tags:
3
  - mteb
4
  model-index:
5
+ - name: multilingual-e5-large-instruct
6
  results:
7
  - task:
8
  type: Classification
 
5280
  value: 87.11747055081017
5281
  - type: max_f1
5282
  value: 80.13002540726349
5283
+ language:
5284
+ - multilingual
5285
+ - af
5286
+ - am
5287
+ - ar
5288
+ - as
5289
+ - az
5290
+ - be
5291
+ - bg
5292
+ - bn
5293
+ - br
5294
+ - bs
5295
+ - ca
5296
+ - cs
5297
+ - cy
5298
+ - da
5299
+ - de
5300
+ - el
5301
+ - en
5302
+ - eo
5303
+ - es
5304
+ - et
5305
+ - eu
5306
+ - fa
5307
+ - fi
5308
+ - fr
5309
+ - fy
5310
+ - ga
5311
+ - gd
5312
+ - gl
5313
+ - gu
5314
+ - ha
5315
+ - he
5316
+ - hi
5317
+ - hr
5318
+ - hu
5319
+ - hy
5320
+ - id
5321
+ - is
5322
+ - it
5323
+ - ja
5324
+ - jv
5325
+ - ka
5326
+ - kk
5327
+ - km
5328
+ - kn
5329
+ - ko
5330
+ - ku
5331
+ - ky
5332
+ - la
5333
+ - lo
5334
+ - lt
5335
+ - lv
5336
+ - mg
5337
+ - mk
5338
+ - ml
5339
+ - mn
5340
+ - mr
5341
+ - ms
5342
+ - my
5343
+ - ne
5344
+ - nl
5345
+ - 'no'
5346
+ - om
5347
+ - or
5348
+ - pa
5349
+ - pl
5350
+ - ps
5351
+ - pt
5352
+ - ro
5353
+ - ru
5354
+ - sa
5355
+ - sd
5356
+ - si
5357
+ - sk
5358
+ - sl
5359
+ - so
5360
+ - sq
5361
+ - sr
5362
+ - su
5363
+ - sv
5364
+ - sw
5365
+ - ta
5366
+ - te
5367
+ - th
5368
+ - tl
5369
+ - tr
5370
+ - ug
5371
+ - uk
5372
+ - ur
5373
+ - uz
5374
+ - vi
5375
+ - xh
5376
+ - yi
5377
+ - zh
5378
+ license: mit
5379
+ ---
5380
+
5381
+ ## Multilingual-E5-large-instruct
5382
+
5383
+ [Text Embeddings by Weakly-Supervised Contrastive Pre-training](https://arxiv.org/pdf/2212.03533.pdf).
5384
+ Liang Wang, Nan Yang, Xiaolong Huang, Binxing Jiao, Linjun Yang, Daxin Jiang, Rangan Majumder, Furu Wei, arXiv 2022
5385
+
5386
+ This model has 24 layers and the embedding size is 1024.
5387
+
5388
+ ## Usage
5389
+
5390
+ Below is an example to encode queries and passages from the MS-MARCO passage ranking dataset.
5391
+
5392
+ ```python
5393
+ import torch.nn.functional as F
5394
+
5395
+ from torch import Tensor
5396
+ from transformers import AutoTokenizer, AutoModel
5397
+
5398
+
5399
+ def average_pool(last_hidden_states: Tensor,
5400
+ attention_mask: Tensor) -> Tensor:
5401
+ last_hidden = last_hidden_states.masked_fill(~attention_mask[..., None].bool(), 0.0)
5402
+ return last_hidden.sum(dim=1) / attention_mask.sum(dim=1)[..., None]
5403
+
5404
+ def get_detailed_instruct(task_description: str, query: str) -> str:
5405
+ return f'Instruct: {task_description}\nQuery: {query}'
5406
+
5407
+ # Each query must come with a one-sentence instruction that describes the task
5408
+ task = 'Given a web search query, retrieve relevant passages that answer the query'
5409
+ queries = [
5410
+ get_detailed_instruct(task, 'how much protein should a female eat'),
5411
+ get_detailed_instruct(task, '南瓜的家常做法')
5412
+ ]
5413
+ # No need to add instruction for retrieval documents
5414
+ documents = [
5415
+ "As a general guideline, the CDC's average requirement of protein for women ages 19 to 70 is 46 grams per day. But, as you can see from this chart, you'll need to increase that if you're expecting or training for a marathon. Check out the chart below to see how much protein you should be eating each day.",
5416
+ "1.清炒南瓜丝 原料:嫩南瓜半个 调料:葱、盐、白糖、鸡精 做法: 1、南瓜用刀薄薄的削去表面一层皮,用勺子刮去瓤 2、擦成细丝(没有擦菜板就用刀慢慢切成细丝) 3、锅烧热放油,入葱花煸出香味 4、入南瓜丝快速翻炒一分钟左右,放盐、一点白糖和鸡精调味出锅 2.香葱炒南瓜 原料:南瓜1只 调料:香葱、蒜末、橄榄油、盐 做法: 1、将南瓜去皮,切成片 2、油锅8成热后,将蒜末放入爆香 3、爆香后,将南瓜片放入,翻炒 4、在翻炒的同时,可以不时地往锅里加水,但不要太多 5、放入盐,炒匀 6、南瓜差不多软和绵了之后,就可以关火 7、撒入香葱,即可出锅"
5417
+ ]
5418
+ input_texts = queries + documents
5419
+
5420
+ tokenizer = AutoTokenizer.from_pretrained('intfloat/multilingual-e5-large-instruct')
5421
+ model = AutoModel.from_pretrained('intfloat/multilingual-e5-large-instruct')
5422
+
5423
+ # Tokenize the input texts
5424
+ batch_dict = tokenizer(input_texts, max_length=512, padding=True, truncation=True, return_tensors='pt')
5425
+
5426
+ outputs = model(**batch_dict)
5427
+ embeddings = average_pool(outputs.last_hidden_state, batch_dict['attention_mask'])
5428
+
5429
+ # normalize embeddings
5430
+ embeddings = F.normalize(embeddings, p=2, dim=1)
5431
+ scores = (embeddings[:2] @ embeddings[2:].T) * 100
5432
+ print(scores.tolist())
5433
+ ```
5434
+
5435
+ ## Supported Languages
5436
+
5437
+ This model is initialized from [xlm-roberta-large](https://huggingface.co/xlm-roberta-large)
5438
+ and continually trained on a mixture of multilingual datasets.
5439
+ It supports 100 languages from xlm-roberta,
5440
+ but low-resource languages may see performance degradation.
5441
+
5442
+ ## Training Details
5443
+
5444
+ **Initialization**: [xlm-roberta-large](https://huggingface.co/xlm-roberta-large)
5445
+
5446
+ **First stage**: contrastive pre-training with 1 billion weakly supervised text pairs.
5447
+
5448
+ **Second stage**: fine-tuning on datasets from the [E5-mistral](https://arxiv.org/abs/2401.00368) paper.
5449
+
5450
+ ## MTEB Benchmark Evaluation
5451
+
5452
+ Check out [unilm/e5](https://github.com/microsoft/unilm/tree/master/e5) to reproduce evaluation results
5453
+ on the [BEIR](https://arxiv.org/abs/2104.08663) and [MTEB benchmark](https://arxiv.org/abs/2210.07316).
5454
+
5455
+ ## FAQ
5456
+
5457
+ **1. Do I need to add instructions to the query?**
5458
+
5459
+ Yes, this is how the model is trained, otherwise you will see a performance degradation.
5460
+ The task definition should be a one-sentence instruction that describes the task.
5461
+ This is a way to customize text embeddings for different scenarios through natural language instructions.
5462
+
5463
+ Please check out [unilm/e5/utils.py](https://github.com/microsoft/unilm/blob/9c0f1ff7ca53431fe47d2637dfe253643d94185b/e5/utils.py#L106) for instructions we used for evaluation.
5464
+
5465
+ On the other hand, there is no need to add instructions to the document side.
5466
+
5467
+ **2. Why are my reproduced results slightly different from reported in the model card?**
5468
+
5469
+ Different versions of `transformers` and `pytorch` could cause negligible but non-zero performance differences.
5470
+
5471
+ **3. Why does the cosine similarity scores distribute around 0.7 to 1.0?**
5472
+
5473
+ This is a known and expected behavior as we use a low temperature 0.01 for InfoNCE contrastive loss.
5474
+
5475
+ For text embedding tasks like text retrieval or semantic similarity,
5476
+ what matters is the relative order of the scores instead of the absolute values,
5477
+ so this should not be an issue.
5478
+
5479
+ ## Citation
5480
+
5481
+ If you find our paper or models helpful, please consider cite as follows:
5482
+
5483
+ ```
5484
+ @article{wang2022text,
5485
+ title={Text Embeddings by Weakly-Supervised Contrastive Pre-training},
5486
+ author={Wang, Liang and Yang, Nan and Huang, Xiaolong and Jiao, Binxing and Yang, Linjun and Jiang, Daxin and Majumder, Rangan and Wei, Furu},
5487
+ journal={arXiv preprint arXiv:2212.03533},
5488
+ year={2022}
5489
+ }
5490
+ ```
5491
+
5492
+ ## Limitations
5493
+
5494
+ Long texts will be truncated to at most 512 tokens.