"""MTEB Results""" import json import datasets logger = datasets.logging.get_logger(__name__) _CITATION = """@article{muennighoff2022mteb, doi = {10.48550/ARXIV.2210.07316}, url = {https://arxiv.org/abs/2210.07316}, author = {Muennighoff, Niklas and Tazi, Nouamane and Magne, Lo{\"\i}c and Reimers, Nils}, title = {MTEB: Massive Text Embedding Benchmark}, publisher = {arXiv}, journal={arXiv preprint arXiv:2210.07316}, year = {2022} } """ _DESCRIPTION = """Results on MTEB""" URL = "https://huggingface.co/datasets/mteb/results/resolve/main/paths.json" VERSION = datasets.Version("1.0.1") EVAL_LANGS = ['af', 'afr-eng', 'am', "amh", 'amh-eng', 'ang-eng', 'ar', 'ar-ar', 'ara-eng', 'arq-eng', 'arz-eng', 'ast-eng', 'awa-eng', 'az', 'aze-eng', 'bel-eng', 'ben-eng', 'ber-eng', 'bn', 'bos-eng', 'bre-eng', 'bul-eng', 'cat-eng', 'cbk-eng', 'ceb-eng', 'ces-eng', 'cha-eng', 'cmn-eng', 'cor-eng', 'csb-eng', 'cy', 'cym-eng', 'da', 'dan-eng', 'de', 'de-fr', 'de-pl', 'deu-eng', 'dsb-eng', 'dtp-eng', 'el', 'ell-eng', 'en', 'en-ar', 'en-de', 'en-en', 'en-tr', 'eng', 'epo-eng', 'es', 'es-en', 'es-es', 'es-it', 'est-eng', 'eus-eng', 'fa', 'fao-eng', 'fi', 'fin-eng', 'fr', 'fr-en', 'fr-pl', 'fra', 'fra-eng', 'fry-eng', 'gla-eng', 'gle-eng', 'glg-eng', 'gsw-eng', 'hau', 'he', 'heb-eng', 'hi', 'hin-eng', 'hrv-eng', 'hsb-eng', 'hu', 'hun-eng', 'hy', 'hye-eng', 'ibo', 'id', 'ido-eng', 'ile-eng', 'ina-eng', 'ind-eng', 'is', 'isl-eng', 'it', 'it-en', 'ita-eng', 'ja', 'jav-eng', 'jpn-eng', 'jv', 'ka', 'kab-eng', 'kat-eng', 'kaz-eng', 'khm-eng', 'km', 'kn', 'ko', 'ko-ko', 'kor-eng', 'kur-eng', 'kzj-eng', 'lat-eng', 'lfn-eng', 'lit-eng', 'lin', 'lug', 'lv', 'lvs-eng', 'mal-eng', 'mar-eng', 'max-eng', 'mhr-eng', 'mkd-eng', 'ml', 'mn', 'mon-eng', 'ms', 'my', 'nb', 'nds-eng', 'nl', 'nl-ende-en', 'nld-eng', 'nno-eng', 'nob-eng', 'nov-eng', 'oci-eng', 'orm', 'orv-eng', 'pam-eng', 'pcm', 'pes-eng', 'pl', 'pl-en', 'pms-eng', 'pol-eng', 'por-eng', 'pt', 'ro', 'ron-eng', 'ru', 'run', 'rus-eng', 'sl', 'slk-eng', 'slv-eng', 'spa-eng', 'sna', 'som', 'sq', 'sqi-eng', 'srp-eng', 'sv', 'sw', 'swa', 'swe-eng', 'swg-eng', 'swh-eng', 'ta', 'tam-eng', 'tat-eng', 'te', 'tel-eng', 'tgl-eng', 'th', 'tha-eng', 'tir', 'tl', 'tr', 'tuk-eng', 'tur-eng', 'tzl-eng', 'uig-eng', 'ukr-eng', 'ur', 'urd-eng', 'uzb-eng', 'vi', 'vie-eng', 'war-eng', 'wuu-eng', 'xho', 'xho-eng', 'yid-eng', 'yor', 'yue-eng', 'zh', 'zh-CN', 'zh-TW', 'zh-en', 'zsm-eng'] # v_measures key is somehow present in voyage-2-law results and is a list SKIP_KEYS = ["std", "evaluation_time", "main_score", "threshold", "v_measures"] # Use "train" split instead TRAIN_SPLIT = ["DanishPoliticalCommentsClassification"] # Use "validation" split instead VALIDATION_SPLIT = ["AFQMC", "Cmnli", "IFlyTek", "TNews", "MSMARCO", "MSMARCO-PL", "MultilingualSentiment", "Ocnli"] # Use "dev" split instead DEV_SPLIT = ["CmedqaRetrieval", "CovidRetrieval", "DuRetrieval", "EcomRetrieval", "MedicalRetrieval", "MMarcoReranking", "MMarcoRetrieval", "MSMARCO", "MSMARCO-PL", "T2Reranking", "T2Retrieval", "VideoRetrieval"] # Use "test.full" split TESTFULL_SPLIT = ["OpusparcusPC"] MODELS = [ "Baichuan-text-embedding", "Cohere-embed-english-v3.0", "Cohere-embed-multilingual-light-v3.0", "Cohere-embed-multilingual-v3.0", "DanskBERT", "FollowIR-7B", "GritLM-7B", "LASER2", "LLM2Vec-Llama-2-supervised", "LLM2Vec-Llama-2-unsupervised", "LLM2Vec-Meta-Llama-3-supervised", "LLM2Vec-Meta-Llama-3-unsupervised", "LLM2Vec-Mistral-supervised", "LLM2Vec-Mistral-unsupervised", "LLM2Vec-Sheared-Llama-supervised", "LLM2Vec-Sheared-Llama-unsupervised", "LaBSE", "OpenSearch-text-hybrid", "all-MiniLM-L12-v2", "all-MiniLM-L6-v2", "all-mpnet-base-v2", "allenai-specter", "bert-base-10lang-cased", "bert-base-15lang-cased", "bert-base-25lang-cased", "bert-base-multilingual-cased", "bert-base-multilingual-uncased", "bert-base-swedish-cased", "bert-base-uncased", "bge-base-en", "bge-base-zh", "bge-base-zh-v1.5", "bge-large-en", "bge-large-en-v1.5", "bge-large-zh", "bge-large-zh-noinstruct", "bge-large-zh-v1.5", "bge-small-zh", "bge-small-zh-v1.5", "bm25", "camembert-base", "camembert-large", "contriever-base-msmarco", "cross-en-de-roberta-sentence-transformer", "dfm-encoder-large-v1", "dfm-sentence-encoder-large-1", "distilbert-base-25lang-cased", "distilbert-base-en-fr-cased", "distilbert-base-en-fr-es-pt-it-cased", "distilbert-base-fr-cased", "distilbert-base-uncased", "distiluse-base-multilingual-cased-v2", "e5-base", "e5-base-v2", "e5-large", "e5-large-v2", "e5-mistral-7b-instruct", "e5-small", "electra-small-nordic", "electra-small-swedish-cased-discriminator", "elser-v2", "embedder-100p", "facebook-dpr-ctx_encoder-multiset-base", "flan-t5-base", "flan-t5-large", "flaubert_base_cased", "flaubert_base_uncased", "flaubert_large_cased", "gbert-base", "gbert-large", "gelectra-base", "gelectra-large", "glove.6B.300d", "google-gecko-256.text-embedding-preview-0409", "google-gecko.text-embedding-preview-0409", "gottbert-base", "gte-Qwen1.5-7B-instruct", "gtr-t5-base", "gtr-t5-large", "gtr-t5-xl", "gtr-t5-xxl", "herbert-base-retrieval-v2", "instructor-base", "instructor-xl", "komninos", "llama-2-7b-chat", "luotuo-bert-medium", "m3e-base", "m3e-large", "mistral-7b-instruct-v0.2", "mistral-embed", "monobert-large-msmarco", "monot5-3b-msmarco-10k", "monot5-base-msmarco-10k", "msmarco-bert-co-condensor", "multi-qa-MiniLM-L6-cos-v1", "multilingual-e5-base", "multilingual-e5-large", "multilingual-e5-small", "nb-bert-base", "nb-bert-large", "nomic-embed-text-v1.5-128", "nomic-embed-text-v1.5-256", "nomic-embed-text-v1.5-512", "nomic-embed-text-v1.5-64", "norbert3-base", "norbert3-large", "paraphrase-multilingual-MiniLM-L12-v2", "paraphrase-multilingual-mpnet-base-v2", "sentence-bert-swedish-cased", "sentence-camembert-base", "sentence-camembert-large", "sentence-croissant-llm-base", "sentence-t5-base", "sentence-t5-large", "sentence-t5-xl", "sentence-t5-xxl", "sgpt-bloom-1b7-nli", "sgpt-bloom-7b1-msmarco", "silver-retriever-base-v1", "st-polish-paraphrase-from-distilroberta", "st-polish-paraphrase-from-mpnet", "sup-simcse-bert-base-uncased", "tart-dual-contriever-msmarco", "tart-full-flan-t5-xl", "text-embedding-3-large", "text-embedding-3-large-256", "text-embedding-3-small", "text-embedding-ada-002", "text-search-ada-001", "text-search-ada-doc-001", "text-search-babbage-001", "text-search-curie-001", "text-search-davinci-001", "text-similarity-ada-001", "text-similarity-babbage-001", "text-similarity-curie-001", "text-similarity-davinci-001", "text2vec-base-chinese", "text2vec-base-multilingual", "text2vec-large-chinese", "titan-embed-text-v1", "udever-bloom-1b1", "udever-bloom-560m", "universal-sentence-encoder-multilingual-3", "universal-sentence-encoder-multilingual-large-3", "unsup-simcse-bert-base-uncased", "use-cmlm-multilingual", "voyage-2", "voyage-code-2", "voyage-large-2-instruct", "voyage-law-2", "voyage-lite-01-instruct", "voyage-lite-02-instruct", "xlm-roberta-base", "xlm-roberta-large", ] # Needs to be run whenever new files are added def get_paths(): import collections, json, os files = collections.defaultdict(list) for model_dir in os.listdir("results"): results_model_dir = os.path.join("results", model_dir) if not os.path.isdir(results_model_dir): print(f"Skipping {results_model_dir}") continue for res_file in os.listdir(results_model_dir): if res_file.endswith(".json"): results_model_file = os.path.join(results_model_dir, res_file) files[model_dir].append(results_model_file) with open("paths.json", "w") as f: json.dump(files, f) return files class MTEBResults(datasets.GeneratorBasedBuilder): """MTEBResults""" BUILDER_CONFIGS = [ datasets.BuilderConfig( name=model, description=f"{model} MTEB results", version=VERSION, ) for model in MODELS ] def _info(self): return datasets.DatasetInfo( description=_DESCRIPTION, features=datasets.Features( { "mteb_dataset_name": datasets.Value("string"), "eval_language": datasets.Value("string"), "metric": datasets.Value("string"), "score": datasets.Value("float"), } ), supervised_keys=None, citation=_CITATION, ) def _split_generators(self, dl_manager): path_file = dl_manager.download_and_extract(URL) with open(path_file) as f: files = json.load(f) downloaded_files = dl_manager.download_and_extract(files[self.config.name]) return [ datasets.SplitGenerator( name=datasets.Split.TEST, gen_kwargs={'filepath': downloaded_files} ) ] def _generate_examples(self, filepath): """This function returns the examples in the raw (text) form.""" logger.info(f"Generating examples from {filepath}") out = [] for path in filepath: with open(path, encoding="utf-8") as f: res_dict = json.load(f) ds_name = res_dict["mteb_dataset_name"] split = "test" if (ds_name in TRAIN_SPLIT) and ("train" in res_dict): split = "train" elif (ds_name in VALIDATION_SPLIT) and ("validation" in res_dict): split = "validation" elif (ds_name in DEV_SPLIT) and ("dev" in res_dict): split = "dev" elif (ds_name in TESTFULL_SPLIT) and ("test.full" in res_dict): split = "test.full" elif "test" not in res_dict: print(f"Skipping {ds_name} as split {split} not present.") continue res_dict = res_dict.get(split) is_multilingual = any(x in res_dict for x in EVAL_LANGS) langs = res_dict.keys() if is_multilingual else ["en"] for lang in langs: if lang in SKIP_KEYS: continue test_result_lang = res_dict.get(lang) if is_multilingual else res_dict for metric, score in test_result_lang.items(): if not isinstance(score, dict): score = {metric: score} for sub_metric, sub_score in score.items(): if any(x in sub_metric for x in SKIP_KEYS): continue if isinstance(sub_score, dict): continue out.append({ "mteb_dataset_name": ds_name, "eval_language": lang if is_multilingual else "", "metric": f"{metric}_{sub_metric}" if metric != sub_metric else metric, "score": sub_score * 100, }) for idx, row in enumerate(sorted(out, key=lambda x: x["mteb_dataset_name"])): yield idx, row