khadija3818 commited on
Commit
618b877
·
1 Parent(s): 65353c3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -1
app.py CHANGED
@@ -2,7 +2,31 @@ from deepsparse import Pipeline
2
  import time
3
  import gradio as gr
4
 
5
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  task = "zero_shot_text_classification"
7
  sparse_classification_pipeline = Pipeline.create(
8
  task=task,
 
2
  import time
3
  import gradio as gr
4
 
5
+ markdownn = '''
6
+ # Text Classification Pipeline with DeepSparse
7
+ Text Classification involves assigning a label to a given text. For example, sentiment analysis is an example of a text classification use case.
8
+ ![Text Classification Pipeline with DeepSparse](https://huggingface.co/spaces/neuralmagic/nlp-text-classification/resolve/main/text-classification.png)
9
+ ## What is DeepSparse
10
+ DeepSparse is an inference runtime offering GPU-class performance on CPUs and APIs to integrate ML into your application. Sparsification is a powerful technique for optimizing models for inference, reducing the compute needed with a limited accuracy tradeoff. DeepSparse is designed to take advantage of model sparsity, enabling you to deploy models with the flexibility and scalability of software on commodity CPUs with the best-in-class performance of hardware accelerators, enabling you to standardize operations and reduce infrastructure costs.
11
+ Similar to Hugging Face, DeepSparse provides off-the-shelf pipelines for computer vision and NLP that wrap the model with proper pre- and post-processing to run performantly on CPUs by using sparse models.
12
+ The text classification Pipeline, for example, wraps an NLP model with the proper preprocessing and postprocessing pipelines, such as tokenization.
13
+ ### Inference API Example
14
+ Here is sample code for a text classification pipeline:
15
+ ```
16
+ from deepsparse import Pipeline
17
+ pipeline = Pipeline.create(task="zero_shot_text_classification", model_path="zoo:nlp/text_classification/distilbert-none/pytorch/huggingface/mnli/pruned80_quant-none-vnni",model_scheme="mnli",model_config={"hypothesis_template": "This text is related to {}"},)
18
+ text = "The senate passed 3 laws today"
19
+ inference = pipeline(sequences= text,labels=['politics', 'public health', 'Europe'],)
20
+ print(inference)
21
+ ```
22
+ ## Use Case Description
23
+ Customer review classification is a great example of text classification in action.
24
+ The ability to quickly classify sentiment from customers is an added advantage for any business.
25
+ Therefore, whichever solution you deploy for classifying the customer reviews should deliver results in the shortest time possible.
26
+ By being fast the solution will process more volume, hence cheaper computational resources are utilized.
27
+ When deploying a text classification model, decreasing the model’s latency and increasing its throughput is critical. This is why DeepSparse Pipelines have sparse text classification models.
28
+ [Want to train a sparse model on your data? Checkout the documentation on sparse transfer learning](https://docs.neuralmagic.com/use-cases/natural-language-processing/question-answering)
29
+ '''
30
  task = "zero_shot_text_classification"
31
  sparse_classification_pipeline = Pipeline.create(
32
  task=task,