{"id":14958361,"url":"https://github.com/centre-for-humanities-computing/stormtrooper","last_synced_at":"2025-10-24T14:31:52.515Z","repository":{"id":187172558,"uuid":"676415670","full_name":"centre-for-humanities-computing/stormtrooper","owner":"centre-for-humanities-computing","description":"Zero/few shot learning components for scikit-learn pipelines with LLMs and transformers.","archived":false,"fork":false,"pushed_at":"2024-11-21T14:10:14.000Z","size":1441,"stargazers_count":14,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-31T02:21:23.446Z","etag":null,"topics":["chatgpt","few-shot-learning","gpt-4","large-language-models","llm","scikit-learn","transformer","transformers","zero-shot-learning"],"latest_commit_sha":null,"homepage":"https://centre-for-humanities-computing.github.io/stormtrooper/","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/centre-for-humanities-computing.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"citation.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-08-09T06:39:40.000Z","updated_at":"2025-01-28T06:57:11.000Z","dependencies_parsed_at":"2024-09-09T15:13:57.858Z","dependency_job_id":null,"html_url":"https://github.com/centre-for-humanities-computing/stormtrooper","commit_stats":{"total_commits":107,"total_committers":1,"mean_commits":107.0,"dds":0.0,"last_synced_commit":"95a5611c3d70dfcb7d7f32c20c0cef0ddfa324c4"},"previous_names":["centre-for-humanities-computing/stormtrooper"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/centre-for-humanities-computing%2Fstormtrooper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/centre-for-humanities-computing%2Fstormtrooper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/centre-for-humanities-computing%2Fstormtrooper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/centre-for-humanities-computing%2Fstormtrooper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/centre-for-humanities-computing","download_url":"https://codeload.github.com/centre-for-humanities-computing/stormtrooper/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237990569,"owners_count":19398452,"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":["chatgpt","few-shot-learning","gpt-4","large-language-models","llm","scikit-learn","transformer","transformers","zero-shot-learning"],"created_at":"2024-09-24T13:16:50.229Z","updated_at":"2025-10-24T14:31:47.451Z","avatar_url":"https://github.com/centre-for-humanities-computing.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg align=\"left\" width=\"82\" height=\"82\" src=\"assets/logo.svg\"\u003e\n\n# stormtrooper\n\n\u003cbr\u003e\nZero/few shot learning components for scikit-learn pipelines with large-language models and transformers.\n\n[Documentation](https://centre-for-humanities-computing.github.io/stormtrooper/)\n\n## New in 1.0.0\n\n### `Trooper`\nThe brand new `Trooper` interface allows you not to have to specify what model type you wish to use.\nStormtrooper will automatically detect the model type from the specified name.\n\n```python\nfrom stormtrooper import Trooper\n\n# This loads a setfit model\nmodel = Trooper(\"all-MiniLM-L6-v2\")\n\n# This loads an OpenAI model\nmodel = Trooper(\"gpt-4\")\n\n# This loads a Text2Text model\nmodel = Trooper(\"google/flan-t5-base\")\n```\n\n### Unified zero and few-shot classification\n\nYou no longer have to specify whether a model should be a few or a zero-shot classifier when initialising it.\nIf you do not pass any training examples, it will be automatically assumed that the model should be zero-shot.\n\n```python\n# This is a zero-shot model\nmodel.fit(None, [\"dog\", \"cat\"])\n\n# This is a few-shot model\nmodel.fit([\"he was a good boy\", \"just lay down on my laptop\"], [\"dog\", \"cat\"])\n\n```\n## Model types\n\nYou can use all sorts of transformer models for few and zero-shot classification in Stormtrooper.\n\n1. Instruction fine-tuned generative models, e.g. `Trooper(\"HuggingFaceH4/zephyr-7b-beta\")`\n2. Encoder models with SetFit, e.g. `Trooper(\"all-MiniLM-L6-v2\")`\n3. Text2Text models e.g. `Trooper(\"google/flan-t5-base\")`\n4. OpenAI models e.g. `Trooper(\"gpt-4\")`\n5. NLI models e.g. `Trooper(\"facebook/bart-large-mnli\")`\n\n## Example usage\n\nFind more in our [docs](https://centre-for-humanities-computing.github.io/stormtrooper/).\n\n```bash\npip install stormtrooper\n```\n\n```python\nfrom stormtrooper import Trooper\n\nclass_labels = [\"atheism/christianity\", \"astronomy/space\"]\nexample_texts = [\n    \"God came down to earth to save us.\",\n    \"A new nebula was recently discovered in the proximity of the Oort cloud.\"\n]\nnew_texts = [\"God bless the reailway workers\", \"The frigate is ready to launch from the spaceport\"]\n\n# Zero-shot classification\nmodel = Trooper(\"google/flan-t5-base\")\nmodel.fit(None, class_labels)\nmodel.predict(new_texts)\n# [\"atheism/christianity\", \"astronomy/space\"]\n\n# Few-shot classification\nmodel = Trooper(\"google/flan-t5-base\")\nmodel.fit(example_texts, class_labels)\nmodel.predict(new_texts)\n# [\"atheism/christianity\", \"astronomy/space\"]\n```\n\n### Fuzzy Matching\n\nGenerative and text2text models by default will fuzzy match results to the closest class label, you can disable this behavior\nby specifying `fuzzy_match=False`.\n\nIf you want fuzzy matching speedup, you should install `python-Levenshtein`.\n\n### Inference on GPU\n\nFrom version 0.2.2 you can run models on GPU.\nYou can specify the device when initializing a model:\n\n```python\nclassifier = Trooper(\"all-MiniLM-L6-v2\", device=\"cuda:0\")\n```\n\n### Inference on multiple GPUs\n\nYou can run a model on multiple devices in order of device priority `GPU -\u003e CPU + Ram -\u003e Disk` and on multiple devices by using the `device_map` argument.\nNote that this only works with text2text and generative models.\n\n```\nmodel = Trooper(\"HuggingFaceH4/zephyr-7b-beta\", device_map=\"auto\")\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcentre-for-humanities-computing%2Fstormtrooper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcentre-for-humanities-computing%2Fstormtrooper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcentre-for-humanities-computing%2Fstormtrooper/lists"}