llm_judge package#

Module contents#

Performs quality estimation for a list of translations using LLMs from OpenAI, Anthropic, Google, and Ollama.

Usage Options#
 usage: llm-judge [-h] -i INPUT -o OUTPUT [-c CONFIG] [-s] [--openai] [--anthropic] [--google]
                  [--ollama] [--ollama-model OLLAMA_MODEL] [--version]

 Quality estimation for a list of translations using LLMs.

 options:
   -h, --help            show this help message and exit
   -i, --input INPUT     path/name of the translations '.csv' file containing the columns 'src', 'mt',
                         'src_lang', and 'mt_lang' (str).
   -o, --output OUTPUT   path/name of the ouput file that should be written to disk (str).
   -c, --config CONFIG   path/name of the configuration file in TOML format (str).
   -s, --score-only      only calculate quality estimation scores without error annotation.
   --openai              use OpenAI model.
   --anthropic           use Anthropic model.
   --google              use Google model.
   --ollama              use Ollama model.
   --ollama-model OLLAMA_MODEL
                         which Ollama model to use, must be a valid Ollama model identifier (str).
   --version             show program's version number and exit

 (c) Micha Birklbauer, 2026
Example Usage#
 llm-judge -i data/test.csv -o data/test_annotated.csv --ollama
Example Output#
 INFO:llm_judge._main:Using OpenAI model: False
 INFO:llm_judge._main:Using Anthropic model: False
 INFO:llm_judge._main:Using Google model: False
 INFO:llm_judge._main:Using Ollama model: True
 INFO:llm_judge._judge:The following LLM-providers are enabled for this instance: Ollama!
 INFO:llm_judge._judge:Loaded the following configuration:
 -------------------- JudgeConfig --------------------
 OpenAI Model:               gpt-5.4
 OpenAI Thinking Level:      low
 Anthropic Model:            claude-opus-5
 Anthropic Thinking Level:   low
 Google Model:               gemini-3.1-pro-preview
 Google Thinking Level:      low
 Ollama Host:                http://localhost:11434
 Ollama Model:               gemma4:e4b
 Ollama Context Length:      4096
 Ollama Keep Alive Duration: -1
 Maximum Output Tokens:      2048
 Maximum Retries:            5
 Retry Waiting Time:         30.0
 Seeds:                      1337, 10081995, 18041970, 1071966, 3082023, 24042025
 -----------------------------------------------------
 INFO:llm_judge._main:Selected Ollama model: gemma4:e4b
 INFO:llm_judge._util:Reading file data/test.csv...
 INFO:llm_judge._util:Successfully read file data/test.csv!
 Annotating data/test.csv...:   0%|                                               | 0/1 [00:00<?, ?it/s]
 INFO:httpx:HTTP Request: POST http://localhost:11434/api/chat "HTTP/1.1 200 OK"
 INFO:llm_judge._judge:Successfully got a valid response after retry 0 for one query.
 Annotating data/test.csv...: 100%|███████████████████████████████████████| 1/1 [00:12<00:00, 12.23s/it]
 INFO:llm_judge._util:Finished annotation of data/test.csv!
 INFO:llm_judge._util:Writing files to disk...
 INFO:llm_judge._util:Successfully wrote file data/test_annotated.csv!
 INFO:llm_judge._util:Successfully wrote file data/test_annotated.csv.json!
 shape: (1, 8)
 ┌─────────────┬─────────────┬──────────┬─────────┬─────────────┬─────────────┬────────────┬────────────┐
 │ src         ┆ mt          ┆ src_lang ┆ mt_lang ┆ score_opena ┆ score_anthr ┆ score_goog ┆ score_olla │
 │ ---         ┆ ---         ┆ ---      ┆ ---     ┆ i           ┆ opic        ┆ le         ┆ ma_gemma4: │
 │ str         ┆ str         ┆ str      ┆ str     ┆ ---         ┆ ---         ┆ ---        ┆ e4b        │
 │             ┆             ┆          ┆         ┆ f64         ┆ f64         ┆ f64        ┆ ---        │
 │             ┆             ┆          ┆         ┆             ┆             ┆            ┆ f64        │
 ╞═════════════╪═════════════╪══════════╪═════════╪═════════════╪═════════════╪════════════╪════════════╡
 │ The lights  ┆ Die Lichter ┆ English  ┆ German  ┆ NaN         ┆ NaN         ┆ NaN        ┆ 0.95       │
 │ are         ┆ sind        ┆          ┆         ┆             ┆             ┆            ┆            │
 │ dimmable,   ┆ dimmbar,    ┆          ┆         ┆             ┆             ┆            ┆            │
 │ but I…      ┆ aber…       ┆          ┆         ┆             ┆             ┆            ┆            │
 └─────────────┴─────────────┴──────────┴─────────┴─────────────┴─────────────┴────────────┴────────────┘
 INFO:llm_judge._judge:Successfully closed all connections and clients for this instance!
 INFO:llm_judge._main:Successfully scored and annotated all translations!

