Skip to content

Instantly share code, notes, and snippets.

View madrugado's full-sized avatar

Valentin Malykh madrugado

View GitHub Profile
import tensorflow as tf
from tensorflow.contrib.rnn import RNNCell
from tensorflow.contrib.rnn import LSTMStateTuple
from tensorflow.python.ops import variable_scope
from tensorflow.python.ops import array_ops
from tensorflow.python.ops.rnn_cell_impl import _linear
from tensorflow.python.ops import math_ops
from tensorflow.python.ops import nn_ops
from random import random, choice
def noise_generator(string, noise_level, chars):
noised = ""
for c in string:
if random() > noise_level:
noised += c
if random() < noise_level:
noised += choice(chars)
return noised
@madrugado
madrugado / bleu.py
Created January 27, 2018 19:54
BLEU version we're using for Babel
# Copyright 2017 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
#!/bin/sh
# this sample script translates a test set, including
# preprocessing (tokenization, truecasing, and subword segmentation),
# and postprocessing (merging subword units, detruecasing, detokenization).
# instructions: set paths to mosesdecoder, subword_nmt, and nematus,
# then run "./translate.sh < input_file > output_file"
# suffix of source language
def sample_gumbel(shape, eps=1e-20):
"""Sample from Gumbel(0, 1)"""
U = tf.random_uniform(shape,minval=0,maxval=1)
return -tf.log(-tf.log(U + eps) + eps)
def gumbel_softmax_sample(logits, temperature):
""" Draw a sample from the Gumbel-Softmax distribution"""
y = logits + sample_gumbel(tf.shape(logits))
return tf.nn.softmax( y / temperature)
@madrugado
madrugado / image_captioning.ipynb
Last active May 16, 2017 18:23
Image Captioning Homework
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@madrugado
madrugado / Keras_usage_example.ipynb
Last active December 13, 2022 16:51
Keras usage example, simple text classification
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import random
import matplotlib.pyplot as plt
from IPython import display
"""
IPython Display rc0
Try:
dsp = IDisplay()
@madrugado
madrugado / longest_chain_of_substrings.cpp
Created October 22, 2015 21:18
The problem solved by this code is: we need to find a longest chain of substrings, where substring produced from string by dropping of one letter. The input reading is omitted.
#include <iostream>
#import <vector>
#import <string>
#import <set>
#import <algorithm>
#import <map>
using namespace std;
int main() {
@madrugado
madrugado / overlap.py
Last active October 22, 2015 21:21
We have dataset of requests and vacancies titles and descriptions. We need to find similar queries and jobs.
#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'madrugado'
import sys
import pymystem3
import itertools
from collections import Counter
import math