コンテンツにスキップ

Attention系

実体: griffith_logic.models.attention.boolean_attention.DLGNBooleanAttention(クラス)

class DLGNBooleanAttention(config: BooleanAttentionConfig, device: str = 'cpu')

論理ゲート版 Attention 機構。

アーキテクチャ: 入力 (batch, input_dim) 二値ベクトル [0,1] ↓ parse_input Q (batch, key_bits), Ks (batch, num_pairs, key_bits), Vs (batch, num_pairs, value_bits) ↓ key_encoder / query_encoder / value_encoder (LutStack) q (batch, d_attn), k (batch, num_pairs, d_attn), v (batch, num_pairs, d_val) ↓ XNOR 類似度 scores (batch, num_pairs) ↓ softmax or argmax で Value 選択 selected (batch, d_val) ↓ output_decoder (LutStack + GroupSum) logits (batch, num_classes)

このAPIを使っている例

実体: griffith_logic.models.attention.boolean_attention.BooleanAttentionConfig(クラス)

class BooleanAttentionConfig(
num_pairs: int = 4,
key_bits: int = 4,
value_bits: int = 4,
encoder_sizes: list = (lambda: [32, 16])(),
value_encoder_sizes: list = (lambda: [32, 16])(),
decoder_sizes: list = (lambda: [64, 32])(),
n_inputs: int = 2,
parameterization: str = 'softmax',
connections: str = 'random',
grad_factor: float = 1.0,
tau_attn: float = 1.0,
share_key_query: bool = True,
tau_out: float = 1.0,
tau_warp: float = 1.0,
gumbel: bool = True,
)

DLGNBooleanAttention のハイパーパラメータ。

このAPIを使っている例

実体: griffith_logic.models.attention.multi_query_attention.DLGNMultiQueryAttention(クラス)

class DLGNMultiQueryAttention(config: MultiQueryAttentionConfig, device: str = 'cpu')

マルチクエリ版 DLGN Boolean Attention。

入力フォーマット: x = [K1, V1, …, K_np, V_np, Q1, Q2, …, Q_nq]

出力: logits (batch, num_queries, num_classes)

このAPIを使っている例

実体: griffith_logic.models.attention.multi_query_attention.MultiQueryAttentionConfig(クラス)

class MultiQueryAttentionConfig(
num_pairs: int = 4,
num_queries: int = 3,
key_bits: int = 4,
value_bits: int = 4,
encoder_sizes: list = (lambda: [32, 16])(),
value_encoder_sizes: list = (lambda: [32, 16])(),
decoder_sizes: list = (lambda: [64, 32])(),
n_inputs: int = 2,
parameterization: str = 'softmax',
connections: str = 'random',
grad_factor: float = 1.0,
tau_attn: float = 1.0,
share_key_query: bool = True,
tau_out: float = 1.0,
tau_warp: float = 1.0,
gumbel: bool = True,
)

DLGNMultiQueryAttention のハイパーパラメータ。

このAPIを使っている例

実体: griffith_logic.models.attention.positional_attention.DLGNPositionalAttention(クラス)

class DLGNPositionalAttention(config: PositionalAttentionConfig, device: str = 'cpu')

位置ベース DLGN Attention。

アーキテクチャ: 入力: [V0, V1, …, V(N-1), pos] (フラット二値) ↓ parse values (batch, num_slots, value_bits), pos (batch, pos_bits) ↓ key_encoder: 固定の位置インデックス [0..N-1] → (num_slots, d_attn) ↓ query_encoder(pos) → (batch, d_attn) ↓ value_encoder(values) → (batch, num_slots, d_val) ↓ XNOR 類似度 scores (batch, num_slots) ↓ softmax/argmax → selected (batch, d_val) ↓ output_decoder + GroupSum logits (batch, num_classes)

このAPIを使っている例

実体: griffith_logic.models.attention.positional_attention.PositionalAttentionConfig(クラス)

class PositionalAttentionConfig(
pos_bits: int = 3,
value_bits: int = 4,
encoder_sizes: list = (lambda: [32, 16])(),
value_encoder_sizes: list = (lambda: [32, 16])(),
decoder_sizes: list = (lambda: [64, 32])(),
n_inputs: int = 2,
parameterization: str = 'softmax',
connections: str = 'random',
grad_factor: float = 1.0,
tau_attn: float = 1.0,
share_key_query: bool = True,
tau_out: float = 1.0,
tau_warp: float = 1.0,
gumbel: bool = True,
)

DLGNPositionalAttention のハイパーパラメータ。

このAPIを使っている例

実体: griffith_logic.models.attention.attention_seq2seq.DLGNAttentionSeq2Seq(クラス)

