{"id":20772210,"url":"https://github.com/flairnlp/transformer-ranker","last_synced_at":"2025-04-04T12:09:05.444Z","repository":{"id":251909846,"uuid":"832616665","full_name":"flairNLP/transformer-ranker","owner":"flairNLP","description":"Efficiently find the best-suited language model (LM) for your NLP task","archived":false,"fork":false,"pushed_at":"2025-03-27T11:37:33.000Z","size":173,"stargazers_count":121,"open_issues_count":4,"forks_count":9,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-28T11:11:05.726Z","etag":null,"topics":["language-models","transferability","transferability-estimation"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/flairNLP.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-23T11:31:50.000Z","updated_at":"2025-03-27T11:37:37.000Z","dependencies_parsed_at":"2024-08-06T13:49:28.681Z","dependency_job_id":"e2a7a87f-a57a-4e9a-99eb-4330631def75","html_url":"https://github.com/flairNLP/transformer-ranker","commit_stats":{"total_commits":67,"total_committers":4,"mean_commits":16.75,"dds":0.4029850746268657,"last_synced_commit":"654ea83729197b930236463512850f1224010f57"},"previous_names":["flairnlp/transformer-ranker"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flairNLP%2Ftransformer-ranker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flairNLP%2Ftransformer-ranker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flairNLP%2Ftransformer-ranker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flairNLP%2Ftransformer-ranker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flairNLP","download_url":"https://codeload.github.com/flairNLP/transformer-ranker/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247174423,"owners_count":20896078,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["language-models","transferability","transferability-estimation"],"created_at":"2024-11-17T12:19:45.079Z","updated_at":"2025-04-04T12:09:05.439Z","avatar_url":"https://github.com/flairNLP.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003eA very simple library that helps you find the \u003cb\u003ebest-suited language model\u003c/b\u003e for your NLP task.\nDeveloped at \u003ca href=\"https://www.informatik.hu-berlin.de/en/forschung-en/gebiete/ml-en/\"\u003eHumboldt University of Berlin\u003c/a\u003e.\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://pypi.org/project/transformer-ranker/\"\u003e\u003cimg alt=\"PyPi version\" src=\"https://badge.fury.io/py/transformer-ranker.svg\"\u003e\u003c/a\u003e\n\u003cimg alt=\"python\" src=\"https://img.shields.io/badge/python-3.9-blue\"\u003e\n\u003cimg alt=\"Static Badge\" src=\"https://img.shields.io/badge/license-MIT-green\"\u003e\n\u003ca href=\"https://huggingface.co/spaces/lukasgarbas/transformer-ranker\"\u003e\u003cimg alt=\"Demo Spaces\" src=\"https://img.shields.io/badge/Demo-Spaces-brightgreen\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\u003cdiv align=\"center\"\u003e\n\u003chr\u003e\n\n[Quick Start](#quick-start) | [Tutorials](#tutorials) | [Demonstration Paper](https://arxiv.org/abs/2409.05997) | [Approach Paper](https://aclanthology.org/2024.findings-acl.757/)\n\n\u003c/div\u003e\n\n\n---\n**The problem**: There are too many pre-trained language models (LMs) out there.\nBut which one of them is best for your NLP classification task? \nSince fine-tuning LMs is costly, it is not possible to try them all!  \n\n**The solution**: *Transferability estimation* with TransformerRanker!\n\n---\nTransformerRanker is a library that\n\n* **quickly finds the best-suited language model for a given NLP classification task.** \n  All you need to do is to select a [dataset](https://huggingface.co/datasets) and a list of pre-trained [language models](https://huggingface.co/models) (LMs) from the 🤗 HuggingFace Hub. TransformerRanker will quickly estimate which of these LMs will perform best on the given task!\n\n* **efficiently performs layerwise analysis of LMs.** Transformer LMs have many layers. Use TransformerRanker to identify which intermediate layer\n  is best-suited for a downstream task!\n\n\u003chr\u003e \n\n## Quick Start\n\nTo install from pip, simply do:\n\n```python3\npip install transformer-ranker\n```\n\n## Example 1: Find the best LM for Named Entity Recognition \n\nLet's say we want to find the best LM for English Named Entity Recognition (NER) on the popular CoNLL-03 dataset. \n\nTo keep this example simple, we use TransformerRanker to only choose between two models: `bert-base-cased` and `bert-base-uncased`. \n\nThe full snippet to do so is as follows: \n\n```python3\nfrom datasets import load_dataset\nfrom transformer_ranker import TransformerRanker\n\n# Step 1: Load the CoNLL-03 dataset from HuggingFace\ndataset = load_dataset('conll2003')\n\n# Step 2: Define the LMs to choose from \nlanguage_models = [\"bert-base-cased\", \"bert-base-uncased\"]\n\n# Step 3: Initialize the ranker with the dataset \nranker = TransformerRanker(dataset, dataset_downsample=0.2)\n\n# ... and run the ranker to obtain the ranking\nresults = ranker.run(language_models, batch_size=64)\n```\n\nIf you run this snippet for the first time, it will first download the CoNLL-03 dataset from HuggingFace, and also \ndownload the two transformer LMs. It will then conduct the estimation for the two LMs. On a GPU-enabled Google Colab \nnotebook, this should only take a minute or two. \n\nPrint the results by doing\n\n```python3\nprint(results)\n```\n\nThis should print: \n\n```console\nRank 1. bert-base-uncased: 2.5935\nRank 2. bert-base-cased: 2.5137\n```\n\nThis indicates that the uncased variant of BERT is likely to perform better on CoNLL-03!\n\n\n## Example 2: Really find the best LM \n\nThe first example was kept simple: we only chose between two LMs. But in practical use cases, you might want to\nchoose between **dozens** of LMs. \n\nTo help you get started, we compiled two lists of popular LMs that in our opinion are good LMs to try:\n1. A 'base' list that contains 17 popular models of medium size.\n2. A 'large' list that contains popular models of larger size.\n   \nTo find the best LM for English NER among 17 base LMs, use the following snippet:\n\n```python3\nfrom datasets import load_dataset\nfrom transformer_ranker import TransformerRanker, prepare_popular_models\n\n# Step 1: Load the CoNLL-03 dataset from HuggingFace\ndataset = load_dataset('conll2003')\n\n# Step 2: Use our list of 17 'base' LMs as candidates \nlanguage_models = prepare_popular_models('base')\n\n# Step 3: Initialize the ranker with the dataset \nranker = TransformerRanker(dataset, dataset_downsample=0.2)\n\n# ... and run the ranker to obtain the ranking\nresults = ranker.run(language_models, batch_size=64)\n\n# print the ranking\nprint(results)\n```\n\nDone! This will print: \n\n```console\nRank 1. microsoft/deberta-v3-base: 2.6739\nRank 2. google/electra-base-discriminator: 2.6115\nRank 3. microsoft/mdeberta-v3-base: 2.6099\nRank 4. roberta-base: 2.5919\nRank 5. typeform/distilroberta-base-v2: 2.5834\nRank 6. sentence-transformers/all-mpnet-base-v2: 2.5709\nRank 7. bert-base-cased: 2.5137\nRank 8. FacebookAI/xlm-roberta-base: 2.4894\nRank 9. Twitter/twhin-bert-base: 2.4261\nRank 10. german-nlp-group/electra-base-german-uncased: 2.2517\nRank 11. distilbert-base-cased: 2.1989\nRank 12. sentence-transformers/all-MiniLM-L12-v2: 2.1957\nRank 13. Lianglab/PharmBERT-cased: 2.1945\nRank 14. google/electra-small-discriminator: 1.945\nRank 15. KISTI-AI/scideberta: 1.9175\nRank 16. SpanBERT/spanbert-base-cased: 1.7301\nRank 17. dmis-lab/biobert-base-cased-v1.2: 1.5784\n```\n\nThis ranking gives you an indication which models might perform best on CoNLL-03.\nAccordingly, you can exclude the lower-ranked models and focus on the top-ranked models.\n\n*Note:* Doing estimation for all 17 base models will take about 15 minutes on a GPU-enabled Colab Notebook (most time is spent \ndownloading the models if you don't already have them locally). \n\n\n\n## Tutorials\n\nWe provide **tutorials** to introduce the library and key concepts:\n\n1. [**Tutorial 1: Library Walkthrough**](docs/01-walkthrough.md)\n2. [**Tutorial 2: Learn by Example**](docs/02-examples.md)\n3. [**Tutorial 3: Advanced**](docs/03-advanced.md)\n\n## Cite\n\nPlease cite the following [paper](https://arxiv.org/abs/2409.05997) when using TransformerRanker or building upon our work:\n\n```bibtex\n@misc{garbas2024transformerrankertoolefficientlyfinding,\n      title={TransformerRanker: A Tool for Efficiently Finding the Best-Suited Language Models for Downstream Classification Tasks}, \n      author={Lukas Garbas and Max Ploner and Alan Akbik},\n      year={2024},\n      eprint={2409.05997},\n      archivePrefix={arXiv},\n      primaryClass={cs.CL},\n      url={https://arxiv.org/abs/2409.05997}, \n}\n```\n\n## Contact\n\nPlease email your questions or comments to [**Lukas Garbas**](mailto:lukas.garbaciauskas@informatik.hu-berlin.de?subject=[GitHub]%20TransformerRanker)\n\n## Contributing\n\nThanks for your interest in contributing! There are many ways to get involved;\ncheck these [open issues](https://github.com/flairNLP/transformer-ranker/issues) for specific tasks.\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflairnlp%2Ftransformer-ranker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflairnlp%2Ftransformer-ranker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflairnlp%2Ftransformer-ranker/lists"}