{"id":15014177,"url":"https://github.com/surajiyer/spacybert","last_synced_at":"2026-02-17T22:31:41.666Z","repository":{"id":57469512,"uuid":"282694849","full_name":"surajiyer/spacybert","owner":"surajiyer","description":"BERT inference (with similar function to hanxiao/bert-as-service) for spaCy with custom extension attributes","archived":false,"fork":false,"pushed_at":"2020-08-05T18:03:06.000Z","size":9,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-11-21T03:09:05.264Z","etag":null,"topics":["bert","huggingface","huggingface-transformers","language-model","machine-learning","natural-language-processing","nlp","pytorch","pytorch-model","spacy","spacy-extension","spacy-pipeline"],"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/surajiyer.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}},"created_at":"2020-07-26T17:01:42.000Z","updated_at":"2021-03-17T03:54:27.000Z","dependencies_parsed_at":"2022-09-19T10:10:32.517Z","dependency_job_id":null,"html_url":"https://github.com/surajiyer/spacybert","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/surajiyer/spacybert","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/surajiyer%2Fspacybert","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/surajiyer%2Fspacybert/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/surajiyer%2Fspacybert/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/surajiyer%2Fspacybert/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/surajiyer","download_url":"https://codeload.github.com/surajiyer/spacybert/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/surajiyer%2Fspacybert/sbom","scorecard":{"id":860043,"data":{"date":"2025-08-11","repo":{"name":"github.com/surajiyer/spacybert","commit":"8525da8e61a91e6ebe49607929fd5c6e7c821530"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.5,"checks":[{"name":"Code-Review","score":0,"reason":"Found 0/2 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/python-publish.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/surajiyer/spacybert/python-publish.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/python-publish.yml:18: update your workflow using https://app.stepsecurity.io/secureworkflow/surajiyer/spacybert/python-publish.yml/master?enable=pin","Warn: pipCommand not pinned by hash: .github/workflows/python-publish.yml:23","Warn: pipCommand not pinned by hash: .github/workflows/python-publish.yml:24","Info:   0 out of   2 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   2 pipCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/python-publish.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":0,"reason":"23 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-3749-ghw9-m3mg","Warn: Project is vulnerable to: PYSEC-2022-43015 / GHSA-47fc-vmwq-366v","Warn: Project is vulnerable to: PYSEC-2025-41 / GHSA-53q9-r3pm-6pq6","Warn: Project is vulnerable to: PYSEC-2024-252 / GHSA-5pcm-hx3q-hm94","Warn: Project is vulnerable to: GHSA-887c-mr87-cxwp","Warn: Project is vulnerable to: PYSEC-2024-251 / GHSA-pg7h-5qx3-wjr3","Warn: Project is vulnerable to: PYSEC-2024-250","Warn: Project is vulnerable to: PYSEC-2024-259","Warn: Project is vulnerable to: PYSEC-2023-299 / GHSA-282v-666c-3fvg","Warn: Project is vulnerable to: GHSA-37mw-44qp-f5jm","Warn: Project is vulnerable to: GHSA-37q5-v5qm-c9v8","Warn: Project is vulnerable to: PYSEC-2023-300 / GHSA-3863-2447-669p","Warn: Project is vulnerable to: GHSA-6rvg-6v2m-4j46","Warn: Project is vulnerable to: GHSA-9356-575x-2w9m","Warn: Project is vulnerable to: GHSA-fpwr-67px-3qhx","Warn: Project is vulnerable to: PYSEC-2024-229 / GHSA-hxxf-235m-72v3","Warn: Project is vulnerable to: GHSA-jjph-296x-mrcr","Warn: Project is vulnerable to: GHSA-phhr-52qp-3mj4","Warn: Project is vulnerable to: GHSA-q2wp-rjmx-x6x9","Warn: Project is vulnerable to: PYSEC-2025-40 / GHSA-qq3j-4f4f-9583","Warn: Project is vulnerable to: PYSEC-2024-227 / GHSA-qxrp-vhvm-j765","Warn: Project is vulnerable to: PYSEC-2023-301 / GHSA-v68g-wm8c-6x7j","Warn: Project is vulnerable to: PYSEC-2024-228 / GHSA-wrfc-pvp9-mr9g"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-24T00:58:40.350Z","repository_id":57469512,"created_at":"2025-08-24T00:58:40.350Z","updated_at":"2025-08-24T00:58:40.350Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29560756,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-17T21:50:49.831Z","status":"ssl_error","status_checked_at":"2026-02-17T21:46:15.313Z","response_time":100,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["bert","huggingface","huggingface-transformers","language-model","machine-learning","natural-language-processing","nlp","pytorch","pytorch-model","spacy","spacy-extension","spacy-pipeline"],"created_at":"2024-09-24T19:45:17.715Z","updated_at":"2026-02-17T22:31:41.639Z","avatar_url":"https://github.com/surajiyer.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# spacybert: Bert inference for spaCy\n[spaCy v2.0](https://spacy.io/usage/v2) extension and pipeline component for loading BERT sentence / document embedding meta data to `Doc`, `Span` and `Token` objects. The Bert backend itself is supported by the [Hugging Face transformers](https://github.com/huggingface/transformers) library.\n\n## Installation\n`spacybert` requires `spacy` v2.0.0 or higher.\n\n## Usage\n### Getting BERT embeddings for single language dataset\n```\nimport spacy\nfrom spacybert import BertInference\nnlp = spacy.load('en')\n```\n\nThen either use BertInference as part of a pipeline,\n```\nbert = BertInference(\n    from_pretrained='path/to/pretrained_bert_weights_dir',\n    set_extension=False)\nnlp.add_pipe(bert, last=True)\n```\nOr not...\n```\nbert = BertInference(\n    from_pretrained='path/to/pretrained_bert_weights_dir',\n    set_extension=True)\n```\nThe difference is that when `set_extension=True`, `bert_repr` is set as a property extension for the Doc, Span and Token spacy objects. If `set_extension=False`, the `bert_repr` is set as an attribute extension with a default value (`=None`). The attribute computes the correct value when `doc._.bert_repr` is called.\n\nGet the Bert representation / embedding.\n```\ndoc = nlp(\"This is a test\")\nprint(doc._.bert_repr)  # \u003c-- torch.Tensor\n```\n\n### Getting BERT embeddings for multiple languages dataset.\n```\nimport spacy\nfrom spacy_langdetect import LanguageDetector\nfrom spacybert import MultiLangBertInference\n\nnlp = spacy.load('en')\nnlp.add_pipe(LanguageDetector(), name='language_detector', last=True)\nbert = MultiLangBertInference(\n    from_pretrained={\n        'en': 'path/to/en_pretrained_bert_weights_dir',\n        'nl': 'path/to/nl_pretrained_bert_weights_dir'\n    },\n    set_extension=False)\nnlp.add_pipe(bert, after='language_detector')\n\ntexts = [\n    \"This is a test\",  # English\n    \"Dit is een test\"  # Dutch\n]\nfor doc in nlp.pipe(texts):\n    print(doc._.bert_repr)  # \u003c-- torch.Tensor\n```\nWhen language_detector detects languages other than the ones for which pre-trained weights is specified, by default `doc._.bert_repr = None`.\n\n## Available attributes\nThe extension sets attributes on the `Doc`, `Span` and `Token`. You can change the attribute name on initializing the extension.\n| | | |\n|-|-|-|\n| `Doc._.bert_repr` | `torch.Tensor` | Document BERT embedding |\n| `Span._.bert_repr` | `torch.Tensor` | Span BERT embedding |\n| `Token._.bert_repr` | `torch.Tensor` | Token BERT embedding |\n| | | |\n\n## Settings\nOn initialization of `BertInference`, you can define the following:\n\n| name | type | default | description |\n|-|-|-|-|\n| `from_pretrained` | `str` | `None` | Path to Bert model directory or name of HuggingFace transformers pre-trained Bert weights, e.g., `bert-base-uncased` |\n| `attr_name` | `str` | `'bert_repr'` | Name of the BERT embedding attribute to set to the `._` property |\n| `max_seq_len` | `int` | 512 | Max sequence length for input to Bert |\n| `pooling_strategy` | `str` | `'REDUCE_MEAN'` | Strategy to generate single sentence embedding from multiple word embeddings. See below for the various pooling strategies available. |\n| `set_extension` | `bool` | `True` | If `True`, then `'bert_repr'` is set as a property extension for the `Doc`, `Span` and `Token` spacy objects. If `False`, the `'bert_repr'` is set as an attribute extension with a default value (`None`) which gets filled correctly when called in a pipeline. Set it to `False` if you want to use this extension in a spacy pipeline. |\n| `force_extension` | `bool` | `True` | A boolean value to create the same 'Extension Attribute' upon being executed again |\n\nOn initialization of `MultiLangBertInference`, you can define the following:\n\n| name | type | default | description |\n|-|-|-|-|\n| `from_pretrained` | `Dict[LANG_ISO_639_1, str]` | `None` | Mapping between two-letter language codes to path to model directory or HuggingFace transformers pre-trained Bert weights |\n| `attr_name` | `str` | `'bert_repr'` | Same as in BertInference |\n| `max_seq_len` | `int` | 512 | Same as in BertInference |\n| `pooling_strategy` | `str` | `'REDUCE_MEAN'` | Same as in BertInference |\n| `set_extension` | `bool` | `True` | Same as in BertInference |\n| `force_extension` | `bool` | `True` | Same as in BertInference |\n\n## Pooling strategies\n| strategy | description |\n|-|-|\n| `REDUCE_MEAN` | Element-wise average the word embeddings |\n| `REDUCE_MAX` | Element-wise maximum of the word embeddings |\n| `REDUCE_MEAN_MAX` | Apply both `'REDUCE_MEAN'` and `'REDUCE_MAX'` and concatenate. So if the original word embedding is of dimensions `(768,)`, then the output will have shape `(1536,)` |\n| `CLS_TOKEN`, `FIRST_TOKEN` | Take the embedding of only the first `[CLS]` token |\n| `SEP_TOKEN`, `LAST_TOKEN` | Take the embedding of only the last `[SEP]` token |\n| `None` | No reduction is applied and a matrix of embeddings per word in the sentence is returned |\n\n## Roadmap\nThis extension is still experimental. Possible future updates include:\n* Getting document representation from other state-of-the-art NLP models other than Google's BERT.\n* Method for computing similarity between `Doc`, `Span` and `Token` objects using the `bert_repr` tensor.\n* Getting representation from multiple / other layers in the models.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsurajiyer%2Fspacybert","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsurajiyer%2Fspacybert","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsurajiyer%2Fspacybert/lists"}