|
import gradio as gr |
|
import evaluate |
|
|
|
|
|
perplexity = evaluate.load("perplexity", module_type="metric") |
|
|
|
def compute_perplexity(text): |
|
|
|
perplexity_results = perplexity.compute(model_id='gpt2', add_start_token=False, predictions=[text]) |
|
perplexity_value = perplexity_results['perplexity'] |
|
|
|
|
|
return f"Perplexity of the input text: {perplexity_value}" |
|
|
|
|
|
demo = gr.Interface( |
|
fn=compute_perplexity, |
|
inputs="text", |
|
outputs="text", |
|
title="Compute Perplexity", |
|
description="Enter a text to compute its perplexity based on the gpt2 model." |
|
) |
|
|
|
if __name__ == "__main__": |
|
demo.launch() |
|
|