Skip to content

Instantly share code, notes, and snippets.

View LukasHaas's full-sized avatar
🤯

Lukas Haas LukasHaas

🤯
View GitHub Profile
@LukasHaas
LukasHaas / LightGCN.py
Last active December 10, 2021 07:41
Modified LightGCN Model
class LightGCN(torch.nn.Module):
def __init__(self, train_data, num_layers, emb_size=16, initialize_with_words=False):
super(LightGCN, self).__init__()
self.convs = nn.ModuleList()
assert (num_layers >= 1), 'Number of layers is not >=1'
for l in range(num_layers):
self.convs.append(LightGCNConv(input_dim, input_dim))
# Initialize using custom embeddings if provided
num_nodes = train_data.node_label_index.size()[0]
@LukasHaas
LukasHaas / LightGCNConv.py
Last active December 10, 2021 07:44
Modified LightGCN Convolutional Layer
class LightGCNConv(MessagePassing):
def __init__(self, aggregation='mean', **kwargs):
super(LightGCNConv, self).__init__(**kwargs)
self.aggregation = aggregation
def forward(self, x, edge_index, size = None):
out = self.propagate(edge_index, x=(x, x))
return out
def message(self, x_j):
@LukasHaas
LukasHaas / QuantileRegressor.py
Last active August 24, 2020 10:58
A scikit learn wrapper class to evaluate regression problems at difference levels of confidence (or quantiles).
import pandas as pd
import numpy as np
from sklearn.base import BaseEstimator, clone
from sklearn.metrics import r2_score
from decimal import Decimal
from typing import Tuple, Union, Dict
class QuantileRegressor(BaseEstimator):
@LukasHaas
LukasHaas / RuleAugmentedEstimator.py
Last active June 24, 2022 17:54
Augment Sklearn Models with Rule-Based Logic
import numpy as np
import pandas as pd
import sklearn
from typing import Dict, Tuple
from sklearn.base import BaseEstimator
class RuleAugmentedEstimator(BaseEstimator):
"""Augments sklearn estimators with rule-based logic.