Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

bertscore_check.py 509 B

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  1. """
  2. BERTScore - measure semantic similarity between generated and reference text.
  3. """
  4. from bert_score import score
  5. def get_assert(output, context):
  6. """
  7. Returns BERTScore F1 as a number (0-1).
  8. Promptfoo will compare against threshold automatically.
  9. """
  10. reference = context.get("vars", {}).get("reference", "")
  11. if not reference:
  12. return 0
  13. try:
  14. _, _, F1 = score([output], [reference], lang="en", verbose=False)
  15. return F1.item()
  16. except:
  17. return 0
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...