{"id":14333193,"url":"https://github.com/ankane/transformers-ruby","last_synced_at":"2025-11-17T14:22:00.190Z","repository":{"id":253842763,"uuid":"844675956","full_name":"ankane/transformers-ruby","owner":"ankane","description":"State-of-the-art transformers for Ruby","archived":false,"fork":false,"pushed_at":"2024-12-29T22:43:32.000Z","size":183,"stargazers_count":710,"open_issues_count":1,"forks_count":11,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-04-14T22:21:43.261Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ankane.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","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-08-19T18:41:02.000Z","updated_at":"2025-04-09T00:16:12.000Z","dependencies_parsed_at":"2024-12-28T08:02:12.533Z","dependency_job_id":"53e5732a-1400-4bb7-aaca-6c813bbfb687","html_url":"https://github.com/ankane/transformers-ruby","commit_stats":{"total_commits":56,"total_committers":3,"mean_commits":"18.666666666666668","dds":0.0357142857142857,"last_synced_commit":"2fc03da8537d572a9a06c67502d4e3f6ea27a9ec"},"previous_names":["ankane/transformers-ruby"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Ftransformers-ruby","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Ftransformers-ruby/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Ftransformers-ruby/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Ftransformers-ruby/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ankane","download_url":"https://codeload.github.com/ankane/transformers-ruby/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254337613,"owners_count":22054253,"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":[],"created_at":"2024-08-25T18:00:45.162Z","updated_at":"2025-11-17T14:21:55.159Z","avatar_url":"https://github.com/ankane.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"# Transformers.rb\n\n:slightly_smiling_face: State-of-the-art [transformers](https://github.com/huggingface/transformers) for Ruby\n\nFor fast inference, check out [Informers](https://github.com/ankane/informers) :fire:\n\n[![Build Status](https://github.com/ankane/transformers-ruby/actions/workflows/build.yml/badge.svg)](https://github.com/ankane/transformers-ruby/actions)\n\n## Installation\n\nFirst, [install Torch.rb](https://github.com/ankane/torch.rb#installation).\n\nThen add this line to your application’s Gemfile:\n\n```ruby\ngem \"transformers-rb\"\n```\n\n## Getting Started\n\n- [Models](#models)\n- [Pipelines](#pipelines)\n\n## Models\n\nEmbedding\n\n- [sentence-transformers/all-MiniLM-L6-v2](#sentence-transformersall-MiniLM-L6-v2)\n- [sentence-transformers/multi-qa-MiniLM-L6-cos-v1](#sentence-transformersmulti-qa-MiniLM-L6-cos-v1)\n- [sentence-transformers/all-mpnet-base-v2](#sentence-transformersall-mpnet-base-v2)\n- [sentence-transformers/paraphrase-MiniLM-L6-v2](#sentence-transformersparaphrase-minilm-l6-v2)\n- [mixedbread-ai/mxbai-embed-large-v1](#mixedbread-aimxbai-embed-large-v1)\n- [thenlper/gte-small](#thenlpergte-small)\n- [intfloat/e5-base-v2](#intfloate5-base-v2)\n- [BAAI/bge-base-en-v1.5](#baaibge-base-en-v15)\n- [Snowflake/snowflake-arctic-embed-m-v1.5](#snowflakesnowflake-arctic-embed-m-v15)\n\nSparse embedding\n\n- [opensearch-project/opensearch-neural-sparse-encoding-v1](#opensearch-projectopensearch-neural-sparse-encoding-v1)\n\nReranking\n\n- [mixedbread-ai/mxbai-rerank-base-v1](#mixedbread-aimxbai-rerank-base-v1)\n- [BAAI/bge-reranker-base](#baaibge-reranker-base)\n\n### sentence-transformers/all-MiniLM-L6-v2\n\n[Docs](https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2)\n\n```ruby\nsentences = [\"This is an example sentence\", \"Each sentence is converted\"]\n\nmodel = Transformers.pipeline(\"embedding\", \"sentence-transformers/all-MiniLM-L6-v2\")\nembeddings = model.(sentences)\n```\n\n### sentence-transformers/multi-qa-MiniLM-L6-cos-v1\n\n[Docs](https://huggingface.co/sentence-transformers/multi-qa-MiniLM-L6-cos-v1)\n\n```ruby\nquery = \"How many people live in London?\"\ndocs = [\"Around 9 Million people live in London\", \"London is known for its financial district\"]\n\nmodel = Transformers.pipeline(\"embedding\", \"sentence-transformers/multi-qa-MiniLM-L6-cos-v1\")\nquery_embedding = model.(query)\ndoc_embeddings = model.(docs)\nscores = doc_embeddings.map { |e| e.zip(query_embedding).sum { |d, q| d * q } }\ndoc_score_pairs = docs.zip(scores).sort_by { |d, s| -s }\n```\n\n### sentence-transformers/all-mpnet-base-v2\n\n[Docs](https://huggingface.co/sentence-transformers/all-mpnet-base-v2)\n\n```ruby\nsentences = [\"This is an example sentence\", \"Each sentence is converted\"]\n\nmodel = Transformers.pipeline(\"embedding\", \"sentence-transformers/all-mpnet-base-v2\")\nembeddings = model.(sentences)\n```\n\n### sentence-transformers/paraphrase-MiniLM-L6-v2\n\n[Docs](https://huggingface.co/sentence-transformers/paraphrase-MiniLM-L6-v2)\n\n```ruby\nsentences = [\"This is an example sentence\", \"Each sentence is converted\"]\n\nmodel = Transformers.pipeline(\"embedding\", \"sentence-transformers/paraphrase-MiniLM-L6-v2\")\nembeddings = model.(sentences)\n```\n\n### mixedbread-ai/mxbai-embed-large-v1\n\n[Docs](https://huggingface.co/mixedbread-ai/mxbai-embed-large-v1)\n\n```ruby\nquery_prefix = \"Represent this sentence for searching relevant passages: \"\n\ninput = [\n  \"The dog is barking\",\n  \"The cat is purring\",\n  query_prefix + \"puppy\"\n]\n\nmodel = Transformers.pipeline(\"embedding\", \"mixedbread-ai/mxbai-embed-large-v1\")\nembeddings = model.(input)\n```\n\n### thenlper/gte-small\n\n[Docs](https://huggingface.co/thenlper/gte-small)\n\n```ruby\nsentences = [\"That is a happy person\", \"That is a very happy person\"]\n\nmodel = Transformers.pipeline(\"embedding\", \"thenlper/gte-small\")\nembeddings = model.(sentences)\n```\n\n### intfloat/e5-base-v2\n\n[Docs](https://huggingface.co/intfloat/e5-base-v2)\n\n```ruby\ndoc_prefix = \"passage: \"\nquery_prefix = \"query: \"\n\ninput = [\n  doc_prefix + \"Ruby is a programming language created by Matz\",\n  query_prefix + \"Ruby creator\"\n]\n\nmodel = Transformers.pipeline(\"embedding\", \"intfloat/e5-base-v2\")\nembeddings = model.(input)\n```\n\n### BAAI/bge-base-en-v1.5\n\n[Docs](https://huggingface.co/BAAI/bge-base-en-v1.5)\n\n```ruby\nquery_prefix = \"Represent this sentence for searching relevant passages: \"\n\ninput = [\n  \"The dog is barking\",\n  \"The cat is purring\",\n  query_prefix + \"puppy\"\n]\n\nmodel = Transformers.pipeline(\"embedding\", \"BAAI/bge-base-en-v1.5\")\nembeddings = model.(input)\n```\n\n### Snowflake/snowflake-arctic-embed-m-v1.5\n\n[Docs](https://huggingface.co/Snowflake/snowflake-arctic-embed-m-v1.5)\n\n```ruby\nquery_prefix = \"Represent this sentence for searching relevant passages: \"\n\ninput = [\n  \"The dog is barking\",\n  \"The cat is purring\",\n  query_prefix + \"puppy\"\n]\n\nmodel = Transformers.pipeline(\"embedding\", \"Snowflake/snowflake-arctic-embed-m-v1.5\")\nembeddings = model.(input, pooling: \"cls\")\n```\n\n### opensearch-project/opensearch-neural-sparse-encoding-v1\n\n[Docs](https://huggingface.co/opensearch-project/opensearch-neural-sparse-encoding-v1)\n\n```ruby\ndocs = [\"The dog is barking\", \"The cat is purring\", \"The bear is growling\"]\n\nmodel_id = \"opensearch-project/opensearch-neural-sparse-encoding-v1\"\nmodel = Transformers::AutoModelForMaskedLM.from_pretrained(model_id)\ntokenizer = Transformers::AutoTokenizer.from_pretrained(model_id)\nspecial_token_ids = tokenizer.special_tokens_map.map { |_, token| tokenizer.vocab[token] }\n\nfeature = tokenizer.(docs, padding: true, truncation: true, return_tensors: \"pt\", return_token_type_ids: false)\noutput = model.(**feature)[0]\n\nvalues, _ = Torch.max(output * feature[:attention_mask].unsqueeze(-1), dim: 1)\nvalues = Torch.log(1 + Torch.relu(values))\nvalues[0.., special_token_ids] = 0\nembeddings = values.to_a\n```\n\n### mixedbread-ai/mxbai-rerank-base-v1\n\n[Docs](https://huggingface.co/mixedbread-ai/mxbai-rerank-base-v1)\n\n```ruby\nquery = \"How many people live in London?\"\ndocs = [\"Around 9 Million people live in London\", \"London is known for its financial district\"]\n\nmodel = Transformers.pipeline(\"reranking\", \"mixedbread-ai/mxbai-rerank-base-v1\")\nresult = model.(query, docs)\n```\n\n### BAAI/bge-reranker-base\n\n[Docs](https://huggingface.co/BAAI/bge-reranker-base)\n\n```ruby\nquery = \"How many people live in London?\"\ndocs = [\"Around 9 Million people live in London\", \"London is known for its financial district\"]\n\nmodel = Transformers.pipeline(\"reranking\", \"BAAI/bge-reranker-base\")\nresult = model.(query, docs)\n```\n\n## Pipelines\n\n- [Text](#text)\n- [Vision](#vision)\n\n### Text\n\nEmbedding\n\n```ruby\nembed = Transformers.pipeline(\"embedding\")\nembed.(\"We are very happy to show you the 🤗 Transformers library.\")\n```\n\nReranking\n\n```ruby\nrerank = Informers.pipeline(\"reranking\")\nrerank.(\"Who created Ruby?\", [\"Matz created Ruby\", \"Another doc\"])\n```\n\nNamed-entity recognition\n\n```ruby\nner = Transformers.pipeline(\"ner\")\nner.(\"Ruby is a programming language created by Matz\")\n```\n\nSentiment analysis\n\n```ruby\nclassifier = Transformers.pipeline(\"sentiment-analysis\")\nclassifier.(\"We are very happy to show you the 🤗 Transformers library.\")\n```\n\nQuestion answering\n\n```ruby\nqa = Transformers.pipeline(\"question-answering\")\nqa.(question: \"Who invented Ruby?\", context: \"Ruby is a programming language created by Matz\")\n```\n\nFeature extraction\n\n```ruby\nextractor = Transformers.pipeline(\"feature-extraction\")\nextractor.(\"We are very happy to show you the 🤗 Transformers library.\")\n```\n\n### Vision\n\nImage classification\n\n```ruby\nclassifier = Transformers.pipeline(\"image-classification\")\nclassifier.(\"image.jpg\")\n```\n\nImage feature extraction\n\n```ruby\nextractor = Transformers.pipeline(\"image-feature-extraction\")\nextractor.(\"image.jpg\")\n```\n\n## API\n\nThis library follows the [Transformers Python API](https://huggingface.co/docs/transformers/index). The following model architectures are currently supported:\n\n- BERT\n- DeBERTa-v2\n- DistilBERT\n- MPNet\n- ViT\n- XLM-RoBERTa\n\n## History\n\nView the [changelog](https://github.com/ankane/transformers-ruby/blob/master/CHANGELOG.md)\n\n## Contributing\n\nEveryone is encouraged to help improve this project. Here are a few ways you can help:\n\n- [Report bugs](https://github.com/ankane/transformers-ruby/issues)\n- Fix bugs and [submit pull requests](https://github.com/ankane/transformers-ruby/pulls)\n- Write, clarify, or fix documentation\n- Suggest or add new features\n\nTo get started with development:\n\n```sh\ngit clone https://github.com/ankane/transformers-ruby.git\ncd transformers-ruby\nbundle install\nbundle exec rake download:files\nbundle exec rake test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fankane%2Ftransformers-ruby","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fankane%2Ftransformers-ruby","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fankane%2Ftransformers-ruby/lists"}