Skip to content

Instantly share code, notes, and snippets.

View georgepar's full-sized avatar

Giorgos Paraskevopoulos georgepar

  • Athens, Greece
View GitHub Profile
import numpy as np
import gzip
import copy
from sklearn.preprocessing import LabelEncoder
from torch.utils.data import Dataset
from torch.utils.data import SubsetRandomSampler, DataLoader
# Combine similar classes and remove underrepresented classes
class_mapping = {
from torch.utils.data import Dataset
from sklearn.preprocessing import LabelEncoder
class LabelTransformer(LabelEncoder):
def inverse(self, y):
try:
return super(LabelTransformer, self).inverse_transform(y)
except:
return super(LabelTransformer, self).inverse_transform([y])
@georgepar
georgepar / read_imdb.py
Last active October 31, 2018 13:41
Read and preprocess IMDB sentiment dataset
import os
data_dir = './aclImdb/'
train_dir = os.path.join(data_dir, 'train')
test_dir = os.path.join(data_dir, 'test')
pos_train_dir = os.path.join(train_dir, 'pos')
neg_train_dir = os.path.join(train_dir, 'neg')
pos_test_dir = os.path.join(test_dir, 'pos')
neg_test_dir = os.path.join(test_dir, 'neg')
@georgepar
georgepar / to_embeddings.py
Last active October 31, 2018 11:44
word2vec
# Initialize word2vec. Context is taken as the 2 previous and 2 next words
model = Word2Vec(sentences, window=5, size=100, workers=4)
model.train(sentences, total_examples=len(sentences), epochs=1000)
# get ordered vocabulary list
voc = model.wv.index2word
# get vector size
dim = model.vector_size
@georgepar
georgepar / compile_fst.sh
Last active September 3, 2020 08:37
fst_creation_example
#!/usr/bin/env bash
python create_fst.py | fstcompile --isymbols=chars.syms --osymbols=chars.syms - rosebud.bin.fst
@georgepar
georgepar / predict.sh
Last active September 11, 2020 13:00
predict_spell_checker
#!/usr/bin/env bash
SPELL_CHECKER_COMPILED=${1}
python test.py |
fstcompile --isymbols=letter_syms.txt --osymbols=letter_syms.txt |
fstcompose - ${SPELL_CHECKER_COMPILED} |
fstshortestpath |
fstrmepsilon |
fsttopsort |
from sklearn.base import BaseEstimator, ClassifierMixin
class EuclideanClassifier(BaseEstimator, ClassifierMixin):
"""Classify samples based on the distance from the mean feature value"""
def __init__(self):
self.X_mean_ = None
def fit(self, X, y):
@georgepar
georgepar / ipynb2pdf.py
Created October 29, 2017 19:43
A script to convert an ipython notebook to pdf with support for greek language
#!/usr/bin/env python3
"""
Credits https://github.com/ivanychev/learning/blob/master/Python/ipynb2pdf/ipynb2pdf.py
Current version of Jupyter doesn't support pdf exporting when it comes to
greek language in the document. To fix this, current script has born.
It requires nbconvert as long as jupyter to be installed.
Author: Sergey Ivanychev
@georgepar
georgepar / Makefile
Created September 30, 2016 12:32
Fuel tacker integration
##############################################################################
# Copyright (c) 2015 Ericsson AB and others.
# geopar@intracom-telecom.com
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
TOP := $(shell pwd)
@georgepar
georgepar / bgpvpn_command_examples
Last active September 29, 2016 10:21
Instructions and code to reproduce the router association tenant separation testcase
# Create a new bgpvpn
neutron bgpvpn-create --type l3 --name mybgpvpn -- --import-targets 55:55 88:88 --export-targets 55:55 88:88 --route-distinguishers 55:55
# Associate network to bgpvpn
neutron bgpvpn-net-assoc-create --network my_net mybgpvpn
# Associate router to bgpvpn
neutron bgpvpn-router-assoc-create --router my_router mybgpvpn2
# Update bgpvpn route targets