transformer_onnx
transformers_onnx is a simple package which can use inside transformers pipeline.
Install
pip install transformers_onnx
Convert model into Onnx format
#for question-answering
python -m transformers.onnx --feature "question-answering" -m nlpconnect/roberta-base-squad2-nq ./qa/
#for text-classification or zeroshot classification
python -m transformers.onnx --feature "sequence-classification" -m cross-encoder/nli-roberta-base ./classifier/
#for feature-extraction (last_hidden_state or pooler_output)
python -m transformers.onnx --feature "default" -m nlpconnect/dpr-ctx_encoder_bert_uncased_L-2_H-128_A-2 ./feature/
#for token-classification
python -m transformers.onnx --feature "token-classification" -m dslim/bert-base-NER ./ner/
Use transformers_onnx to run transformers pipeline
Question Answering
from transformers import pipeline, AutoTokenizer, AutoConfig
from transformer_onnx import OnnxModel
model = OnnxModel("qa/model.onnx", task="question-answering")
model.config = AutoConfig.from_pretrained("nlpconnect/roberta-base-squad2-nq")
tokenizer = AutoTokenizer.from_pretrained("nlpconnect/roberta-base-squad2-nq")
qa = pipeline("question-answering", model=model, tokenizer=tokenizer)
# Input data
context = ["Released on 6/03/2021",
"Release delayed until the 11th of August",
"Documentation can be found here: huggingface.com"]
# Define column queries
queries = ["What is Released date?", "till when delayed?", "What is the url?"]
qa(context=context, question=queries)
Text Classification/ Zero shot classification
from transformers import pipeline, AutoTokenizer, AutoConfig
from transformer_onnx import OnnxModel
model = OnnxModel("classifier/model.onnx", task="sequence-classification")
model.config = AutoConfig.from_pretrained("cross-encoder/nli-roberta-base")
tokenizer = AutoTokenizer.from_pretrained("cross-encoder/nli-roberta-base")
zero_shot = pipeline("zero-shot-classification", model=model, tokenizer=tokenizer)
zero_shot(sequences=["Hello Hiiii", "I am playing football"], candidate_labels=["Greeting", "Sports"])
Feature Extraction
from transformers import pipeline, AutoTokenizer, AutoConfig
from transformer_onnx import OnnxModel
# for last_hidden_state
model = OnnxModel("feature/model.onnx", task="last_hidden_state")
tokenizer = AutoTokenizer.from_pretrained("nlpconnect/dpr-ctx_encoder_bert_uncased_L-2_H-128_A-2")
feature_extractor = pipeline("feature-extraction", model=model, tokenizer=tokenizer)
feature_extractor(["Hello Hiiii", "I am playing football"])
# for pooler_output
model = OnnxModel("feature/model.onnx", task="pooler_output")
tokenizer = AutoTokenizer.from_pretrained("nlpconnect/dpr-ctx_encoder_bert_uncased_L-2_H-128_A-2")
feature_extractor = pipeline("feature-extraction", model=model, tokenizer=tokenizer)
feature_extractor(["Hello Hiiii", "I am playing football"])
NER
from transformers import pipeline, AutoTokenizer, AutoConfig
from transformer_onnx import OnnxModel
model = OnnxModel("ner/model.onnx", task="token-classification")
model.config = AutoConfig.from_pretrained("dslim/bert-base-NER")
tokenizer = AutoTokenizer.from_pretrained("dslim/bert-base-NER")
ner = pipeline("token-classification", model=model, tokenizer=tokenizer)
ner("My name is transformers and I live in github/huggingface")
Metadata
Release files for transformers-onnx 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| transformers_onnx-0.0.2.tar.gz | 8.7 kB | Without provenance | Details for transformers_onnx-0.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| transformers_onnx-0.0.2-py3-none-any.whl | Python 3 | none | any | Details for transformers_onnx-0.0.2-py3-none-any.whl |
Total release size: 17.2 kB
Release files / transformers_onnx-0.0.2.tar.gz
| Download URL | transformers_onnx-0.0.2.tar.gz |
|---|---|
| Size | 8.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fafee518ee5a0304b72b29ccc2200a596ca3ed8018c2d108774d4f7a3e9b3f64
|
|
BLAKE2b-256 checksum How to use checksums |
22e52e765580a0f7308739189294c4f7fda141e052a95028382dd76f7d477b5f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.7.13
|
Release files / transformers_onnx-0.0.2-py3-none-any.whl
| Download URL | transformers_onnx-0.0.2-py3-none-any.whl |
|---|---|
| Size | 8.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
16e60fae85c2250d461660ec3b94bec5b122bbb7a41a37a60c61df880f61f006
|
|
BLAKE2b-256 checksum How to use checksums |
f703239688da65ed53b9c2ad33b7eb250d6265998643af9f006e4aba3edfaf9e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.7.13
|
Security for transformers-onnx 0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.