Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Questions around perplexity metric for language modeling

Aperta
#688 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
32/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
python

Direzione di ricerca

Inizia confrontando il calcolo manuale della perplexity nella documentazione di Transformers con evaluate/metrics/perplexity/perplexity.py e l’esempio di riferimento della metrica collegato. Riproduci quindi i risultati riportati per Wikitext e GPT-2 dal notebook Colab, poi traccia il percorso con cui gli input di tipo lista e stringa raggiungono la metrica. Il lavoro è completato quando le discrepanze e il comportamento di elaborazione degli input sono spiegati o coperti da una correzione documentata e da test.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Hi there,

I've been fiddling with perplexity computation in the past few days, and I was struck by a few discrepancies:

  • In your manual implementation, I read:
     

    When we run the above with stride = 1024, i.e. no overlap, the resulting PPL is 19.44, which is about the same as the 19.93 reported in the GPT-2 paper (note: p. 5).

  • On the reference page (see 'Examples'):
     
    perplexity = evaluate.load("perplexity", module_type="metric")
    input_texts = datasets.load_dataset("wikitext",
                                        "wikitext-2-raw-v1",
                                        split="test")["text"][:50]
    input_texts = [s for s in input_texts if s!='']
    results = perplexity.compute(model_id='gpt2',
                                 predictions=input_texts)
    print(list(results.keys()))
    >>>['perplexities', 'mean_perplexity']
    print(round(results["mean_perplexity"], 2))
    >>>576.76
    print(round(results["perplexities"][0], 2))
    >>>889.28
    
    (Of course this is run on a very short sequence, only 50 characters!)

Here's a Colab notebook with my experiments.

Question 1

Even when using evaluate, I get fairly different results: just for the 50 character selection, I obtain:

320.85
567.91

Something in the implementation changed since the docs were written? What am I missing?

Question 2

There is still a humongous difference between the manual computation (first page I quoted above, ported in the notebook, and similar results when experimenting with a faster, batched implementation using stride in the tokenizer) and what the metric produces. What I'm expecting for wikitext is something of the order of 20-30, and lower for bigger models, not in the hundreds, let alone in the thousands (see the notebook, result when joining all rows with \n\n)... (At first I thought it was because of pad_tokens being counted, that was wrong.) I'm now at a loss as to where that might come from. Any ideas?

Question 3

Also, notice that I can pass the dataset either as a list of strings of varying lengths, or as one long string, and it runs, but the perplexity class itself, on its own, does not seem to handle that (no return_overflowing_tokens = True passed to the tokenizer, for instance, I performed a few tests with the class only): I'm guessing the dataset is processed somewhere before being fed to it? I'm in the process of understanding the whole pipeline of invocation of the metric, but so far I haven't found where it happens.

Apologies if the first version of this issue had quite a few silly mistakes, and thanks for reading!

Lingua principale
Python
Stelle
2.5k
Fork
346
Merge medio
38m
PR unite (30g)
4

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di huggingface/evaluate

Tutte le issue di huggingface/evaluate

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.