Spaces:
Runtime error
Runtime error
inserimento primi test e modifica modello
Browse files- MLOps_project/CD/app.py +0 -0
- MLOps_project/CI/test_ci.py +7 -7
- MLOps_project/dockerfile +14 -0
- MLOps_project/modello.py +21 -7
MLOps_project/CD/app.py
ADDED
|
File without changes
|
MLOps_project/CI/test_ci.py
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
|
|
|
|
|
| 1 |
class TestClass :
|
| 2 |
"""
|
| 3 |
-
test
|
| 4 |
"""
|
| 5 |
|
| 6 |
-
def
|
| 7 |
-
|
| 8 |
-
assert x==1
|
| 9 |
|
| 10 |
-
def
|
| 11 |
-
|
| 12 |
-
assert y>5
|
|
|
|
| 1 |
+
import modello
|
| 2 |
+
|
| 3 |
class TestClass :
|
| 4 |
"""
|
| 5 |
+
test sul modello per pipeline CI
|
| 6 |
"""
|
| 7 |
|
| 8 |
+
def check_trivial_output(self) :
|
| 9 |
+
assert modello.sentiment_task("neutral")[0]["label"]=="neutral" and modello.sentiment_task("awesome")[0]["label"]=="positive" and modello.sentiment_task("terrible")[0]["label"]=="negative"
|
|
|
|
| 10 |
|
| 11 |
+
def train_set_bigger_than_test_set(self) :
|
| 12 |
+
assert modello.df_train.shape[0]>modello.df_test.shape[0]
|
|
|
MLOps_project/dockerfile
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#dockerfile
|
| 2 |
+
|
| 3 |
+
# versione di Python
|
| 4 |
+
FROM python:3.12.1
|
| 5 |
+
|
| 6 |
+
# copia della directory in /app
|
| 7 |
+
COPY ./MLOps_project/CD /app
|
| 8 |
+
|
| 9 |
+
# set della working directory
|
| 10 |
+
WORKDIR /app
|
| 11 |
+
RUN ls
|
| 12 |
+
|
| 13 |
+
# run dello script Python
|
| 14 |
+
CMD ["python", "app.py"]
|
MLOps_project/modello.py
CHANGED
|
@@ -1,11 +1,25 @@
|
|
|
|
|
| 1 |
from transformers import pipeline
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
sentiment_task = pipeline("sentiment-analysis", model="cardiffnlp/twitter-roberta-base-sentiment-latest", tokenizer="cardiffnlp/twitter-roberta-base-sentiment-latest")
|
| 3 |
-
# print(sentiment_task("Covid cases are increasing fast!"))
|
| 4 |
|
| 5 |
-
|
| 6 |
ds = load_dataset("SetFit/tweet_sentiment_extraction")
|
| 7 |
-
#
|
| 8 |
-
#
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Utilities
|
| 2 |
from transformers import pipeline
|
| 3 |
+
from datasets import load_dataset
|
| 4 |
+
import pandas as pd
|
| 5 |
+
|
| 6 |
+
# Import del modello da Hugging Face
|
| 7 |
sentiment_task = pipeline("sentiment-analysis", model="cardiffnlp/twitter-roberta-base-sentiment-latest", tokenizer="cardiffnlp/twitter-roberta-base-sentiment-latest")
|
|
|
|
| 8 |
|
| 9 |
+
# Import di un dataset da Hugging Face
|
| 10 |
ds = load_dataset("SetFit/tweet_sentiment_extraction")
|
| 11 |
+
# Il dataset viene splittato autometicamente in train set e test set da load_dataset
|
| 12 |
+
# Per comodità trasformo i dataset in dataframe di pandas
|
| 13 |
+
df_train = ds['train'].to_pandas()
|
| 14 |
+
df_test = ds['test'].to_pandas()
|
| 15 |
+
|
| 16 |
+
X_train = df_train['text'].values
|
| 17 |
+
y_train = df_train['label_text'].values
|
| 18 |
+
X_test = df_test['text'].values
|
| 19 |
+
y_test = df_test['label_text'].values
|
| 20 |
+
|
| 21 |
+
# Estraggo il modello
|
| 22 |
+
model = sentiment_task.model
|
| 23 |
+
|
| 24 |
+
# Ri-addestro il modello sul dataset importato
|
| 25 |
+
model.fit(X_train,y_train)
|