Download code/minijev/encoders/__init__.py from markuz89/minijev-general: direct link, hf CLI and curl.
- Browser
- Download file 1.79 kB
-
https://huggingface.co/markuz89/minijev-general/resolve/main/code/minijev/encoders/__init__.py
- Command line
-
hf download hf://markuz89/minijev-general/code/minijev/encoders/__init__.py
-
curl -L -o __init__.py https://huggingface.co/markuz89/minijev-general/resolve/main/code/minijev/encoders/__init__.py
1.79 kB
| """State encoders (modality -> tokens (B, S, d) + mask in the shared latent space). | |
| kind input key class | |
| grid state_grid GridStateEncoder (Snake uses it via environments/snake/encoder.py) | |
| text state_ids ByteTextStateEncoder | PretrainedTextStateEncoder (shares the text backbone) | |
| numeric state_x NumericStateEncoder | |
| log state_log_ids text encoder on normalised logs (see numeric.normalise_log) | |
| """ | |
| from __future__ import annotations | |
| from torch import nn | |
| from .grid import GridStateEncoder | |
| from .numeric import NumericStateEncoder | |
| from minijev.text_task_utils import normalise_log | |
| from .text import (ByteTextStateEncoder, PretrainedTextBackbone, PretrainedTextStateEncoder, Projection, | |
| QuestionEncoder, TextPooler, TextStateEncoder) | |
| from minijev.keys import STATE_INPUTS # noqa: E402 | |
| def build_state_encoder(kind: str, d: int, cfg: dict, embed: nn.Embedding | None = None, | |
| d_text: int | None = None, cls=None) -> nn.Module: | |
| cfg = dict(cfg or {}) | |
| if cls is not None: | |
| return cls(d, **cfg) | |
| if kind == "grid": | |
| return GridStateEncoder(d, **cfg) | |
| if kind in ("text", "log"): | |
| if d_text is not None: # pretrained text backbone | |
| return PretrainedTextStateEncoder(d, d_text, **cfg) | |
| return ByteTextStateEncoder(embed, d, **cfg) | |
| if kind == "numeric": | |
| return NumericStateEncoder(d, **cfg) | |
| raise ValueError(f"unknown state encoder {kind!r}") | |
| __all__ = ["STATE_INPUTS", "build_state_encoder", "GridStateEncoder", "NumericStateEncoder", "normalise_log", | |
| "ByteTextStateEncoder", "TextStateEncoder", "PretrainedTextBackbone", "PretrainedTextStateEncoder", | |
| "Projection", "QuestionEncoder", "TextPooler"] | |