Package: blanc
Evaluation measuresThis repositary contains reference implementations and explanations to accompanyPrimer.airesearch and publications related to evaluation measures, mostly for the purpose of summary evaluation.These evaluation measures include:BLANC-help (or simply 'BLANC'), BLANC-tuneblanc.pyAll the info is in this pageShannon Score, Information Difference, BLANC-Shannonshannon.pyInfo:Shannon Score and Information DifferenceESTIME, ESTIME-soft, ESTIME-coherenceestime.pyInfo:ESTIME (hard, soft and coherence)Annotated summary quality datasets:dataSetupInstall Python 3.6 or higherInstall withpip install blancBLANCThis is the reference implementation of BLANC-help and BLANC-tune as defined inFill in the BLANC: Human-free quality estimation of document summaries.BLANC is a reference-free approach to the automatic estimation of document summary quality. Our goal is to measure the functional performance of a summary with an objective, reproducible, and fully automated method. Our approach achieves this by measuring the performance boost gained by a pre-trained language model with access to a document summary while carrying out its language understanding task on the document's text. Unlike ROUGE, BLANC does not require human-written reference summaries, allowing for fully human-free summary quality estimation.Two types of BLANC scores were introduced in the paper and are available in this repo: BLANC-help and BLANC-tune. BLANC-help is faster to calculate (around 30% faster on CUDA with default settings), but BLANC-tune is more theoretically principled. They are around 90% correlated with each other, so either one can be used in most cases.BLANC-help with gap=2 on average correlates the best with human scoresSensitivity of BLANC to human-scored qualities of text summaries, it is now set as default. The original paper used gap=6. Optimal parameters for BLANC-help and for BLANC-tune are found by using 'max-help' criterion, without relying on human summaries or human scores, inIs Human Scoring the Best Criteria for Summary Evaluation?(the paper points to the possible bias of human experts).Python UsageBasic usage:>>>fromblancimportBlancHelp,BlancTune>>>document="Jack drove his minivan to the bazaar to purchase milk and honey for his large family.">>>summary="Jack bought milk and honey.">>>blanc_help=BlancHelp()>>>blanc_tune=BlancTune(finetune_mask_evenly=False,show_progress_bar=False)>>>blanc_help.eval_once(document,summary)0.2222222222222222>>>blanc_tune.eval_once(document,summary)0.3333333333333333By default, BLANC is run on the CPU. Using CUDA with batching is much faster:blanc_help=BlancHelp(device='cuda',inference_batch_size=128)blanc_tune=BlancTune(device='cuda',inference_batch_size=24,finetune_mask_evenly=False,finetune_batch_size=24)With these batch sizes, BLANC-help takes around 1.4 sec per summary and BLANC-tune takes around 1.8 sec per summary on an NVIDIA V100. In addition to the parameters controlling device and batch sizes, BlancHelp and BlancTune take several other parameters controlling how the BLANC scores are calculated, and the default values for those parameters reproduce the results of the paper. BlancTune results may vary if random_seed is not set.If you want to compute the BLANC scores of many documents and summaries at once, you can useeval_pairs()oreval_summaries_for_docs().eval_pairs()is useful when you have many documents, each with a single summary:>>>documents=["Jack drove his minivan to the bazaar to purchase milk and honey for his large family.","As Jill started taking a walk in the park, she certainly noticed that the trees were extra green this year."]>>>summaries=["Jack bought milk and honey.","Jill saw green trees in the park."]>>>blanc_help.eval_pairs(documents,summaries)[0.2222222222222222,0.0]eval_summaries_for_docs()is useful when you have many documents, each with many summaries:>>>doc_summaries=[["Jack bought milk and honey.","Jack drove to the bazaar in a minivan"],["Jill saw green trees in the park.","The trees were green."]]>>>blanc_tune.eval_summaries_for_docs(documents,doc_summaries)[[0.2222222222222222,0.2222222222222222],[-0.07142857142857142,-0.14285714285714285]]CLI UsageA CLI for computing BLANC scores is provided for convenience.$ blanc help --gap 6 --doc "Jack drove his minivan to the bazaar to purchase milk and honey for his large family." --summary "Jack bought milk and honey."
0.1111111111111111Input data can also be provided in JSON format, with sample JSON input provided indata/$ blanc help --single_json data/single.json --gap 6
0.1111111111111111
$ blanc tune --pairs_json data/pairs.json --gap 6 --finetune_mask_evenly False
[0.2222222222222222, 0.14285714285714285]
$ blanc tune --doc_summaries_json data/doc-summaries.json --gap 6 --finetune_mask_evenly False
[[0.2222222222222222, 0.2222222222222222], [0.14285714285714285, 0.07142857142857142]]Thesingle_jsoninput format expects a single JSON blob with keysdocumentandsummary. Thepairs_jsoninput format expects a list of JSON blobs, each with adocumentand asummary. Thedoc_summaries_jsoninput format expects a list of JSON blobs, each with keysdocumentandsummaries, wheresummariesis a list of strings. These keys are customizable with thedoc_key,summary_key, andsummaries_keyarguments. By default, the output is printed to STDOUT, but it can be written to a JSON file provided with theoutput_jsonargument.Full documentation is available withblanc --help:required arguments:
  {help,tune}           BLANC-help or BLANC-tune

input arguments:
  --doc DOC             single input document (default: None)
  --summary SUMMARY     single input summary (default: None)
  --single_json FILENAME
                        filename for single document summary pair (default:
                        None)
  --pairs_json FILENAME
                        filename for list of document summary pairs (default:
                        None)
  --doc_summaries_json FILENAME
                        filename for list of documents, each with a list of
                        summaries (default: None)
  --doc_key KEY         json key for the input document (default: doc)
  --summary_key KEY     json key for the input summary (single_json or
                        pairs_json input) (default: summary)
  --summaries_key KEY   json key for the input summaries (doc_summaries_json
                        input) (default: summaries)

