-
I would like to use the model to extract a keyword or key phrase from a short text. Is there any ready-made way to show the model an example of such an operation? Currently, I provide an example as part of the prompt, but maybe there is a more suitable way for this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @jarosik83 , you can use the few-shot approach where you 'fake' the memory: prefill a ChatMemory with a couple of examples (UserMessage: your short text; AiMessage: the keyword or result you want to get; UserMessage: another example; AiMessage: the desired result for that; ...). It works pretty awesome. You can see an example here (works pretty flawless with only 2 positive and 2 negative examples): https://github.com/langchain4j/langchain4j-examples/blob/main/tutorials/src/main/java/_06_FewShot.java |
Beta Was this translation helpful? Give feedback.
Hi @jarosik83 , you can use the few-shot approach where you 'fake' the memory: prefill a ChatMemory with a couple of examples (UserMessage: your short text; AiMessage: the keyword or result you want to get; UserMessage: another example; AiMessage: the desired result for that; ...). It works pretty awesome. You can see an example here (works pretty flawless with only 2 positive and 2 negative examples): https://github.com/langchain4j/langchain4j-examples/blob/main/tutorials/src/main/java/_06_FewShot.java