class DLGNAttentionSeq2Seq(config: AttentionSeq2SeqConfig, device: str = 'cpu')

DLGN Boolean Attention を使った固定長 seq2seq モデル。

クエリは「出力位置 t」の位置エンコーディングに基づく。 これにより「t番目に欲しい情報はどこにあるか」をAttentionで学習する。 シンプルな「1ヘッド、cross-attention のみ」の Transformer 相当。

実体: griffith_logic.models.attention.attention_seq2seq.AttentionSeq2SeqConfig(クラス)

class AttentionSeq2SeqConfig(
seq_len: int = 4,
value_bits: int = 4,
encoder_sizes: list = (lambda: [32, 16])(),
value_encoder_sizes: list = (lambda: [32, 16])(),
decoder_sizes: list = (lambda: [64, 32])(),
n_inputs: int = 2,
parameterization: str = 'softmax',
connections: str = 'random',
grad_factor: float = 1.0,
selection: str = 'soft',
tau_attn: float = 1.0,
share_key_query: bool = False,
tau_out: float = 1.0,
tau_warp: float = 1.0,
gumbel: bool = True,
)

DLGNAttentionSeq2Seq のハイパーパラメータ。

実体: griffith_logic.models.attention.pointer_attention.DLGNPointerAttention(クラス)

class DLGNPointerAttention(config: PointerAttentionConfig, device: str = 'cpu')

Pointer Network 風の DLGN seq2seq モデル。

アーキテクチャ: Encoder (並列): values (B, N, value_bits) → value_encoder → v_enc (B, N, d_val) memory → key_encoder → k_enc (B, N, d_attn) content key

Decoder (t = 0..N-1, リカレント):
state_t = decoder_cell([state_{t-1}, prev_val])
query_t = query_producer(state_t)
scores_t = XNOR(query_t, k_enc) - mask_scale × used_mask
attn_t = softmax(scores_t / τ) (訓練) / one_hot(argmax) (推論)
selected_t = attn_t @ v_enc
logits_t = group_sum(output_decoder(selected_t))
teacher forcing: prev_val = v_enc[target_pointer[t]]
free running: prev_val = selected_t
used_mask += attn_t

このAPIを使っている例

実体: griffith_logic.models.attention.pointer_attention.PointerAttentionConfig(クラス)

class PointerAttentionConfig(
seq_len: int = 4,
value_bits: int = 4,
value_encoder_sizes: list = (lambda: [32, 16])(),
key_encoder_sizes: list = (lambda: [32, 16])(),
decoder_cell_sizes: list = (lambda: [64, 16])(),
query_producer_sizes: list = (lambda: [32, 16])(),
output_decoder_sizes: list = (lambda: [64, 32])(),
n_inputs: int = 2,
parameterization: str = 'softmax',
connections: str = 'random',
grad_factor: float = 1.0,
tau_attn: float = 1.0,
mask_scale: float = 10.0,
tau_out: float = 1.0,
tau_warp: float = 1.0,
gumbel: bool = True,
)

DLGNPointerAttention のハイパーパラメータ。

このAPIを使っている例

実体: griffith_logic.models.attention.attention_translator.DLGNAttentionTranslator(クラス)

class DLGNAttentionTranslator(
config: TranslatorConfig,
device: str = 'cpu',
dfa_targets: list[str] | None = None,
dfa_lr: float | None = None,
)

Bahdanau-style Attention seq2seq。

Encoder (並列) + Decoder (リカレント) + Cross-Attention。 RDDLGN (Bührer et al., 2025) と同じインターフェース: forward(src_tokens, tgt_tokens) -> (logits, emb_reg_loss)

実体: griffith_logic.models.attention.attention_translator.TranslatorConfig(クラス)

class TranslatorConfig(
vocab_size: int = 50,
d_emb: int = 32,
src_len: int = 16,
tgt_len: int = 16,
n_layer_sizes: list = (lambda: [64, 64])(),
key_encoder_sizes: list = (lambda: [32, 16])(),
l_layer_sizes: list = (lambda: [64, 64])(),
p_layer_sizes: list = (lambda: [96, 64])(),
query_producer_sizes: list = (lambda: [32, 16])(),
m_layer_sizes: list = (lambda: [128, 128, 300])(),
n_inputs: int = 2,
parameterization: str = 'softmax',
connections: str = 'random',
grad_factor: float = 1.0,
selection: str = 'soft',
wiring: str = 'fixed',
lm_tau: float = 0.001,
tau_attn: float = 1.0,
tau: float = 1.0,
init_mode: str = 'zero',
init_scale: float = 0.5,
shared_vocab: bool = True,
tau_warp: float = 1.0,
gumbel: bool = True,
)

DLGNAttentionTranslator のハイパーパラメータ。