mwitiderrick commited on
Commit
10e9596
1 Parent(s): 38d0523

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -8
app.py CHANGED
@@ -5,7 +5,7 @@ import gradio as gr
5
  markdownn = '''
6
  # Text Classification Pipeline with DeepSparse
7
  DeepSparse is sparsity-aware inference runtime offering GPU-class performance on CPUs and APIs to integrate ML into your application. DeepSparse provides sparsified pipelines for computer vision and NLP.
8
- The pipelines are similar to Hugging Face pipelines but are faster because they have been pruned and quantized. Here is a sample code for a question-answering pipeline:
9
  ```
10
  from deepsparse import Pipeline
11
  pipeline = pipeline.create(task="text-classification", model_path="zoo:nlp/text_classification/bert-base_cased/pytorch/huggingface/mnli/pruned90_quant-none")
@@ -13,27 +13,31 @@ inference = pipeline(text)
13
  print(inference)
14
  ```
15
  '''
16
- task = "text-classification"
17
  dense_classification_pipeline = Pipeline.create(
18
  task=task,
19
- model_path="zoo:nlp/text_classification/bert-base_cased/pytorch/huggingface/mnli/base-none",
 
 
20
  )
21
 
22
  sparse_classification_pipeline = Pipeline.create(
23
  task=task,
24
- model_path="zoo:nlp/text_classification/bert-base_cased/pytorch/huggingface/mnli/pruned90_quant-none",
 
 
25
  )
26
  def run_pipeline(text):
27
  dense_start = time.perf_counter()
28
 
29
- dense_output = dense_classification_pipeline([text])
30
  dense_result = dict(dense_output)
31
  dense_end = time.perf_counter()
32
  dense_duration = (dense_end - dense_start) * 1000.0
33
 
34
  sparse_start = time.perf_counter()
35
 
36
- sparse_output = sparse_classification_pipeline([text])
37
  sparse_result = dict(sparse_output)
38
  sparse_end = time.perf_counter()
39
  sparse_duration = (sparse_end - sparse_start) * 1000.0
@@ -66,8 +70,8 @@ with gr.Blocks() as demo:
66
 
67
  gr.Examples(
68
  [
69
- ["DeepSparse is sparsity-aware inference runtime offering GPU-class performance on CPUs and APIs to integrate ML into your application"],
70
- ["SparseML is a Library for applying sparsification recipes to neural networks with a few lines of code, enabling faster and smaller models"],
71
  ["Gradio is an open-source Python package that allows you to quickly create easy-to-use, customizable UI components for your ML model, any API, or even an arbitrary Python function using a few lines of code. You can integrate the Gradio GUI directly into your Jupyter notebook or share it as a link with anyone."],
72
  ],
73
  inputs=[text],
 
5
  markdownn = '''
6
  # Text Classification Pipeline with DeepSparse
7
  DeepSparse is sparsity-aware inference runtime offering GPU-class performance on CPUs and APIs to integrate ML into your application. DeepSparse provides sparsified pipelines for computer vision and NLP.
8
+ The text classification Pipeline, for example, wraps an NLP model with the proper preprocessing and postprocessing pipelines, such as tokenization. Here is a sample code for a question-answering pipeline:
9
  ```
10
  from deepsparse import Pipeline
11
  pipeline = pipeline.create(task="text-classification", model_path="zoo:nlp/text_classification/bert-base_cased/pytorch/huggingface/mnli/pruned90_quant-none")
 
13
  print(inference)
14
  ```
15
  '''
16
+ task = "zero_shot_text_classification"
17
  dense_classification_pipeline = Pipeline.create(
18
  task=task,
19
+ model_path="zoo:nlp/text_classification/distilbert-none/pytorch/huggingface/mnli/base-none",
20
+ model_scheme="mnli",
21
+ model_config={"hypothesis_template": "This text is related to {}"},
22
  )
23
 
24
  sparse_classification_pipeline = Pipeline.create(
25
  task=task,
26
+ model_path="zoo:nlp/text_classification/distilbert-none/pytorch/huggingface/mnli/pruned80_quant-none-vnni",
27
+ model_scheme="mnli",
28
+ model_config={"hypothesis_template": "This text is related to {}"},
29
  )
30
  def run_pipeline(text):
31
  dense_start = time.perf_counter()
32
 
33
+ dense_output = dense_classification_pipeline(sequences= text,labels=['politics', 'public health', 'Europe'],)
34
  dense_result = dict(dense_output)
35
  dense_end = time.perf_counter()
36
  dense_duration = (dense_end - dense_start) * 1000.0
37
 
38
  sparse_start = time.perf_counter()
39
 
40
+ sparse_output = sparse_classification_pipeline(sequences= text,labels=['politics', 'public health', 'Europe'],)
41
  sparse_result = dict(sparse_output)
42
  sparse_end = time.perf_counter()
43
  sparse_duration = (sparse_end - sparse_start) * 1000.0
 
70
 
71
  gr.Examples(
72
  [
73
+ ["Fun for adults and children"],
74
+ ["Fun for only children"],
75
  ["Gradio is an open-source Python package that allows you to quickly create easy-to-use, customizable UI components for your ML model, any API, or even an arbitrary Python function using a few lines of code. You can integrate the Gradio GUI directly into your Jupyter notebook or share it as a link with anyone."],
76
  ],
77
  inputs=[text],