arguments for BLANC-help and BLANC-tune:
  --model_name NAME     BERT model type (default: bert-base-uncased)
  --measure {improve,relative}
                        measure improve or relative, as defined in the paper
                        (default: relative)
  --gap GAP             distance between words to mask during inference
                        (default: 2)
  --gap_mask NUM        number of tokens to mask during inference at each
                        gap-defined position
                        (default: 1)
  --min_token_length_normal LEN
                        minimum number of chars in normal tokens to mask,
                        where a normal token is a whole word (default: 4)
  --min_token_length_lead LEN
                        minimum number of chars in lead token to mask, where a
                        lead token begins a word (default: 2)
  --min_token_length_followup LEN
                        minimum number of chars in followup token to mask,
                        where a followup token continues a word (default: 100)
  --device DEVICE       cpu or cuda device (default: cpu)
  --random_seed SEED    random seed for python and torch (default: 1)
  --inference_batch_size SIZE
                        batch size to use during inference (default: 1)
  --inference_mask_evenly MASK_EVENLY
                        when True, mask every `gap` tokens that are longer
                        than `min_token_length` during finetuning, when False
                        randomly mask tokens with probability 0.15 (default:
                        True)

BLANC-help arguments:
  --filler_token TOKEN  token to use as filler in lieu of summary (default: .)
  --help_sep SEP        token to use to separate the summary or filler from
                        the sentence, or '' for no separator (default: )

BLANC-tune arguments:
  --finetune_batch_size SIZE
                        batch size to use when finetuning on summary (default:
                        1)
  --finetune_epochs EPOCHS
                        number of epochs to train for when finetuning on
                        summary (default: 10)
  --finetune_mask_evenly MASK_EVENLY
                        when True, mask every `gap` tokens that are longer
                        than `min_token_length`during finetuning, when False
                        randomly mask tokens with probability 0.15 (default:
                        False)
  --finetune_chunk_size SIZE
                        number of summary tokens to use at a time when
                        finetuning (default: 64)
  --finetune_chunk_stride STRIDE
                        number of tokens between summary chunks for finetuning
                        (default: 32)
  --learning_rate LR    learning rate when finetuning on summary (default:
                        5e-05)
  --warmup_steps STEPS  warmup steps when finetuning on summary (default: 0)BLANC onSummEvaldatasetBLANC can run on top of any pretrained BERT or AlBERT model (more will be added). The table below lists correlations of BLANC with human scores on the human-annotatedSummEvaldataset (described inSummEval: Re-evaluating Summarization Evaluation). The dataset contains 1600 text-summary pairs by 100 texts x 16 systems. We show correlation (Spearman and Kendall's Tau-c) between BLANC-help and experts-average scores for each quality of the summary (coherence, consistency, fluency, relevance):qualitymodelSpearmanKendallcoherencebbu0.1220.09coherencebbc0.1970.142coherenceblu0.1160.085coherenceblc0.2260.165coherencebluw0.0830.06coherenceblcw0.1960.142coherenceab0.1680.125coherenceal0.1520.111coherenceaxl0.150.11coherenceaxxl0.1270.093consistencybbu0.190.094consistencybbc0.190.094consistencyblu0.2070.102consistencyblc0.2040.1consistencybluw0.1670.082consistencyblcw0.180.089consistencyab0.1920.095consistencyal0.1990.098consistencyaxl0.1790.088consistencyaxxl0.20.098fluencybbu0.0890.051fluencybbc0.1080.062fluencyblu0.1120.065fluencyblc0.1130.064fluencybluw0.1070.061fluencyblcw0.1210.069fluencyab0.1240.072fluencyal0.1320.076fluencyaxl0.1190.069fluencyaxxl0.1150.066relevancebbu0.2160.156relevancebbc0.2780.201relevanceblu0.2170.156relevanceblc0.3060.223relevancebluw0.1940.14relevanceblcw0.2580.188relevanceab0.270.193relevanceal0.2670.192relevanceaxl0.2450.176relevanceaxxl0.2460.179Thetransformersmodels are: bert-base-uncased (bbu), bert-base-cased (bbc), bert-large-uncased (blu), bert-large-cased (blc), bert-large-uncased-whole-word-masking (bluw), bert-large-cased-whole-word-masking (blcw), albert-base-v2 (ab), albert-large-v2 (al), albert-xlarge-v2 (axl), albert-xxlarge-v2 (axxl). The BLANC-help was used with the current default settings (gap=2, min_token_length_normal=4, min_token_length_lead=2, min_token_length_followup=100). All the p-values above are of order 10^-5 or lower.The system-level correlations (correlations between 16-dimensional scores after averaging each system scores over 100 texts) have too high p-values. The table below shows only the correlations with p-values <0.05:qualitymodelSpearmanpKendallpconsistencybbu0.7380.0010.5670.002consistencybbc0.7590.0010.5330.003consistencyblu0.7240.0020.5670.002consistencyblc0.7880.00.5670.002consistencybluw0.7710.00.6170.001consistencyblcw0.7910.00.60.001consistencyab0.7240.0020.5830.001consistencyal0.7740.00.60.001consistencyaxl0.7060.0020.5170.005consistencyaxxl0.8120.00.6170.001fluencybbc0.5580.0250.4440.017fluencyblc0.5490.0280.4440.017fluencybluw0.5250.0370.3770.043fluencyblcw0.5950.0150.4770.01fluencyal0.5180.040.3930.034fluencyaxxl0.5340.0330.410.027relevancebbc0.4670.011relevanceblc0.4670.011relevanceblcw0.5150.0410.4670.011