Skip to content

Instantly share code, notes, and snippets.

View nilansaha's full-sized avatar

Nilan Saha nilansaha

View GitHub Profile
@nilansaha
nilansaha / ElasticsearchHelpers.py
Created May 29, 2021 21:35 — forked from eranhirs/ElasticsearchHelpers.py
Sanitize a query string for Elasticsearch / Lucene . Based on a discussion on Stack Overflow: http://stackoverflow.com/questions/16205341/symbols-in-query-string-for-elasticsearch
import re
class ElasticsearchHelpers(object):
"""
Sanitize a query string for Elasticsearch / Lucene.
Based on:
http://stackoverflow.com/questions/16205341/symbols-in-query-string-for-elasticsearch
https://gist.github.com/bcoe/6505434
@nilansaha
nilansaha / pytorch_lightning_boilerplate.py
Created November 29, 2020 07:14
PyTorch Lightning Boilerplate
import torch
import random
import torch.nn as nn
from torch.optim import Adam
import pytorch_lightning as pl
from torch.utils.data import Dataset, DataLoader
class SampleDataset(Dataset):
def __init__(self, size, coef_1, coef_2):
self.size = size
@nilansaha
nilansaha / pytorch_boilerplate.py
Created November 22, 2020 22:14
Simple PyTorch Boilerplate
import torch
import torch.nn as nn
from torch.optim import Adam
from torch.utils.data import Dataset, DataLoader
class SampleDataset(Dataset):
def __init__(self, size, coef_1, coef_2):
self.size = size
self.coef_1 = coef_1
self.coef_2 = coef_2
out = parallel(delayed(_fit_and_score)(clone(base_estimator),
X, y,
train=train, test=test,
parameters=parameters,
**fit_and_score_kwargs)
for parameters, (train, test)
in product(candidate_params,
cv.split(X, y, groups)))