iryna-kondr / scikit-llm

Seamlessly integrate LLMs into scikit-learn.
https://beastbyte.ai/
MIT License
3.38k stars 275 forks source link

Prompt JSON response for DynamicFewShotGPTClassifier is blank #66

Closed igormoreira-2 closed 1 year ago

igormoreira-2 commented 1 year ago

Hi,

I just started using skllm and I have tried to build a simple DynamicFewShotGPTClassifier with the following code:

from skllm import DynamicFewShotGPTClassifier

X = [
    "I love reading science fiction novels, they transport me to other worlds.",
    "A good mystery novel keeps me guessing until the very end.",
    "Historical novels give me a sense of different times and places.",
    "I love watching science fiction movies, they transport me to other galaxies.",
    "A good mystery movie keeps me on the edge of my seat.",
    "Historical movies offer a glimpse into the past.",
]

y = ["books", "books", "books", "movies", "movies", "movies"]

query = "I have fallen deeply in love with this sci-fi book; its unique blend of science and fiction has me spellbound."

clf = DynamicFewShotGPTClassifier(n_examples=1).fit(X, y)

prompt = clf._get_prompt(query)
print(prompt)

Everything seems to work just fine, but the Your JSON response is blank. Any ideas of what could be happening? Thanks

Prompt output:

List of categories: ['books', 'movies']

Training data:

Sample input:
```I love reading science fiction novels, they transport me to other worlds.```

Sample target: books

Sample input:
```I love watching science fiction movies, they transport me to other galaxies.```

Sample target: movies

Text sample: ```I have fallen deeply in love with this sci-fi book; its unique blend of science and fiction has me spellbound.```

Your JSON response:
OKUA1 commented 1 year ago

Hi @igormoreira-2

I don't see any problems with the example you provided. Whenever you call the _get_prompt() method (which in fact is not supposed to be called by the users in most of the cases), only the prompt itself (that is passed to the model afterwards) is returned. The line "Your JSON response" is a part of the prompt as it instructs the model to immediately start producing the JSON. However, the JSON object itself is obviously cannot be in the prompt as it has to be generated by the model.

What exactly are you trying to achieve ? If you need the predictions, you can just call .predict([query]), but if you want to see the raw response of the model, this is not really possible.

igormoreira-2 commented 1 year ago

Hi @OKUA1 , thanks for the swift response. You are right, there is no issue at all. It's just that by reading the get_prompt() response I assumed the json output would be there. But yeah, when I called the .predict() method, it worked just fine. As I said, I just started experimenting with skllm 2 days ago, so I'm still learning ;) .