Skip to content

Commit a2f6e2a

Browse files
committed
ML services validation update
1 parent 7e4b8e2 commit a2f6e2a

File tree

5 files changed

+36
-37
lines changed

5 files changed

+36
-37
lines changed
5.63 KB
Binary file not shown.

ml_services_validation_19-05/slides/machine_learning.tex

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,26 @@ \section{Machine Learning}
2020
\end{block}
2121
\end{frame}
2222

23+
\begin{frame}{AI in perspective}
24+
\only<1>{
25+
\begin{figure}
26+
\includegraphics[width=\textwidth]{img/tree-ai.png}
27+
\end{figure}
28+
}
29+
30+
\only<2>{
31+
\begin{figure}
32+
\includegraphics[width=\textwidth]{img/venn-ai.jpeg}
33+
\end{figure}
34+
}
35+
36+
\only<3>{
37+
\begin{figure}
38+
\includegraphics[width=\textwidth]{img/venn-ai-simplified.jpeg}
39+
\end{figure}
40+
}
41+
\end{frame}
42+
2343
\begin{frame}{What is Machine Learning?}
2444
The science of getting a computer to act without programming. There are three types of machine learning algorithms:
2545

@@ -42,34 +62,14 @@ \section{Machine Learning}
4262
\end{block}
4363
\end{frame}
4464

45-
\begin{frame}{AI in perspective}
46-
\only<1>{
47-
\begin{figure}
48-
\includegraphics[width=\textwidth]{img/tree-ai.png}
49-
\end{figure}
50-
}
51-
52-
\only<2>{
53-
\begin{figure}
54-
\includegraphics[width=\textwidth]{img/venn-ai.jpeg}
55-
\end{figure}
56-
}
57-
58-
\only<3>{
59-
\begin{figure}
60-
\includegraphics[width=\textwidth]{img/venn-ai-simplified.jpeg}
61-
\end{figure}
62-
}
63-
\end{frame}
64-
6565
\begin{frame}{Supervised Learning}
6666
\begin{figure}
6767
\includegraphics[width=\textwidth]{img/training-process.png}
6868
\end{figure}
6969
\end{frame}
7070

7171
\begin{frame}{The Model}
72-
We are going to build a model that performs a sentiment analysis over a text and concludes it it is positive or negative.
72+
We are going to build a model that performs a sentiment analysis over a text and concludes if it is positive or negative.
7373

7474
\textbf{Input:} A text (a list of integers representing each word).
7575

ml_services_validation_19-05/slides/service.tex

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ \section{Building a Machine Learning Service}
33
\begin{frame}{How to expose the ML model?}
44
Machine Learning models can be used either as an internal piece of a service or as a service itself.
55

6+
\pause
7+
68
If it is used as an \textbf{internal piece} you won't notice it, such as scoring or recommendation systems within bigger products like Spotify or Netflix.
79

10+
\pause
11+
812
But you can also find them as a \textbf{service that exposes an API} to directly interact with the model. There are many examples of that in AWS, Google Cloud, Azure...
913
\end{frame}
1014

@@ -21,17 +25,17 @@ \section{Building a Machine Learning Service}
2125
\begin{description}
2226
\item[Verb] \texttt{\textbf{GET}}
2327
\item[URL] \texttt{https://service.url/analyze/}
24-
\item[Params] \texttt{text=The girl is having fun while playing with her toys}
28+
\item[Params] \texttt{text=The\%20girl\%20is\%20having\%20fun\%20while\%20playing}
2529
\end{description}
2630
}
2731
\end{exampleblock}
2832

2933
\begin{exampleblock}{Response}
3034
\begin{minted}[fontsize=\footnotesize]{js}
3135
{
32-
"score": 0.5628073215484619,
33-
"text": "The girl is having fun while playing with her toys",
34-
"sentiment": "Positive"
36+
"text": "The girl is having fun while playing",
37+
"sentiment": "Positive",
38+
"score": 0.6321590542793274
3539
}
3640
\end{minted}
3741
\end{exampleblock}
@@ -40,14 +44,16 @@ \section{Building a Machine Learning Service}
4044
\begin{frame}{Building a REST API with Flama}
4145
To build a REST API we need to define:
4246

43-
\begin{enumerate}
47+
\begin{enumerate}[<+->]
4448
\item A \textbf{component} that loads our ML model.
4549
\item The \textbf{data schema} for our response.
4650
\item The \textbf{view} function that will be called through requests to \texttt{/analyze/} endpoint.
4751
\item The whole API \textbf{application}.
4852
\end{enumerate}
4953

50-
Everything put together is less than 100 lines of python code.
54+
\only<4>{
55+
Everything put together is less than 100 lines of python code.
56+
}
5157
\end{frame}
5258

5359
\begin{frame}[fragile]{ML Component}

ml_services_validation_19-05/src/api/api.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ class SentimentAnalysis(Schema):
4747
sentiment = fields.String(title="sentiment", description="Sentiment class (Positive or Negative)")
4848

4949

50-
def home():
51-
return "Welcome to Sentiment Analysis API"
52-
53-
5450
def analyze(text: str, model: SentimentAnalysisModel) -> SentimentAnalysis:
5551
"""
5652
tags:
@@ -66,21 +62,17 @@ def analyze(text: str, model: SentimentAnalysisModel) -> SentimentAnalysis:
6662
text = unquote(text)
6763
score, sentiment = model.predict(text)
6864

69-
return {
70-
"text": text,
71-
"score": score,
72-
"sentiment": sentiment,
73-
}
65+
return {"text": text, "score": score, "sentiment": sentiment}
7466

7567

7668
app = Flama(
7769
components=[SentimentAnalysisModelComponent(model_path="model.h5", words_path="words.json")],
7870
title="Sentiment Analysis", # API title
7971
version="0.1", # API version
8072
description="A sentiment analysis API for movies reviews", # API description
73+
redoc="/redoc/",
8174
)
8275

83-
app.add_route("/", home, methods=["GET"])
8476
app.add_route("/analyze/", analyze, methods=["GET"])
8577

8678

ml_services_validation_19-05/src/api/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ h5py
55
tensorflow
66
flama[full]
77
uvicorn
8+
marshmallow==3.0.0rc5

0 commit comments

Comments
 (0)