This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
def download_file_from_google_drive(id, destination): | |
def get_confirm_token(response): | |
for key, value in response.cookies.items(): | |
if key.startswith('download_warning'): | |
return value | |
return None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
%matplotlib inline | |
def parallel_shuffle(*arrays): | |
length = arrays[0].shape[0] | |
for arr in arrays: | |
assert arr.shape[0] == length | |
p = np.random.permutation(length) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# After Ubuntu 16.04, Systemd becomes the default. | |
# It is simpler than https://gist.github.com/Doowon/38910829898a6624ce4ed554f082c4dd | |
[Unit] | |
Description=Jupyter Notebook | |
[Service] | |
Type=simple | |
PIDFile=/run/jupyter.pid | |
ExecStart=/home/nokados/anaconda3/bin/jupyter-notebook --config=/home/nokados/.jupyter/jupyter_notebook_config.py --no-browser |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from IPython.core.display import display, HTML, clear_output | |
from ipywidgets import widgets, Layout | |
import math | |
PAGESIZE=10 | |
class Paginator: | |
def __init__(self, df, pagesize = PAGESIZE, start_page = 0): | |
self.df = df | |
self.pagesize = pagesize | |
self.page = start_page |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json, requests, time | |
import datetime | |
import pickle | |
from collections import Counter | |
from pyquery import PyQuery | |
from readability import Document | |
from lxml.etree import XMLSyntaxError, LxmlError | |
from readability.readability import Unparseable | |
from requests.adapters import MaxRetryError | |
from requests.exceptions import ConnectionError |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def bind(self, method): | |
def new_method(new_self, *args, **kwargs): | |
new_self.data = method(self.data, *args, **kwargs) | |
return new_self | |
setattr(self, method.__name__, types.MethodType(new_method, self)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# name: это строка которую транслитим | |
def transliterate(name): | |
""" | |
Автор: LarsKort | |
Дата: 16/07/2011; 1:05 GMT-4; | |
Не претендую на "хорошесть" словарика. В моем случае и такой пойдет, | |
вы всегда сможете добавить свои символы и даже слова. Только | |
это нужно делать в обоих списках, иначе будет ошибка. | |
""" | |
# Слоаврь с заменами |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def has(expr): | |
return lambda x: bool(re.search(expr, x, flags=re.IGNORECASE|re.MULTILINE|re.DOTALL)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%load_ext autoreload | |
%autoreload 2 | |
import pandas as pd | |
from tqdm import tqdm_notebook, tqdm_pandas, tnrange | |
import time | |
import numpy as np | |
from IPython.display import clear_output | |
import pickle as pkl | |
import os |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def word2vec_embedding_layer(embeddings_path='data/weights.npz', max_review_length=150): | |
weights = load_weights(embeddings_path) | |
layer = Embedding(input_dim=weights.shape[0], | |
output_dim=weights.shape[1], | |
input_length=max_review_length, | |
weights=[weights]) | |
return layer | |
# How to make 'data/weights.npz'? What is load_weights()? | |
# See https://gist.github.com/nokados/d5cfec00bc194822f89dff556ff62b29 |
NewerOlder