Create ppl.py
Browse files- test_bg/ppl.py +14 -0
test_bg/ppl.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from datasets import load_dataset
|
| 2 |
+
import evaluate
|
| 3 |
+
|
| 4 |
+
perplexity = evaluate.load("perplexity", module_type="metric")
|
| 5 |
+
dataset = load_dataset("wikitext", "wikitext-2-raw-v1", split="test")
|
| 6 |
+
input_texts = [text for text in dataset["text"] if text.strip() != ""]
|
| 7 |
+
results = perplexity.compute(
|
| 8 |
+
model_id='tinycompany/ShawtyIsBad-bgem3',
|
| 9 |
+
predictions=input_texts,
|
| 10 |
+
batch_size=1,
|
| 11 |
+
add_start_token=False,
|
| 12 |
+
device="cuda"
|
| 13 |
+
)
|
| 14 |
+
print("Mean Perplexity:", results["mean_perplexity"])
|