Small language models that run locally to evaluate AI system safety and quality
Weave’s local scorers are a suite of small language models that run locally on your machine with minimal latency. These models evaluate the safety and quality of your AI system’s inputs, context, and outputs.Some of these models are fine-tuned by Weights & Biases, while others are state-of-the-art open-source models trained by the community. Weights & Biases (W&B) Reports were used for training and evaluation. You can find the full details in this list of W&B Reports.The model weights are publicly available in W&B Artifacts, and are automatically downloaded when you instantiate the scorer class. The artifact paths can be found here if you’d like to download them yourself: weave.scorers.default_modelsThe object returned by these scorers contains a passed boolean attribute indicating whether the input text is safe or high quality, as well as a metadata attribute that contains more detail such as the raw score from the model.
While local scorers can be run on CPUs and GPUs, use GPUs for best performance.
import weavefrom weave.scorers import WeaveBiasScorerV1bias_scorer = WeaveBiasScorerV1()result = bias_scorer.score(output="Martian men are terrible at cleaning")print(f"The text is biased: {not result.passed}")print(result)
import weavefrom weave.scorers import WeaveToxicityScorerV1toxicity_scorer = WeaveToxicityScorerV1()result = toxicity_scorer.score(output="people from the south pole of Mars are the worst")print(f"Input is toxic: {not result.passed}")print(result)
This scorer checks if your AI system’s output contains any hallucinations based on the input data.The WeaveHallucinationScorerV1 uses the open source HHEM 2.1 model from Vectara. For more information, see the WeaveHallucinationScorerV1 W&B Report.
import weavefrom weave.scorers import WeaveHallucinationScorerV1hallucination_scorer = WeaveHallucinationScorerV1()result = hallucination_scorer.score( query="What is the capital of Antarctica?", context="People in Antarctica love the penguins.", output="While Antarctica is known for its sea life, penguins aren't liked there.")print(f"Output is hallucinated: {not result.passed}")print(result)
This scorer is designed to be used when evaluating RAG systems. It scores the relevance of the context to the query.The WeaveContextRelevanceScorerV1 uses a fine-tuned deberta-small-long-nli model from tasksource. For more details, see the WeaveContextRelevanceScorerV1 W&B Report.
import weavefrom weave.scorers import WeaveContextRelevanceScorerV1context_relevance_scorer = WeaveContextRelevanceScorerV1()result = context_relevance_scorer.score( query="What is the capital of Antarctica?", output="The Antarctic has the happiest penguins." # context is passed to the output parameter)print(f"Output is relevant: {result.passed}")print(result)
import weavefrom weave.scorers import WeaveCoherenceScorerV1coherence_scorer = WeaveCoherenceScorerV1()result = coherence_scorer.score( query="What is the capital of Antarctica?", output="but why not monkey up day")print(f"Output is coherent: {result.passed}")print(result)
This scorer checks whether the input text is fluent—that is, easy to read and understand, similar to natural human language. It evaluates grammar, syntax, and overall readability.The WeaveFluencyScorerV1 uses a fine-tuned ModernBERT-base model from AnswerDotAI. For more information, see the WeaveFluencyScorerV1 W&B Report.
The WeaveTrustScorerV1 is a composite scorer for RAG systems that evaluates the trustworthiness of model outputs by grouping other scorers into two categories: Critical and Advisory. Based on the composite score, it returns a trust level:
high: No issues detected
medium: Only Advisory issues detected
low: Critical issues detected or input is empty
Any input that fails a Critical scorer results in a low trust level. Failing an Advisory scorer results in medium.
import weavefrom weave.scorers import WeaveTrustScorerV1trust_scorer = WeaveTrustScorerV1()def print_trust_scorer_result(result): print() print(f"Output is trustworthy: {result.passed}") print(f"Trust level: {result.metadata['trust_level']}") if not result.passed: print("Triggered scorers:") for scorer_name, scorer_data in result.metadata['raw_outputs'].items(): if not scorer_data.passed: print(f" - {scorer_name} did not pass") print() print(f"WeaveToxicityScorerV1 scores: {result.metadata['scores']['WeaveToxicityScorerV1']}") print(f"WeaveHallucinationScorerV1 scores: {result.metadata['scores']['WeaveHallucinationScorerV1']}") print(f"WeaveContextRelevanceScorerV1 score: {result.metadata['scores']['WeaveContextRelevanceScorerV1']}") print(f"WeaveCoherenceScorerV1 score: {result.metadata['scores']['WeaveCoherenceScorerV1']}") print(f"WeaveFluencyScorerV1: {result.metadata['scores']['WeaveFluencyScorerV1']}") print()result = trust_scorer.score( query="What is the capital of Antarctica?", context="People in Antarctica love the penguins.", output="The cat stretched lazily in the warm sunlight.")print_trust_scorer_result(result)print(result)
To specify specific entity types, such as emails or phone numbers, pass a list of Presidio entities to the selected_entities parameter. Otherwise, Presidio will detect all entity types in its default entities list.
To detect specific entity types, such as emails or phone numbers, pass a list to the selected_entities parameter.
You can pass custom recognizers via the custom_recognizers parameter as a list of presidio.EntityRecognizer instances.
To handle non-English input, use the language parameter to specify the language.
import weavefrom weave.scorers import PresidioScorerpresidio_scorer = PresidioScorer()result = presidio_scorer.score( output="Mary Jane is a software engineer at XYZ company and her email is mary.jane@xyz.com.")print(f"Output contains PII: {not result.passed}")print(result)
Weave local scorers are not available in TypeScript yet. Stay tuned!To use Weave scorers in TypeScript, see function-based scorers.