Examples

>>> from llm_judge import Judge
>>> judge = Judge(openai=False, anthropic=False, google=False, ollama="mistral:7b")
>>> jr = judge.score(
...     src="The mitochondria is the powerhouse of the cell.",
...     mt="Das Mitochondrium ist das Kraftwerk der Zelle.",
...     src_lang="English",
...     mt_lang="German",
... )
>>> type(jr)
<class 'llm_judge._judge.JudgeResult'>
>>> jr.openai is None
True
>>> jr.anthropic is None
True
>>> jr.google is None
True
>>> jr.ollama is None
False
>>> type(jr.ollama)
<class 'llm_judge._judge.JudgeModelResult'>
>>> jr.ollama.model
'mistral:7b'
>>> jr.ollama.score
0.95
>>> judge.close()
>>> from llm_judge import Judge
>>> judge = Judge(
...     openai=False,
...     anthropic=False,
...     google=False,
...     ollama=True,
...     config="config/judge_config.toml",
... )
>>> jr = judge.score(
...     src="The mitochondria is the powerhouse of the cell.",
...     mt="Das Mitochondrium ist das Kraftwerk der Zelle.",
...     src_lang="English",
...     mt_lang="German",
... )
>>> type(jr)
<class 'llm_judge._judge.JudgeResult'>
>>> jr.openai is None
True
>>> jr.anthropic is None
True
>>> jr.google is None
True
>>> jr.ollama is None
False
>>> type(jr.ollama)
<class 'llm_judge._judge.JudgeModelResult'>
>>> jr.ollama.model
'qwen3.8:27b'
>>> type(jr.ollama.quality_estimation)
<class 'llm_judge._translation.QualityEstimation'>
>>> jr.ollama.score
1.0
>>> judge.close()
>>> from llm_judge import Judge
>>> judge = Judge(
...     openai=False,
...     anthropic=False,
...     google=False,
...     ollama=True,
...     config="config/judge_config.toml",
... )
>>> jr = judge.score_and_annotate(
...     src="The mitochondria is the powerhouse of the cell.",
...     mt="Das Mitochondrium ist das Kraftwerk der Zelle.",
...     src_lang="English",
...     mt_lang="German",
... )
>>> type(jr)
<class 'llm_judge._judge.JudgeResult'>
>>> jr.openai is None
True
>>> jr.anthropic is None
True
>>> jr.google is None
True
>>> jr.ollama is None
False
>>> type(jr.ollama)
<class 'llm_judge._judge.JudgeModelResult'>
>>> jr.ollama.model
'qwen3.8:27b'
>>> type(jr.ollama.quality_estimation)
<class 'llm_judge._translation.QualityEstimationAnnotated'>
>>> jr.ollama.score
1.0
>>> judge.close()
class llm_judge.Judge(
openai: bool | str | None = None,
anthropic: bool | str | None = None,
google: bool | str | None = None,
ollama: bool | str | None = None,
config: JudgeConfig | str | None = None,
)[source]#

Bases: object

Judge to rate translation quality.

Judge to rate translation quality using LLMs from OpenAI, Anthropic, Google, and Ollama.

Parameters:
  • openai (str, or bool, or None, default = None) –

    • If a string is given, an OPENAI_API_KEY is expected.

    • If None or True the API key will be attempted to be read from the environment.

    • If False the OpenAI model will not be used as a judge.

  • anthropic (str, or bool, or None, default = None) –

    • If a string is given, an ANTHROPIC_API_KEY is expected.

    • If None or True the API key will be attempted to be read from the environment.

    • If False the Anthropic model will not be used as a judge.

  • google (str, or bool, or None, default = None) –

    • If a string is given, an GEMINI_API_KEY is expected.

    • If None or True the API key will be attempted to be read from the environment.

    • If False the Google model will not be used as a judge.

  • ollama (str, or bool, or None, default = None) –

    • If a string is given, an Ollama model identifier (e.g. gemma4:e4b) is expected.

    • If None or True the Ollama model from the config file will be used.

    • If False the Ollama model will not be used as a judge.

  • config (JudgeConfig, str, or None, default = None) –

    • The configuration for the LLMs/Judge.

    • If a string is given, the path to a judge_config.toml file is expected.

    • If None the default configuration will be loaded.

Raises:
  • RuntimeError – If an Ollama model identifier was provided with parameter ollama but a configuration was also provided via config (potential clash in model identifiers).

  • ValueError – If none of the LLM providers were setup.

Examples

>>> from llm_judge import Judge
>>> judge = Judge(openai=False, anthropic=False, google=False, ollama="mistral:7b")
>>> # do something with the judge
>>> judge.close()
close() → None[source]#

Closes all connections and clients.

Closes all connections and all running LLM-provider clients.

Warning

This should be called at the end when the Judge instance is not longer needed!

Examples

>>> from llm_judge import Judge
>>> with Judge(
...     openai=False, anthropic=False, google=False, ollama="mistral:7b"
... ) as judge:
>>>     jr = judge.score(
...         src="The mitochondria is the powerhouse of the cell.",
...         mt="Das Mitochondrium ist das Kraftwerk der Zelle.",
...         src_lang="English",
...         mt_lang="German",
...     )
>>> jr.ollama.score
0.95
>>> from llm_judge import Judge
>>> judge = Judge(
...     openai=False, anthropic=False, google=False, ollama="mistral:7b"
... )
>>> jr = judge.score(
...     src="The mitochondria is the powerhouse of the cell.",
...     mt="Das Mitochondrium ist das Kraftwerk der Zelle.",
...     src_lang="English",
...     mt_lang="German",
... )
>>> jr.ollama.score
0.95
>>> judge.close()
score(
src: str,
mt: str,
src_lang: str,
mt_lang: str,
) → JudgeResult[source]#

Performs quality estimation without annotation.

Performs quality estimation without error annotation using all setup LLMs for one translation. This means that LLMs will only return a quality estimation score but no annotation of how that score was reasoned. The type of JudgeModelResult.quality_estimation for each applied LLM will always be QualityEstimation - if a successful reponse was received.

Parameters:
  • src (str) – The source text.

  • mt (str) – The machine translation.

  • src_lang (str) – The language of the source text, e.g. "English".

  • mt_lang (str) – The language of the machine translation, e.g. "German".

Returns:

The results of all LLMs in a result container, see JudgeResult.

Return type:

JudgeResult

Raises:

RuntimeError – If the Judge instance is already closed.

Examples

>>> from llm_judge import Judge
>>> judge = Judge(
...     openai=False, anthropic=False, google=False, ollama="mistral:7b"
... )
>>> jr = judge.score(
...     src="The mitochondria is the powerhouse of the cell.",
...     mt="Das Mitochondrium ist das Kraftwerk der Zelle.",
...     src_lang="English",
...     mt_lang="German",
... )
>>> type(jr)
<class 'llm_judge._judge.JudgeResult'>
>>> jr.openai is None
True
>>> jr.anthropic is None
True
>>> jr.google is None
True
>>> jr.ollama is None
False
>>> type(jr.ollama)
<class 'llm_judge._judge.JudgeModelResult'>
>>> jr.ollama.model
'mistral:7b'
>>> jr.ollama.score
0.95
>>> type(jr.ollama.quality_estimation)
<class 'llm_judge._translation.QualityEstimation'>
>>> judge.close()
>>> from llm_judge import Judge
>>> judge = Judge(
...     openai=False,
...     anthropic=False,
...     google=False,
...     ollama=True,
...     config="config/judge_config.toml",
... )
>>> jr = judge.score(
...     src="The mitochondria is the powerhouse of the cell.",
...     mt="Das Mitochondrium ist das Kraftwerk der Zelle.",
...     src_lang="English",
...     mt_lang="German",
... )
>>> type(jr)
<class 'llm_judge._judge.JudgeResult'>
>>> jr.openai is None
True
>>> jr.anthropic is None
True
>>> jr.google is None
True
>>> jr.ollama is None
False
>>> type(jr.ollama)
<class 'llm_judge._judge.JudgeModelResult'>
>>> jr.ollama.model
'qwen3.8:27b'
>>> jr.ollama.score
1.0
>>> type(jr.ollama.quality_estimation)
<class 'llm_judge._translation.QualityEstimation'>
>>> judge.close()
score_and_annotate(
src: str,
mt: str,
src_lang: str,
mt_lang: str,
) → JudgeResult[source]#

Performs quality estimation with annotation.

Performs quality estimation with error annotation using all setup LLMs for one translation. The type of JudgeModelResult.quality_estimation for each applied LLM will always be QualityEstimationAnnotated - if a successful reponse was received.

Parameters:
  • src (str) – The source text.

  • mt (str) – The machine translation.

  • src_lang (str) – The language of the source text, e.g. "English".

  • mt_lang (str) – The language of the machine translation, e.g. "German".

Returns:

The results of all LLMs in a result container, see JudgeResult.

Return type:

JudgeResult

Raises:

RuntimeError – If the Judge instance is already closed.

Examples

>>> from llm_judge import Judge
>>> judge = Judge(
...     openai=False, anthropic=False, google=False, ollama="mistral:7b"
... )
>>> jr = judge.score_and_annotate(
...     src="The mitochondria is the powerhouse of the cell.",
...     mt="Das Mitochondrium ist das Kraftwerk der Zelle.",
...     src_lang="English",
...     mt_lang="German",
... )
>>> type(jr)
<class 'llm_judge._judge.JudgeResult'>
>>> jr.openai is None
True
>>> jr.anthropic is None
True
>>> jr.google is None
True
>>> jr.ollama is None
False
>>> type(jr.ollama)
<class 'llm_judge._judge.JudgeModelResult'>
>>> jr.ollama.model
'mistral:7b'
>>> jr.ollama.score
0.95
>>> type(jr.ollama.quality_estimation)
<class 'llm_judge._translation.QualityEstimationAnnotated'>
>>> judge.close()
>>> from llm_judge import Judge
>>> judge = Judge(
...     openai=False,
...     anthropic=False,
...     google=False,
...     ollama=True,
...     config="config/judge_config.toml",
... )
>>> jr = judge.score_and_annotate(
...     src="The mitochondria is the powerhouse of the cell.",
...     mt="Das Mitochondrium ist das Kraftwerk der Zelle.",
...     src_lang="English",
...     mt_lang="German",
... )
>>> type(jr)
<class 'llm_judge._judge.JudgeResult'>
>>> jr.openai is None
True
>>> jr.anthropic is None
True
>>> jr.google is None
True
>>> jr.ollama is None
False
>>> type(jr.ollama)
<class 'llm_judge._judge.JudgeModelResult'>
>>> jr.ollama.model
'qwen3.8:27b'
>>> jr.ollama.score
1.0
>>> type(jr.ollama.quality_estimation)
<class 'llm_judge._translation.QualityEstimationAnnotated'>
>>> judge.close()
class llm_judge.JudgeConfig(
*,
openai_model: str = 'gpt-5.4',
openai_thinking_level: Literal['none', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max'] = 'low',
anthropic_model: str = 'claude-opus-5',
anthropic_thinking_level: Literal['low', 'medium', 'high', 'xhigh', 'max'] = 'low',
google_model: str = 'gemini-3.1-pro-preview',
google_thinking_level: str = 'low',
ollama_host: str = 'http://localhost:11434',
ollama_model: str = 'gemma4:e4b',
ollama_context_length: Annotated[int, Ge(ge=1)] = 4096,
ollama_keep_alive: int | str = -1,
max_output_tokens: Annotated[int, Ge(ge=1)] = 2048,
max_retry: Annotated[int, Ge(ge=0)] = 5,
retry_wait_time: Annotated[float, Ge(ge=0.0)] = 30.0,
seeds: list[int] = [1337, 10081995, 18041970, 1071966, 3082023, 24042025],
)[source]#

Bases: BaseModel

Configuration for all LLM-providers.

anthropic_model: Annotated[str, Field(frozen=True, description='The Anthropic model identifier.')]#

The Anthropic model identifier. See here.

anthropic_thinking_level: Annotated[Literal['low', 'medium', 'high', 'xhigh', 'max'], Field(frozen=True, description='The Anthropic thinking level of the model.')]#

The Anthropic thinking level of the model. See here.

google_model: Annotated[str, Field(frozen=True, description='The Google model identifier.')]#

The Google model identifier. See here.

google_thinking_level: Annotated[str, Field(frozen=True, description='The Google thinking level of the model.')]#

The Google thinking level of the model. See here and here.

max_output_tokens: Annotated[int, Field(ge=1, frozen=True, description='Maximum number of output tokens to generate.')]#

Maximum number of output tokens to generate.

max_retry: Annotated[int, Field(ge=0, frozen=True, description='The maximum number of request retries.')]#

The maximum number of request retries for failed API calls.

model_config = {'str_strip_whitespace': True, 'strict': True, 'validate_assignment': True}#

Pydantic configuration for the underlying validation model.

model_post_init(context: Any = None) → None[source]#

Performs extra validation and post init functions.

Warning

This method should not be called manually!

classmethod model_validate_toml(toml_path: str) → JudgeConfig[source]#

Validate the given TOML data against the Pydantic model.

Parameters:

toml_path (str) – Path/name of the TOML file.

Returns:

The parsed JudgeConfig instance.

Return type:

JudgeConfig

Raises:

RuntimeError – If the TOML file could not be read.

Examples

>>> from llm_judge import JudgeConfig
>>> jc = JudgeConfig.model_validate_toml("config/judge_config.toml")
>>> jc.openai_model
'gpt-6-astra'
ollama_context_length: Annotated[int, Field(ge=1, frozen=True, description='Maximum number of tokens a model has access to in memory')]#

Maximum number of tokens a model has access to in memory. See here.

ollama_host: Annotated[str, Field(frozen=True, description='The Ollama host address.')]#

The Ollama host address (optionally including port).

ollama_keep_alive: Annotated[int | str, Field(frozen=True, description='The Ollama model in-memory duration.')]#

The Ollama model in-memory duration.

ollama_model: Annotated[str, Field(frozen=True, description='The Ollama model to use.')]#

The Ollama model to use, given as a valid model identifier. See here.

openai_model: Annotated[str, Field(frozen=True, description='The OpenAI model identifier.')]#

The OpenAI model identifier. See here.

openai_thinking_level: Annotated[Literal['none', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max'], Field(frozen=True, description='The OpenAI thinking level of the model.')]#

The OpenAI thinking level of the model. See here and here.

retry_wait_time: Annotated[float, Field(ge=0.0, frozen=True, description='Time in seconds to wait between failed API requests.')]#

Time in seconds to wait between failed API requests.

seeds: Annotated[list[int], Field(frozen=True, description='Random seeds to use for generation.')]#

Random seeds to use for generation. Length must be at least``max_retry + 1``.

class llm_judge.JudgeModelResult(
*,
model: str,
prompt: str,
status: Literal['ok', 'error'],
parameters: dict[str, str] | None,
response: str | None,
quality_estimation: QualityEstimation | QualityEstimationAnnotated | None,
quality_estimation_dict: dict[str, Any] | None,
)[source]#

Bases: BaseModel

Quality estimation result for one specific query and LLM.

model: Annotated[str, Field(frozen=True, description='The name of the LLM.')]#

The name of the LLM.

model_config = {'str_strip_whitespace': True, 'strict': True, 'validate_assignment': True}#

Pydantic configuration for the underlying validation model.

parameters: Annotated[dict[str, str] | None, Field(frozen=True, description='Additional parameters passed to the LLM.')]#

Additional parameters passed to the LLM.

prompt: Annotated[str, Field(frozen=True, description='The prompt used with the LLM.')]#

The prompt used with the LLM.

quality_estimation: Annotated[QualityEstimation | QualityEstimationAnnotated | None, Field(frozen=True, description='The quality estimation returned by the LLM.')]#

The quality estimation returned by the LLM.

quality_estimation_dict: Annotated[dict[str, Any] | None, Field(frozen=True, description='The quality estimation returned by the LLM as json.')]#

The quality estimation returned by the LLM as json.

response: Annotated[str | None, Field(frozen=True, description='The LLM response as raw text.')]#

The LLM response as raw text.

property score: float#

The quality estimation score returned by the LLM (if any - maybe ‘nan’).

status: Annotated[Literal['ok', 'error'], Field(frozen=True, description='Status of the response.')]#

Status of the response. Can be ‘ok’ or ‘error’. Only ‘ok’ denotes a successful response.

class llm_judge.JudgeResult(
*,
openai: JudgeModelResult | None,
anthropic: JudgeModelResult | None,
google: JudgeModelResult | None,
ollama: JudgeModelResult | None,
)[source]#

Bases: BaseModel

Quality estimation results for one specific query and all LLMs.

anthropic: Annotated[JudgeModelResult | None, Field(frozen=True, description='Result of the Anthropic model.')]#

Result of the Anthropic model. ‘None’ if the model was not setup.

google: Annotated[JudgeModelResult | None, Field(frozen=True, description='Result of the Google model.')]#

Result of the Google model. ‘None’ if the model was not setup.

model_config = {'str_strip_whitespace': True, 'strict': True, 'validate_assignment': True}#

Pydantic configuration for the underlying validation model.

ollama: Annotated[JudgeModelResult | None, Field(frozen=True, description='Result of the Ollama model.')]#

Result of the Ollama model. ‘None’ if the model was not setup.

openai: Annotated[JudgeModelResult | None, Field(frozen=True, description='Result of the OpenAI model.')]#

Result of the OpenAI model. ‘None’ if the model was not setup.

class llm_judge.QualityEstimation(
*,
quality_estimation_value: Annotated[float, Ge(ge=0.0), Le(le=100.0)],
)[source]#

Bases: BaseModel

model_config = {}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

quality_estimation_value: float#
class llm_judge.QualityEstimationAnnotated(
*,
quality_estimation_value: Annotated[float, Ge(ge=0.0), Le(le=100.0)],
source: str,
machine_translation: str,
errors: Annotated[list[TranslationErrorAccuracy | TranslationErrorFluency | TranslationErrorStyle | TranslationErrorTerminology | TranslationErrorNontranslation | TranslationErrorOther | TranslationErrorNoerror], MinLen(min_length=0)],
)[source]#

Bases: QualityEstimation

errors: list[TranslationErrorAccuracy | TranslationErrorFluency | TranslationErrorStyle | TranslationErrorTerminology | TranslationErrorNontranslation | TranslationErrorOther | TranslationErrorNoerror]#
machine_translation: str#
model_config = {}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

source: str#
class llm_judge.TranslationError(
*,
error_type: Literal['accuracy', 'fluency', 'style', 'terminology', 'non-translation', 'other', 'no-error'],
error_subtype: Literal['addition', 'mistranslation', 'omission', 'untranslated text', 'character encoding', 'grammar', 'inconsistency', 'punctuation', 'register', 'spelling', 'awkward', 'inappropriate for context', 'inconsistent use', 'no-subtype'],
error_severity: Literal['critical', 'major', 'minor'],
error_index_start: Annotated[int, Ge(ge=0)],
error_index_end: Annotated[int, Ge(ge=0)],
description: str,
location: str,
)[source]#

Bases: BaseModel

description: str#
error_index_end: int#
error_index_start: int#
error_severity: Literal['critical', 'major', 'minor']#
error_subtype: Literal['addition', 'mistranslation', 'omission', 'untranslated text', 'character encoding', 'grammar', 'inconsistency', 'punctuation', 'register', 'spelling', 'awkward', 'inappropriate for context', 'inconsistent use', 'no-subtype']#
error_type: Literal['accuracy', 'fluency', 'style', 'terminology', 'non-translation', 'other', 'no-error']#
location: str#
model_config = {}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class llm_judge.TranslationErrorAccuracy(
*,
error_type: Literal['accuracy'],
error_subtype: Literal['addition', 'mistranslation', 'omission', 'untranslated text'],
error_severity: Literal['critical', 'major', 'minor'],
error_index_start: Annotated[int, Ge(ge=0)],
error_index_end: Annotated[int, Ge(ge=0)],
description: str,
location: str,
)[source]#

Bases: TranslationError

error_subtype: Literal['addition', 'mistranslation', 'omission', 'untranslated text']#
error_type: Literal['accuracy']#
model_config = {}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class llm_judge.TranslationErrorFluency(
*,
error_type: Literal['fluency'],
error_subtype: Literal['character encoding', 'grammar', 'inconsistency', 'punctuation', 'register', 'spelling'],
error_severity: Literal['critical', 'major', 'minor'],
error_index_start: Annotated[int, Ge(ge=0)],
error_index_end: Annotated[int, Ge(ge=0)],
description: str,
location: str,
)[source]#

Bases: TranslationError

error_subtype: Literal['character encoding', 'grammar', 'inconsistency', 'punctuation', 'register', 'spelling']#
error_type: Literal['fluency']#
model_config = {}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class llm_judge.TranslationErrorNoerror(
*,
error_type: Literal['no-error'],
error_subtype: Literal['no-subtype'],
error_severity: Literal['critical', 'major', 'minor'],
error_index_start: Annotated[int, Ge(ge=0)],
error_index_end: Annotated[int, Ge(ge=0)],
description: str,
location: str,
)[source]#

Bases: TranslationError

error_subtype: Literal['no-subtype']#
error_type: Literal['no-error']#
model_config = {}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class llm_judge.TranslationErrorNontranslation(
*,
error_type: Literal['non-translation'],
error_subtype: Literal['no-subtype'],
error_severity: Literal['critical', 'major', 'minor'],
error_index_start: Annotated[int, Ge(ge=0)],
error_index_end: Annotated[int, Ge(ge=0)],
description: str,
location: str,
)[source]#

Bases: TranslationError

error_subtype: Literal['no-subtype']#
error_type: Literal['non-translation']#
model_config = {}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class llm_judge.TranslationErrorOther(
*,
error_type: Literal['other'],
error_subtype: Literal['no-subtype'],
error_severity: Literal['critical', 'major', 'minor'],
error_index_start: Annotated[int, Ge(ge=0)],
error_index_end: Annotated[int, Ge(ge=0)],
description: str,
location: str,
)[source]#

Bases: TranslationError

error_subtype: Literal['no-subtype']#
error_type: Literal['other']#
model_config = {}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class llm_judge.TranslationErrorStyle(
*,
error_type: Literal['style'],
error_subtype: Literal['awkward'],
error_severity: Literal['critical', 'major', 'minor'],
error_index_start: Annotated[int, Ge(ge=0)],
error_index_end: Annotated[int, Ge(ge=0)],
description: str,
location: str,
)[source]#

Bases: TranslationError

error_subtype: Literal['awkward']#
error_type: Literal['style']#
model_config = {}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class llm_judge.TranslationErrorTerminology(
*,
error_type: Literal['terminology'],
error_subtype: Literal['inappropriate for context', 'inconsistent use'],
error_severity: Literal['critical', 'major', 'minor'],
error_index_start: Annotated[int, Ge(ge=0)],
error_index_end: Annotated[int, Ge(ge=0)],
description: str,
location: str,
)[source]#

Bases: TranslationError

error_subtype: Literal['inappropriate for context', 'inconsistent use']#
error_type: Literal['terminology']#
model_config = {}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

llm_judge.annotate_csv(
input_file: str,
judge: Judge,
score_only: bool = False,
output_file: str | None = None,
) → tuple[DataFrame, list[JudgeResult]][source]#

Quality estimation for a list of translations in a ‘.csv’ file using LLMs.

Parameters:
  • input_file (str) – Path/name of the translations ‘.csv’ file containing the columns src, mt, src_lang, and mt_lang.

  • judge (Judge) – The judge to be used for quality estimation.

  • score_only (bool, default = False) – If True translations will only be scored without error annotation. Internally, if True the function Judge.score() is called, otherwise (default) Judge.score_and_annotate() is called.

  • output_file (str, or None, default = None) – Path/name of the ouput file that should be written to disk. If None nothing is written to disk.

Returns:

Results as a polars.DataFrame and as list of JudgeResult.

Return type:

tuple of polars.DataFrame and list of JudgeResult

Examples

>>> from llm_judge import annotate_csv, Judge
>>> judge = Judge(openai=False, anthropic=False, google=False, ollama="mistral:7b")
>>> pl_df, list_jr = annotate_csv("data/test.csv", judge=judge)
Annotating data/test.csv...: 100%|█████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:04<00:00,  4.96s/it]
>>> pl_df
shape: (1, 8)
┌──────────────────────────────────┬──────────────────┬──────────┬─────────┬──────────────┬─────────────────┬──────────────┬─────────────────────────┐
│ src                              ┆ mt               ┆ src_lang ┆ mt_lang ┆ score_openai ┆ score_anthropic ┆ score_google ┆ score_ollama_mistral:7b │
│ ---                              ┆ ---              ┆ ---      ┆ ---     ┆ ---          ┆ ---             ┆ ---          ┆ ---                     │
│ str                              ┆ str              ┆ str      ┆ str     ┆ f64          ┆ f64             ┆ f64          ┆ f64                     │
╞══════════════════════════════════╪══════════════════╪══════════╪═════════╪══════════════╪═════════════════╪══════════════╪═════════════════════════╡
│ The lights are dimmable, but I…  ┆ Die Lichter sind ┆ English  ┆ German  ┆ NaN          ┆ NaN             ┆ NaN          ┆ 0.95                    │
│                                  ┆ dimmbar, aber…   ┆          ┆         ┆              ┆                 ┆              ┆                         │
└──────────────────────────────────┴──────────────────┴──────────┴─────────┴──────────────┴─────────────────┴──────────────┴─────────────────────────┘
>>> len(list_jr)
1
>>> type(list_jr[0])
<class 'llm_judge._judge.JudgeResult'>
>>> judge.close()
llm_judge.main(argv: list[str] | None = None) → int[source]#

Main function.

Parameters:

argv (list or str, or None, default = None) – Arguments passed to argparse.

Returns:

Exit status (zero is success).

Return type:

int

Examples

>>> from llm_judge import main
>>> main(["-i", "data/test.csv", "-o", "data/test_annotated.csv", "--ollama"])