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

fix a bug for prompt version 0.6 in jaqket_v2 #105

Merged
merged 2 commits into from
Oct 24, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions lm_eval/tasks/ja/jaqket_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,28 @@ class JAQKETV2WithLlama2(JAQKETV2WithJAAlpacaPrompt):
DESCRIPTION = f"<s>[INST] <<SYS>>\n{SYSTEM_PROMPT}\n<</SYS>>\n\n"
FEWSHOT_SEP = " </s><s>[INST] "

def preprocess_ctx(self, ctx, max_length):
# if ctx fits in max length, return
if len(self.tokenizer.encode(ctx)) <= max_length:
return ctx

# if ctx is too long, split on a tag that separates each example
_, remainder = ctx.split(self.DESCRIPTION, 1)
ctxs = remainder.split(self.FEWSHOT_SEP)
mkshing marked this conversation as resolved.
Show resolved Hide resolved
# if there is no example and still the description + QA prompt is too long, fail
if len(ctxs) < 2:
raise ValueError(
f"description + QA prompt with no example (0-shot) doesn't fit in max_length. ctx: {ctx}"
)

# delete the first example, the last includes QA prompt to be answered by lm
del ctxs[0]

# recur
return self.preprocess_ctx(
self.DESCRIPTION + self.FEWSHOT_SEP.join(ctxs), max_length
)

def doc_to_text(self, doc):
"""
Insert the following prompt into `{{ user_msg }}`, which is based on prompt version 0.3
Expand Down
Loading