Skip to main content

Wrappers for including pre-trained transformers in spaCy pipelines

Project description

spaCy-wrap: For Wrapping fine-tuned transformers in spaCy pipelines

PyPI version python version Code style: black github actions pytest github actions docs github coverage CodeFactor

Installation

Installing spacy-wrap is simple using pip:

pip install spacy_wrap

There is no reason to update from GitHub as the version on PyPI should always be the same as on GitHub.

Simple Example

The following shows a simple example of how you can quickly add a finetuned transformer model from the Huggingface model hub. In this case we will add the Hate speech model for Danish to a blank Danish pipeline.

import spacy
import spacy_wrap

nlp = spacy.blank("da")

config = {
    "doc_extension_trf_data": "clf_trf_data",  # document extention for the forward pass
    "doc_extension_prediction": "hate_speech",  # document extention for the prediction
    "labels": ["Not hate Speech", "Hate speech"],
    "model": {
        "name": "DaNLP/da-bert-hatespeech-detection",  # the model name or path of huggingface model
    },
}

transformer = nlp.add_pipe("classification_transformer", config=config)
transformer.model.initialize()

doc = nlp("Senile gamle idiot") # old senile idiot

doc._.clf_trf_data
# TransformerData(wordpieces=...
doc._.hate_speech
# "Hate speech"
doc._.hate_speech_prob
# {'prob': array([0.013, 0.987], dtype=float32), 'labels': ['Not hate Speech', 'Hate speech']}

📖 Documentation

Documentation
🔧 Installation Installation instructions for spacy-wrap
📚 Usage Guides Guides and instructions on how to use spacy-wrap and its features.
📰 News and changelog New additions, changes and version history.
🎛 Documentation The detailed reference for spacy-wrap's API. Including function documentation

💬 Where to ask questions

Type
🚨 FAQ FAQ
🚨 Bug Reports GitHub Issue Tracker
🎁 Feature Requests & Ideas GitHub Issue Tracker
👩‍💻 Usage Questions GitHub Discussions
🗯 General Discussion GitHub Discussions

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spacy-wrap-0.0.2.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

spacy_wrap-0.0.2-py2.py3-none-any.whl (9.1 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file spacy-wrap-0.0.2.tar.gz.

File metadata

  • Download URL: spacy-wrap-0.0.2.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.10

File hashes

Hashes for spacy-wrap-0.0.2.tar.gz
Algorithm Hash digest
SHA256 9c347e72268d01b094d40358bda35a21de78161e490c4e0cb2d08a6c1c5d0b8c
MD5 4767a707a2cfe81e3acfec5301e02100
BLAKE2b-256 fa94035bc4d1f7209c4a552d5efd2a0c3bbe5296edec1acdf14df1fbca682673

See more details on using hashes here.

File details

Details for the file spacy_wrap-0.0.2-py2.py3-none-any.whl.

File metadata

  • Download URL: spacy_wrap-0.0.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.10

File hashes

Hashes for spacy_wrap-0.0.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 3eaac1f11d79641f71e2bdcf676d64a044059c83bf63abdb0cd0dee029d5c0de
MD5 49c07a0d42a4f6716b24e1a9158e7d15
BLAKE2b-256 f577d4904d13257686956a2801be1577ebd60d75974b1ec5ed9367b77b65331a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page