Skip to content

Instantly share code, notes, and snippets.

View cjmcmurtrie's full-sized avatar
🎯
Focusing

Conan cjmcmurtrie

🎯
Focusing
View GitHub Profile
@cjmcmurtrie
cjmcmurtrie / 1dcnn.py
Last active July 14, 2024 05:53
1D convolutional text classifier in Pytorch.
import torch
import torch.nn as nn
import torch.nn.functional as fnn
import torch.optim as onn
class Transpose(nn.Module):
def __init__(self):
super(Transpose, self).__init__()
def distance_permutation(array, d):
"""
This function returns a staggered permutation of a sequence an the corresponding
permuted indices, such that no item is allowed to move more than d steps from
it's original position.
"""
rng = range(len(array))
for i in rng:
swap = randint(0, d)
if i - swap < rng[i] < i + swap: