You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For a simple evaluation without defined categories for length, we can add a percentage threshold and check if the generated text is in a certain range. Possible implementation:
defeval_generation_length(generated_text, expected_len, threshold):
""" Our goal is to evaluate the length of a given generated text string in terms of expected and actual length with a threshold. Example: Prompt: "a text with around [100] chars" expected length 100 chars, Generated text: "the cake is a lie ..." actual text length 93, Evaluation with threshold 10%: check if text 93 is between 100-10% and 100+10% """input_len=len(generated_text)
threshold_range=expected_len*(threshold/100)
expected_len_min=expected_len-threshold_range# len - thresholdexpected_len_max=expected_len+threshold_range# len + thresholdprint("For a given text with {} chars, the threshold {} is used to define a soft boundary to check if it is between {} and {}".format(input_len, threshold, expected_len_min, input_len, expected_len_max))
ifexpected_len_min<input_lenandinput_len<expected_len_max:
returnTrueelse:
returnFalseif__name__=="__main__":
text="Obama was the guest of honor at the conference. Bieber performed at the concert last night."# generated textprompt_defined_len=100# text with x charsthreshold=25# x %print("Evaluation: {}".format(eval_generation_length(text, prompt_defined_len, threshold)))
No description provided.
The text was updated successfully, but these errors were encountered: