Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'ZeroShotGPTClassifier' object has no attribute 'key' #93

Closed
AndreasKarasenko opened this issue May 16, 2024 · 2 comments · Fixed by #95
Closed

AttributeError: 'ZeroShotGPTClassifier' object has no attribute 'key' #93

AndreasKarasenko opened this issue May 16, 2024 · 2 comments · Fixed by #95

Comments

@AndreasKarasenko
Copy link
Contributor

I was trying to work on #55 a bit and ran into some other issues.
Calling any GPT classifier like below raises errors for key and org.

clf = ZeroShotGPTClassifier(model="gpt-3.5-turbo")
clf
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'ZeroShotGPTClassifier' object has no attribute 'org'

Expected behavior:

clf
ZeroShotGPTClassifier()

The likely cause is how you handle the key and org. You define key and org attributes in the ZeroShotGPTClassifier innit but then set them using _set_keys from the GPTMixin. GPTMixin, however creates 2 new attributes called openai_key and openai_org, the original attributes are never set.
The same issue arrises with FewShot, Dynamic and GPTVectorizer.

The easiest fix would be to do some refactoring in the GPTMixin.

@iryna-kondr
Copy link
Owner

Hi, @AndreasKarasenko,key and org are arguments of init but not attributes. Could you send the whole code snippet so I could reproduce the issue?

@AndreasKarasenko
Copy link
Contributor Author

Hi, @iryna-kondr the culprit is the BaseEstimator from scikit-learn. According to this scikit-learn documentation (excerpt below) the get_params function looks at the innit parameters and not necessarilly the attributes we assign in the function itself. The set_params function constructs a dict of the innit parameters.

"All scikit-learn estimators have get_params and set_params functions. The get_params function takes no arguments and returns a dict of the init parameters of the estimator, together with their values."

Example code that would produce the error.

from skllm.models.gpt.classification.zero_shot import ZeroShotGPTClassifier
from skllm.datasets import get_classification_dataset

# demo sentiment analysis dataset
# labels: positive, negative, neutral
X, y = get_classification_dataset()

clf = ZeroShotGPTClassifier(model="gpt-3.5-turbo")
clf.fit(X,y)
labels = clf.predict(X)
clf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants