Made-With-ML/tests/model/utils.py

13 lines
378 B
Python
Raw Normal View History

2023-07-26 13:53:11 +02:00
import numpy as np
import pandas as pd
from madewithml import predict
def get_label(text, predictor):
df = pd.DataFrame({"title": [text], "description": "", "tag": "other"})
z = predictor.predict(data=df)["predictions"]
preprocessor = predictor.get_preprocessor()
label = predict.decode(np.stack(z).argmax(1), preprocessor.index_to_class)[0]
return label