Simplify example

Signed-off-by: András Schmelczer <andras@schmelczer.dev>
This commit is contained in:
Andras Schmelczer 2022-04-10 14:43:21 +02:00
parent 76c9f4a0cd
commit 0877d34b8b
9 changed files with 18 additions and 22 deletions

2
.gitignore vendored
View file

@ -4,3 +4,5 @@ __pycache__
.cache .cache
.mypy_cache .mypy_cache
.pytest_cache .pytest_cache
**/.ipynb_checkpoints
**/tracing_database.json

View file

@ -9,6 +9,7 @@
"psutil", "psutil",
"pydantic", "pydantic",
"pyplot", "pyplot",
"redoc",
"sklearn", "sklearn",
"starlette", "starlette",
"Tfidf", "Tfidf",

3
example/.gitignore vendored
View file

@ -1,3 +0,0 @@
data
.ipynb_checkpoints
tracing_database.json

View file

@ -1 +0,0 @@
model_key = "small-domain-prediction-v2"

View file

@ -1,3 +1,5 @@
#!/usr/bin/env python3
import json import json
from random import shuffle from random import shuffle

View file

@ -1 +0,0 @@
from .domain_prediction import DomainPrediction

View file

@ -1,9 +0,0 @@
from typing import List
from pydantic import BaseModel
class DomainPrediction(BaseModel):
domain: str
probability: float
explanation: List[str]

View file

@ -1,16 +1,21 @@
import re import re
from typing import Dict, Iterable, List from typing import Dict, Iterable, List
from config import model_key
from models import DomainPrediction
from preprocess import preprocess from preprocess import preprocess
from pydantic import BaseModel
from sklearn.pipeline import Pipeline from sklearn.pipeline import Pipeline
from good_ai import log_argument, log_metric, use_model from good_ai import log_argument, log_metric, use_model
from good_ai.utilities.clean import clean from good_ai.utilities.clean import clean
@use_model(model_key, version="latest") class DomainPrediction(BaseModel):
domain: str
probability: float
explanation: List[str]
@use_model("small-domain-prediction-v2", version="latest")
@log_argument("text", validator=lambda t: len(t) > 0) @log_argument("text", validator=lambda t: len(t) > 0)
def predict_domain( def predict_domain(
text: str, model: Pipeline, cut_off_probability: float = 0.2 text: str, model: Pipeline, cut_off_probability: float = 0.2

View file

@ -29,8 +29,7 @@
"from good_ai.utilities.language import is_english, predict_language\n", "from good_ai.utilities.language import is_english, predict_language\n",
"from good_ai import save_model, set_default_config, LargeFile\n", "from good_ai import save_model, set_default_config, LargeFile\n",
"\n", "\n",
"from preprocess import preprocess\n", "from preprocess import preprocess"
"from config import model_key"
] ]
}, },
{ {
@ -48,7 +47,8 @@
"source": [ "source": [
"PREFIX = \"domain-\"\n", "PREFIX = \"domain-\"\n",
"DATASET_KEY = \"data\"\n", "DATASET_KEY = \"data\"\n",
"MAX_FILE_COUNT = 5" "MAX_FILE_COUNT = 5\n",
"MODEL_KEY = \"small-domain-prediction-v2\""
] ]
}, },
{ {
@ -774,7 +774,7 @@
} }
], ],
"source": [ "source": [
"save_model(classifier, key=model_key, keep_last_n=1)" "save_model(classifier, key=MODEL_KEY, keep_last_n=1)"
] ]
} }
], ],