• Stars
    star
    126
  • Rank 282,938 (Top 6 %)
  • Language
    Python
  • License
    GNU General Publi...
  • Created over 2 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Accelerated NLP pipelines for fast inference on CPU and GPU. Built with Transformers, Optimum and ONNX Runtime.

Optimum Transformers

Tests License PyPI

Accelerated NLP pipelines for fast inference 🚀 on CPU and GPU. Built with 🤗Transformers, Optimum and ONNX runtime.

Installation:

With PyPI:

pip install optimum-transformers

Or directly from GitHub:

pip install git+https://github.com/AlekseyKorshuk/optimum-transformers

Usage:

The pipeline API is similar to transformers pipeline with just a few differences which are explained below.

Just provide the path/url to the model, and it'll download the model if needed from the hub and automatically create onnx graph and run inference.

from optimum_transformers import pipeline

# Initialize a pipeline by passing the task name and 
# set onnx to True (default value is also True)
nlp = pipeline("sentiment-analysis", use_onnx=True)
nlp("Transformers and onnx runtime is an awesome combo!")
# [{'label': 'POSITIVE', 'score': 0.999721109867096}]  

Or provide a different model using the model argument.

from optimum_transformers import pipeline

nlp = pipeline("question-answering", model="deepset/roberta-base-squad2", use_onnx=True)
nlp(question="What is ONNX Runtime ?",
         context="ONNX Runtime is a highly performant single inference engine for multiple platforms and hardware")
# {'answer': 'highly performant single inference engine for multiple platforms and hardware', 'end': 94,
# 'score': 0.751201868057251, 'start': 18}
from optimum_transformers import pipeline

nlp = pipeline("ner", model="mys/electra-base-turkish-cased-ner", use_onnx=True, optimize=True,
                    grouped_entities=True)
nlp("adana kebap ülkemizin önemli lezzetlerinden biridir.")
# [{'entity_group': 'B-food', 'score': 0.869149774312973, 'word': 'adana kebap'}]

Set use_onnx to False for standard torch inference. Set optimize to True for quantize with ONNX. ( set use_onnx to True)

Supported pipelines

You can create Pipeline objects for the following down-stream tasks:

  • feature-extraction: Generates a tensor representation for the input sequence
  • ner and token-classification: Generates named entity mapping for each word in the input sequence.
  • sentiment-analysis: Gives the polarity (positive / negative) of the whole input sequence. Can be used for any text classification model.
  • question-answering: Provided some context and a question referring to the context, it will extract the answer to the question in the context.
  • text-classification: Classifies sequences according to a given number of classes from training.
  • zero-shot-classification: Classifies sequences according to a given number of classes directly in runtime.
  • fill-mask: The task of masking tokens in a sequence with a masking token, and prompting the model to fill that mask with an appropriate token.
  • text-generation: The task of generating text according to the previous text provided.

Calling the pipeline for the first time loads the model, creates the onnx graph, and caches it for future use. Due to this, the first load will take some time. Subsequent calls to the same model will load the onnx graph automatically from the cache.

Benchmarks

Note: For some reason, onnx is slow on colab notebook, so you won't notice any speed-up there. Benchmark it on your own hardware.

Check our example of benchmarking: example.

For detailed benchmarks and other information refer to this blog post and notebook.

Note: These results were collected on my local machine. So if you have high performance machine to benchmark, please contact me.

Benchmark sentiment-analysis pipeline

Benchmark zero-shot-classification pipeline

Benchmark token-classification pipeline

Benchmark question-answering pipeline

Benchmark fill-mask pipeline

About

Built by Aleksey Korshuk

Follow

Follow

Follow

🚀 If you want to contribute to this project OR create something cool together — contact me: link

Star this repository:

GitHub stars

Resources

More Repositories

1

yoomoney-api

YooMoney API Python library
Python
229
star
2

huggingnft

Generate NFT or train new model in just few clicks! Train as much as you can, others will resume from checkpoint!
Jupyter Notebook
139
star
3

huggingartists

Lyrics generation with GPT2-based Transformer
Jupyter Notebook
99
star
4

clip-gan

Create music videos using CLIP with BigGAN, DALL-E and StyleGAN
Jupyter Notebook
50
star
5

role-play-synthetic

Synthetic Role-Play Conversation Dataset Generation
Python
24
star
6

chat-data-pipeline

Chat data cleaning, filtering and deduplication pipeline.
Python
11
star
7

Slaves-Vk-MiniApp-Bot

8
star
8

accompaniment-generator

Generate accompaniment part with chords using Evolutionary algorithm.
Python
7
star
9

gai-project

Train expert conversational role-play LLMs with synthetic data
Python
6
star
10

numerical-methods

Numerical methods for ordinary differential equations: Euler, Improved Euler, Runge-Kutta.
Python
5
star
11

least-square-approximation

A computer program in C++ programming language to compose a least square approximation.
C++
3
star
12

graph-adt

Graph ADT and its implementation based on adjacency matrix
C++
3
star
13

snowball-fight

Python
3
star
14

tenderhack-volat

TenderHack: рекомендательный сервис для публикации и участия в закупках
CSS
3
star
15

FSAtoRegExp

FSA to RegExp Translator
Python
2
star
16

GymGo

Python
2
star
17

AlekseyKorshuk

2
star
18

VOLAT

C++
2
star
19

os-course

C
2
star
20

studying-notes

Studying notes from my learning journey
2
star
21

AlekseyKorshuk.github.io

HTML
2
star
22

vision-ai

Derive insights from your images in the cloud or at the edge with Vertex AI’s vision capabilities powered by AutoML, or use pre-trained Vision API models to detect emotion, understand text, and more.
2
star
23

dgp

Decision Genetic Programming - Solving OpenAI Gyms
Python
1
star
24

WgForgeDocker

WGForge homework: docker, database.
Python
1
star
25

database-course

PLpgSQL
1
star
26

agi-poe

Python
1
star
27

aml-faster-rcnn-vs-yolovx

Applied Machine Learning Assignment: Comparison of Faster RCNN and Yolovx
Jupyter Notebook
1
star