scikit-llm
scikit-llm copied to clipboard
How we can use custom train model for predictions
Let us assume we have build model on our own custom labeled data. we can save model as pickle file , while testing we can load that particular pickle file and do predictions. Is this functionality available with the current implementation.if yes, please share me the sample notebook or code for it.
thanks chandra
I am not sure whether I understood the question correctly, but you can save skllm estimator as pickle the same way you would do with any other python object.
@OKUA1 let us assume we have done this:
from skllm.datasets import get_classification_dataset
# demo sentiment analysis dataset
# labels: positive, negative, neutral
X, y = all_list,list(data.completion.values)
clf = ZeroShotGPTClassifier(openai_model = "gpt-3.5-turbo")
clf.fit(X, y)```
until here we have done training the model right ?
we can save model file as pickle file:
clf.save(model.pickle).
for testing the model:
we can load the model and we can testing something like this
clf = pickle.load(model.pickle)
clf.predit("some text") #itshould give classification
@ChandraReddy97 please follow a general pickle guide like the one below. While we have never tested the pickling/unpickling process with skllm, it should still work. Let me know if you run into any problems. https://practicaldatascience.co.uk/machine-learning/how-to-save-and-load-machine-learning-models-using-pickle
I am closing the issue as it must have been resolved. Please let me know if it was not the case.
Pickle` works well.
import Pickle
import SKLLMConfig from skllm.config
import os
pickle.dump(clf, open("data/zero_shot_gpt.pkl", "wb"))
SKLLMConfig.set_openai_key(os.getenv("OPENAI_API_KEY"))
clf_loaded = pickle.load(open("data/zero_shot_gpt.pkl", "rb"))
clf_loaded.predict([[
"The successor to the saga will have new hardware and a lower price point," according to a person familiar with the plans,
"The newly created ETF could attract up to $36 billion in inflows from other crypto products such as the Grayscale Bitcoin Trust (GBTC), a report said.",
"Bitcoin's RSI divergence signals a correction, 10x Research said."
])