Code Monkey home page Code Monkey logo

correct_language_validator's Introduction

Overview

Developed by SCB 10X
Date of development Feb 15, 2024
Validator type Quality
Blog -
License Apache 2
Input/Output Output

Description

Validate that an LLM-generated text is in the expected language. If the text is not in the expected language, the validator will attempt to translate it to the expected language.

Use fast-langdetect library to detect the language of the input text, and iso-language-codes library to get the language names from the ISO codes.

Utilize Meta's facebook/nllb-200-distilled-600M translation model (available on Huggingface) to translate the text from the detected language to the expected language.

Intended use

  • Primary intended uses: This validator is useful when you’re using multiple languages in an LLM application.
  • Out-of-scope use cases: N/A

Resources required

  • Dependencies:
    • fast_langdetect
    • iso_language_codes
    • transformers HuggingFace library
    • facebook/nllb-200-distilled-600M translation model
  • Foundation model access keys: HuggingFace

Example Usage Guide

Installation

$ guardrails hub install hub://guardrails/correct_language

Initialization

from guardrails.hub import CorrectLanguage

# Create validator
language_validator = CorrectLanguage(expected_language_iso="en", threshold=0.75)

# Create Guard with Validator
guard = Guard.from_string(
    validators=[language_validator, ...],
    num_reasks=2,
)

Invocation

guard.parse("Translated_text")

guard("Translate this to english: Danke")

API Ref

N/A

Expected deployment metrics

CPU GPU
Latency -
Memory -
Cost -
Expected quality -

Resources required

  • Dependencies:
    • fast_langdetect
    • iso_language_codes
    • transformers HuggingFace library
    • facebook/nllb-200-distilled-600M translation model
  • Foundation model access keys: Huggingface auth
  • Compute: Yes

Validator Performance

Evaluation Dataset

N/A

Model Performance Measures

Accuracy -
F1 Score -

Decision thresholds

0.7

correct_language_validator's People

Contributors

kunato avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.