{"id":13878528,"url":"https://github.com/ankane/mitie-ruby","last_synced_at":"2025-11-17T14:08:15.230Z","repository":{"id":43067705,"uuid":"295525650","full_name":"ankane/mitie-ruby","owner":"ankane","description":"Named-entity recognition for Ruby","archived":false,"fork":false,"pushed_at":"2025-11-10T21:11:34.000Z","size":92,"stargazers_count":178,"open_issues_count":0,"forks_count":7,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-11-10T23:11:53.533Z","etag":null,"topics":["named-entity-recognition","ner"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsl-1.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2020-09-14T20:03:01.000Z","updated_at":"2025-11-10T21:11:30.000Z","dependencies_parsed_at":"2024-07-27T05:33:32.287Z","dependency_job_id":"735d0961-e86e-48c1-8b6e-55ae70388a8f","html_url":"https://github.com/ankane/mitie-ruby","commit_stats":{"total_commits":108,"total_committers":3,"mean_commits":36.0,"dds":"0.35185185185185186","last_synced_commit":"6c888e1afd9cffebb0a56f43b5da840050fdc730"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/ankane/mitie-ruby","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fmitie-ruby","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fmitie-ruby/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fmitie-ruby/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fmitie-ruby/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ankane","download_url":"https://codeload.github.com/ankane/mitie-ruby/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fmitie-ruby/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":284893619,"owners_count":27080542,"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","status":"online","status_checked_at":"2025-11-17T02:00:06.431Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["named-entity-recognition","ner"],"created_at":"2024-08-06T08:01:52.200Z","updated_at":"2025-11-17T14:08:15.215Z","avatar_url":"https://github.com/ankane.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"# MITIE Ruby\n\n[MITIE](https://github.com/mit-nlp/MITIE) - named-entity recognition, binary relation detection, and text categorization - for Ruby\n\n- Finds people, organizations, and locations in text\n- Detects relationships between entities, like `PERSON` was born in `LOCATION`\n\n[![Build Status](https://github.com/ankane/mitie-ruby/actions/workflows/build.yml/badge.svg)](https://github.com/ankane/mitie-ruby/actions)\n\n## Installation\n\nAdd this line to your application’s Gemfile:\n\n```ruby\ngem \"mitie\"\n```\n\nAnd download the pre-trained models for your language:\n\n- [English](https://github.com/mit-nlp/MITIE/releases/download/v0.4/MITIE-models-v0.2.tar.bz2)\n- [Spanish](https://github.com/mit-nlp/MITIE/releases/download/v0.4/MITIE-models-v0.2-Spanish.zip)\n- [German](https://github.com/mit-nlp/MITIE/releases/download/v0.4/MITIE-models-v0.2-German.tar.bz2)\n\n## Getting Started\n\n- [Named Entity Recognition](#named-entity-recognition)\n- [Binary Relation Detection](#binary-relation-detection)\n- [Text Categorization](#text-categorization)\n\n## Named Entity Recognition\n\nLoad an NER model\n\n```ruby\nmodel = Mitie::NER.new(\"ner_model.dat\")\n```\n\nCreate a document\n\n```ruby\ndoc = model.doc(\"Nat works at GitHub in San Francisco\")\n```\n\nGet entities\n\n```ruby\ndoc.entities\n```\n\nThis returns\n\n```ruby\n[\n  {text: \"Nat\",           tag: \"PERSON\",       score: 0.3112371212688382, offset: 0},\n  {text: \"GitHub\",        tag: \"ORGANIZATION\", score: 0.5660115198329334, offset: 13},\n  {text: \"San Francisco\", tag: \"LOCATION\",     score: 1.3890524313885309, offset: 23}\n]\n```\n\nGet tokens\n\n```ruby\ndoc.tokens\n```\n\nGet tokens and their offset\n\n```ruby\ndoc.tokens_with_offset\n```\n\nGet all tags for a model\n\n```ruby\nmodel.tags\n```\n\n### Training\n\nLoad an NER model into a trainer\n\n```ruby\ntrainer = Mitie::NERTrainer.new(\"total_word_feature_extractor.dat\")\n```\n\nCreate training instances\n\n```ruby\ntokens = [\"You\", \"can\", \"do\", \"machine\", \"learning\", \"in\", \"Ruby\", \"!\"]\ninstance = Mitie::NERTrainingInstance.new(tokens)\ninstance.add_entity(3..4, \"topic\")    # machine learning\ninstance.add_entity(6..6, \"language\") # Ruby\n```\n\nAdd the training instances to the trainer\n\n```ruby\ntrainer.add(instance)\n```\n\nTrain the model\n\n```ruby\nmodel = trainer.train\n```\n\nSave the model\n\n```ruby\nmodel.save_to_disk(\"ner_model.dat\")\n```\n\n## Binary Relation Detection\n\nDetect relationships betweens two entities, like:\n\n- `PERSON` was born in `LOCATION`\n- `ORGANIZATION` was founded in `LOCATION`\n- `FILM` was directed by `PERSON`\n\nThere are 21 detectors for English. You can find them in the `binary_relations` directory in the model download.\n\nLoad a detector\n\n```ruby\ndetector = Mitie::BinaryRelationDetector.new(\"rel_classifier_organization.organization.place_founded.svm\")\n```\n\nAnd create a document\n\n```ruby\ndoc = model.doc(\"Shopify was founded in Ottawa\")\n```\n\nGet relations\n\n```ruby\ndetector.relations(doc)\n```\n\nThis returns\n\n```ruby\n[{first: \"Shopify\", second: \"Ottawa\", score: 0.17649169745814464}]\n```\n\n### Training\n\nLoad an NER model into a trainer\n\n```ruby\ntrainer = Mitie::BinaryRelationTrainer.new(model)\n```\n\nAdd positive and negative examples to the trainer\n\n```ruby\ntokens = [\"Shopify\", \"was\", \"founded\", \"in\", \"Ottawa\"]\ntrainer.add_positive_binary_relation(tokens, 0..0, 4..4)\ntrainer.add_negative_binary_relation(tokens, 4..4, 0..0)\n```\n\nTrain the detector\n\n```ruby\ndetector = trainer.train\n```\n\nSave the detector\n\n```ruby\ndetector.save_to_disk(\"binary_relation_detector.svm\")\n```\n\n## Text Categorization\n\nLoad a model into a trainer\n\n```ruby\ntrainer = Mitie::TextCategorizerTrainer.new(\"total_word_feature_extractor.dat\")\n```\n\nAdd labeled text to the trainer\n\n```ruby\ntrainer.add(\"This is super cool\", \"positive\")\n```\n\nTrain the model\n\n```ruby\nmodel = trainer.train\n```\n\nSave the model\n\n```ruby\nmodel.save_to_disk(\"text_categorization_model.dat\")\n```\n\nLoad a saved model\n\n```ruby\nmodel = Mitie::TextCategorizer.new(\"text_categorization_model.dat\")\n```\n\nCategorize text\n\n```ruby\nmodel.categorize(\"What a super nice day\")\n```\n\n## Deployment\n\nCheck out [Trove](https://github.com/ankane/trove) for deploying models.\n\n```sh\ntrove push ner_model.dat\n```\n\n## History\n\nView the [changelog](https://github.com/ankane/mitie-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/mitie-ruby/issues)\n- Fix bugs and [submit pull requests](https://github.com/ankane/mitie-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/mitie-ruby.git\ncd mitie-ruby\nbundle install\nbundle exec rake vendor:all\n\nexport MITIE_MODELS_PATH=path/to/MITIE-models/english\nbundle exec rake test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fankane%2Fmitie-ruby","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fankane%2Fmitie-ruby","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fankane%2Fmitie-ruby/lists"}