Skip to content

Instantly share code, notes, and snippets.

View rtkclouds's full-sized avatar

caio rtkclouds

View GitHub Profile
@rtkclouds
rtkclouds / HexastoreAttention.py
Created August 19, 2024 18:21
This code defines a custom attention mechanism and transformer layer based on the hexastore concept, which is typically used for efficiently querying triples in a knowledge graph (Subject, Predicate, Object).
import torch
import torch.nn as nn
import torch.nn.functional as F
class HexastoreAttention(nn.Module):
def __init__(self, d_model, num_heads):
super().__init__()
self.d_model = d_model
self.num_heads = num_heads
self.head_dim = d_model // num_heads