Simplify example
Signed-off-by: András Schmelczer <andras@schmelczer.dev>
This commit is contained in:
parent
91554384f2
commit
0dd48dca60
9 changed files with 18 additions and 22 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -3,4 +3,6 @@
|
|||
__pycache__
|
||||
.cache
|
||||
.mypy_cache
|
||||
.pytest_cache
|
||||
.pytest_cache
|
||||
**/.ipynb_checkpoints
|
||||
**/tracing_database.json
|
||||
|
|
|
|||
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
|
|
@ -9,6 +9,7 @@
|
|||
"psutil",
|
||||
"pydantic",
|
||||
"pyplot",
|
||||
"redoc",
|
||||
"sklearn",
|
||||
"starlette",
|
||||
"Tfidf",
|
||||
|
|
|
|||
3
example/.gitignore
vendored
3
example/.gitignore
vendored
|
|
@ -1,3 +0,0 @@
|
|||
data
|
||||
.ipynb_checkpoints
|
||||
tracing_database.json
|
||||
|
|
@ -1 +0,0 @@
|
|||
model_key = "small-domain-prediction-v2"
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import json
|
||||
from random import shuffle
|
||||
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
from .domain_prediction import DomainPrediction
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
from typing import List
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class DomainPrediction(BaseModel):
|
||||
domain: str
|
||||
probability: float
|
||||
explanation: List[str]
|
||||
|
|
@ -1,16 +1,21 @@
|
|||
import re
|
||||
from typing import Dict, Iterable, List
|
||||
|
||||
from config import model_key
|
||||
from models import DomainPrediction
|
||||
from preprocess import preprocess
|
||||
from pydantic import BaseModel
|
||||
from sklearn.pipeline import Pipeline
|
||||
|
||||
from good_ai import log_argument, log_metric, use_model
|
||||
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)
|
||||
def predict_domain(
|
||||
text: str, model: Pipeline, cut_off_probability: float = 0.2
|
||||
|
|
|
|||
|
|
@ -29,8 +29,7 @@
|
|||
"from good_ai.utilities.language import is_english, predict_language\n",
|
||||
"from good_ai import save_model, set_default_config, LargeFile\n",
|
||||
"\n",
|
||||
"from preprocess import preprocess\n",
|
||||
"from config import model_key"
|
||||
"from preprocess import preprocess"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
@ -48,7 +47,8 @@
|
|||
"source": [
|
||||
"PREFIX = \"domain-\"\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": [
|
||||
"save_model(classifier, key=model_key, keep_last_n=1)"
|
||||
"save_model(classifier, key=MODEL_KEY, keep_last_n=1)"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue