> ## Documentation Index
> Fetch the complete documentation index at: https://proto.evodesign.org/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# gLM2 Perplexity

> Score protein or DNA naturalness by gLM2/Minerva masked mean NLL.

![gLM2 Perplexity](https://proto-bio.github.io/proto-assets/images/constraint/glm2-perplexity/hero.png)

> [!NOTE]
>
> **License:** This constraint can use multiple tools, each under its own license. See the **Tools Used** tab and each tool's page for license details.

This constraint is open source. Any third-party models, product names, or trademarks referenced are the property of their respective owners, and Proto is not affiliated with them.

***

&#x20;Tools Used Tools Used  Source Source

[![](https://proto-bio.github.io/proto-assets/images/tool/glm2/social.png)](https://proto.evodesign.org/docs/tools/masked-models/glm2.md)

[![](https://proto-bio.github.io/proto-assets/images/tool/minerva/social.png)](https://proto.evodesign.org/docs/tools/masked-models/minerva.md)

![Proto](https://mintcdn.com/bio-pro/cMLt8hAqaP9M3LKy/assets/logo/logo-light.svg?fit=max\&auto=format\&n=cMLt8hAqaP9M3LKy\&q=85\&s=f5e5dfd1b8f9b9db3a0be0e2eb01f678)

evo-design/proto-language

&#x20;View source

[Open](https://github.com/evo-design/proto-language/blob/1a97e675c7e5e4ae0e92be91b1bb7b49f1331104/proto_language/constraint/sequence_scoring/glm2_perplexity_constraint.py#L210)

Constraint contributors[![](https://avatars.githubusercontent.com/u/61667248?v=4\&s=64)adititm](https://github.com/adititm)[![](https://avatars.githubusercontent.com/u/21143637?v=4\&s=64)bviggiano](https://github.com/bviggiano)
Forward gLM2/Minerva scoring of the one-hot sequence via masked pseudo-log-likelihood.

## API Reference

ConfigGLM2PerplexityConfig[ Source](https://github.com/evo-design/proto-language/blob/1a97e675c7e5e4ae0e92be91b1bb7b49f1331104/proto_language/constraint/sequence_scoring/glm2_perplexity_constraint.py#L53)

Configuration for gLM2/Minerva perplexity scoring (forward + gradient).

**model\_checkpoint** `enum` (default: tattabio/gLM2\_650M)

gLM2 ('tattabio/...') or Minerva-MLM ('gbrixi/...') checkpoint

Options: `tattabio/gLM2_150M`, `tattabio/gLM2_650M`, `gbrixi/minerva-mlm`, `gbrixi/minerva-mlm-8k`

**temperature** `number` *required*

Softmax temperature applied to logits (fixed for this constraint).

**use\_ste** `boolean` (default: True)

Hard one-hot forward pass with soft-probability gradients.

**device** `string` (default: cuda)

Device for model execution, e.g. 'cuda' or 'cuda:0'.

**batch\_size** `integer`

Masked PLL variants per forward pass; lower if OOM.

**score\_mode** `enum` (default: nll)

Return raw mean NLL by default, or perplexity when set to 'ppl'.

Options: `nll`, `ppl`

**logit\_scale** `number` (default: 1.0)

Pre-scale raw logits; gradients are scaled back by the same factor.

ReturnsConstraintOutput

Per-proposal scores with NLL and perplexity metadata.

## Usage

```python python icon="python" theme={null}
from proto_language.core import Constraint
from proto_language.constraint import glm2_perplexity_constraint, GLM2PerplexityConfig

constraint = Constraint(
    inputs=[segment],
    function=glm2_perplexity_constraint,
    function_config=GLM2PerplexityConfig(
        # Configure parameters here
    ),
)

scores = constraint.evaluate()
```

## Metadata

| Property | Value |
| - | - |
| Key | `glm2-perplexity` |
| Function | `glm2_perplexity_constraint` |
| Category | `sequence_scoring` |
| Mode | `dual` |
| Uses GPU | `True` |
| Supported Types | `protein`, `dna` |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.