{"id":18689718,"url":"https://github.com/mrseanryan/entity-classifier","last_synced_at":"2025-11-08T07:30:30.654Z","repository":{"id":218218949,"uuid":"745862628","full_name":"mrseanryan/entity-classifier","owner":"mrseanryan","description":"Classify entities into clusters via embedding vectors, using a given list of category names","archived":false,"fork":false,"pushed_at":"2024-02-12T15:29:27.000Z","size":13,"stargazers_count":1,"open_issues_count":3,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-28T01:49:41.427Z","etag":null,"topics":["classification","classification-algorithm","embedding-vectors","machine-learning"],"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/mrseanryan.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-01-20T11:25:15.000Z","updated_at":"2024-01-21T23:09:52.000Z","dependencies_parsed_at":"2024-11-07T10:55:23.134Z","dependency_job_id":null,"html_url":"https://github.com/mrseanryan/entity-classifier","commit_stats":null,"previous_names":["mrseanryan/entity-classifier"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrseanryan%2Fentity-classifier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrseanryan%2Fentity-classifier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrseanryan%2Fentity-classifier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrseanryan%2Fentity-classifier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mrseanryan","download_url":"https://codeload.github.com/mrseanryan/entity-classifier/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239550286,"owners_count":19657541,"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":["classification","classification-algorithm","embedding-vectors","machine-learning"],"created_at":"2024-11-07T10:44:55.255Z","updated_at":"2025-11-08T07:30:30.624Z","avatar_url":"https://github.com/mrseanryan.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# entity-classifier\nClassify entities into clusters via a zero-shot approach using embedding vectors, using a given list of category names.\n\n- use an embedding to make vectors of entity names\n- use the same embedding to make vectors of category names\n- for each embedding, find the category that has a nearest vector\n- then can classify the entities, for presentation in logical groups\n\n## Approach\n\nCompare words (labels) by examining how close are their encoded vectors:\n\n- the dot product of 2 normalised vectors = cosine Angle\n- cosine distance = 1 - v.w\n  - smaller means closer\n\n## Dependencies\n\n- Python 3.11\n- pyenv - if on Windows use [pyenv-win](https://github.com/pyenv-win/pyenv-win)\n\n## Install\n\nSwitch to Python 3.11.6:\n\n```\npyenv install 3.11.6\npyenv local 3.11.6\n```\n\nSetup a virtual environment:\n\n```\n./create_env.sh\n```\n\nInstall SBERT and cornsnake via this pip command:\n\n```\npip install -U sentence-transformers==2.2.2 cornsnake==0.0.26\n```\n\n## Usage\n\n```\npython main.py \u003cpath to category list file\u003e \u003cpath to entity names file\u003e [threshold (number between 0 and 1)]\n```\n\n## Example\n\nTo test:\n\n```\n./test.sh\n```\n\nOUTPUT:\n\n```\nCATEGORY: (unknown)\n  entity ['Aardvark', 'Alpaca', 'Anaconda']\nCATEGORY: animal\n  entity ['Albatross', 'Alligator', 'Ant', 'Zebu']\nCATEGORY: country\n  entity ['Albania', 'Andorra', 'Angola', 'Austria', 'Bangladesh', 'Belgium']\n```\n\nThe results are not perfect, but not bad considering this is a simple 'out of the box' solution.\n\n## Further improvements\n\nHierarchy of labels:\n\n- first, classify against a top-level list of labels\n- then, for each label, classify against that labels list of sub-labels\n\nIncrease accuracy:\n\n- take several embeddings per class and use their average for that class\n- try different embeddings, can get better results\n- try different distance measures from your library\n- consider tuning the embedding (for example, for the domain vocabulary of a particular industry or problem space)\n\n# References\n\n[My Medium article](https://medium.com/@mr.sean.ryan/classify-entities-via-a-zero-shot-approach-using-embedding-encodings-7ee9ee6e6bf2)\n\n[Conference notes from ML Con Berlin 2023](https://github.com/mrseanryan/dev-conferences/blob/master/2023/mlcon-berlin/talk-Embeddings-Intro.md/README.md)\n\n[SBERT: How to Use Sentence Embeddings to Solve Real-World Problems](https://anirbansen2709.medium.com/sbert-how-to-use-sentence-embeddings-to-solve-real-world-problems-f950aa300c72)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrseanryan%2Fentity-classifier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrseanryan%2Fentity-classifier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrseanryan%2Fentity-classifier/lists"}