Skip to main content

PyTorch implementation of BERT score

Project description

BERTScore

Automatic Evaluation Metric described in the paper BERTScore: Evaluating Text Generation with BERT.

Authors:

*: Equal Contribution

Overview

BERTScore leverages the pre-trained contextual embeddings from BERT and matches words in candidate and reference sentences by cosine similarity. It has been shown to correlate with human judgment on setence-level and system-level evaluation. Moreover, BERTScore computes precision, recall, and F1 measure, which can be useful for evaluating different language generation tasks.

For an illustration, BERTScore precision can be computed as

If you find this repo useful, please cite:

@article{bert-score,
  title={BERTScore: Evaluating Text Generation with BERT},
  author={Zhang, Tianyi and Kishore, Varsha and Wu, Felix and Weinberger, Kilian Q. and Artzi, Yoav.},
  journal={arXiv preprint arXiv:1904.09675},
  year={2019}
}

Installation

Install requiremnts by pip install -r requiremnts.txt

Install it from the source by:

git clone https://github.com/Tiiiger/bert_score
cd bert_score
pip install .

Usage

Metric

We provide a command line interface(CLI) of BERTScore as well as a python module. For the CLI, you can use it as follows:

  1. To evaluate English text files:

We provide example inputs under ./example.

bert-score -r example/refs.txt -c example/hyps.txt --bert bert-base-uncased 
  1. To evaluate Chinese text files:

Please format your input files similar to the ones in ./example.

bert-score -r [references] -c [candidates] --bert bert-base-chinese
  1. To evaluate text files in other languages:

Please format your input files similar to the ones in ./example.

bert-score -r [references] -c [candidates]

See more options by bert-score -h.

For the python module, please refer to cli/score.py.

Acknowledgement

This repo wouldn't be possible without the awesome bert and pytorch-pretrained-BERT.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bert_score-0.1.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

bert_score-0.1.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file bert_score-0.1.0.tar.gz.

File metadata

  • Download URL: bert_score-0.1.0.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.24.0 CPython/3.6.7

File hashes

Hashes for bert_score-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a8794e7a5750c86d25a07ebc5847d15f8e0a0c4352dff580d7179169194ecec9
MD5 10d2ae0b24524047773dc562da5ff879
BLAKE2b-256 60766c460b8ef36aebf70ea891672610ab19093400c9729e57222aced7e7a715

See more details on using hashes here.

File details

Details for the file bert_score-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: bert_score-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.24.0 CPython/3.6.7

File hashes

Hashes for bert_score-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d822176308ccf1352f15c3f2e4888b0b17d6784a6267043c369a13f9287d758e
MD5 beb7f00f02ca02098929e18791e58daf
BLAKE2b-256 7c9d40c76d648834646c0f7ff111dd41f5b16cc3db270610ed6247f4f21f636f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page