Skip to content

Bart summarizer #907

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions examples/pytorch/text-summarizer/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
Please refer to the [tutorial](https://cortex.dev/iris-classifier) to see how to deploy an example with Cortex.

Please refer [here](https://sshleifer.github.io/blog_v2/jupyter/2020/03/12/bart.html) to learn more about BART.
2 changes: 2 additions & 0 deletions examples/pytorch/text-summarizer/cortex.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
type: python
path: predictor.py
compute:
cpu: 1
gpu: 1 # This is optional, since the API will run on CPUs (albeit slower)
mem: 4G
11 changes: 8 additions & 3 deletions examples/pytorch/text-summarizer/predictor.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
# WARNING: you are on the master branch, please refer to the examples on the branch that matches your `cortex version`

from summarizer import Summarizer
import torch
from transformers import pipeline


class PythonPredictor:
def __init__(self, config):
self.model = Summarizer()
device = 0 if torch.cuda.is_available() else -1
self.summarizer = pipeline(task="summarization", device=device)

def predict(self, payload):
return self.model(payload["text"])
summary = self.summarizer(
payload["text"], num_beams=4, length_penalty=2.0, max_length=142, no_repeat_ngram_size=3
)
return summary[0]["summary_text"]
3 changes: 1 addition & 2 deletions examples/pytorch/text-summarizer/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
transformers
spacy==2.1.3
bert-extractive-summarizer==0.3.*
torch
2 changes: 1 addition & 1 deletion examples/pytorch/text-summarizer/sample.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"text": "Machine learnng (ML) is the scientific study of algorithms and statistical models that computer systems use to perform a specific task without using explicit instructions, relying on patterns and inference instead. It is seen as a subset of artificial intelligence. Machine learning algorithms build a mathematical model based on sample data, known as training data, in order to make predictions or decisions without being explicitly programmed to perform the task. Machine learning algorithms are used in a wide variety of applications, such as email filtering and computer vision, where it is difficult or infeasible to develop a conventional algorithm for effectively performing the task. Machine learning is closely related to computational statistics, which focuses on making predictions using computers. The study of mathematical optimization delivers methods, theory and application domains to the field of machine learning. Data mining is a field of study within machine learning, and focuses on exploratory data analysis through unsupervised learning. In its application across business problems, machine learning is also referred to as predictive analytics."
"text": "Machine learning (ML) is the scientific study of algorithms and statistical models that computer systems use to perform a specific task without using explicit instructions, relying on patterns and inference instead. It is seen as a subset of artificial intelligence. Machine learning algorithms build a mathematical model based on sample data, known as training data, in order to make predictions or decisions without being explicitly programmed to perform the task. Machine learning algorithms are used in a wide variety of applications, such as email filtering and computer vision, where it is difficult or infeasible to develop a conventional algorithm for effectively performing the task. Machine learning is closely related to computational statistics, which focuses on making predictions using computers. The study of mathematical optimization delivers methods, theory and application domains to the field of machine learning. Data mining is a field of study within machine learning, and focuses on exploratory data analysis through unsupervised learning. In its application across business problems, machine learning is also referred to as predictive analytics."
}