Developed by | SCB 10X |
---|---|
Date of development | Feb 15, 2024 |
Validator type | Quality |
Blog | - |
License | Apache 2 |
Input/Output | Output |
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.
- Primary intended uses: This validator is useful when you’re using multiple languages in an LLM application.
- Out-of-scope use cases: N/A
- Dependencies:
- fast_langdetect
- iso_language_codes
- transformers HuggingFace library
- facebook/nllb-200-distilled-600M translation model
- Foundation model access keys: HuggingFace
$ guardrails hub install hub://guardrails/correct_language
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,
)
guard.parse("Translated_text")
guard("Translate this to english: Danke")
N/A
CPU | GPU | |
---|---|---|
Latency | - | |
Memory | - | |
Cost | - | |
Expected quality | - |
- Dependencies:
- fast_langdetect
- iso_language_codes
- transformers HuggingFace library
- facebook/nllb-200-distilled-600M translation model
- Foundation model access keys: Huggingface auth
- Compute: Yes
N/A
Accuracy | - |
---|---|
F1 Score | - |
0.7