Skip to content

Commit

Permalink
Create evaluation.py to implement the passkey retrieval task mentione…
Browse files Browse the repository at this point in the history
…d in the LongRoPE paper as an additional evaluation metric.
  • Loading branch information
jshuadvd committed Jul 5, 2024
1 parent 45de677 commit c706553
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions evaluation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import random
import torch


def generate_passkey_prompt(passkey, context_length):
"""
Generate a prompt with a hidden passkey for the retrieval task.
"""
filler = "The grass is green. The sky is blue. The sun is yellow. Here we go. There and back again. "
filler_tokens = len(filler.split())

passkey_position = random.randint(filler_tokens, context_length - filler_tokens)

pre_passkey = filler * (passkey_position // filler_tokens)
post_passkey = filler * (
(context_length - passkey_position - len(passkey) - filler_tokens)
// filler_tokens
)

prompt = (
f"{pre_passkey}The pass key is {passkey}. Remember it. {passkey} is the pass key. "
f"{post_passkey}What is the pass key? The pass key is"
)

return prompt

0 comments on commit c706553

Please sign in to comment.