Skip to content

Instantly share code, notes, and snippets.

@avostryakov
avostryakov / gist:7c82247cd9fd8d16641c3ea8484b9f6f
Created November 30, 2016 13:59
Memory Network implementation
import cPickle
import numpy as np
import tensorflow as tf
from data_utils_ubuntu import CustomRunner
def position_encoding(sentence_size, embedding_size):
"""
Position Encoding described in section 4.1 [1]
@avostryakov
avostryakov / batch_normalized_lstm_layer.py
Last active May 12, 2017 09:10
Implementation of Recurrent Batch Normalization article in Lasagne
from lasagne import nonlinearities, init
from lasagne.layers.normalization import BatchNormLayer
from lasagne.layers.recurrent import Gate, Layer, MergeLayer, LSTMLayer
from lasagne.utils import unroll_scan
import numpy as np
import theano
import theano.tensor as T
import os
from django.core.files.storage import FileSystemStorage
from django.db.models import signals
class MyFileSystemStorage(FileSystemStorage):
def rename(self, src, dest):
return os.rename(self.path(src), self.path(dest))
class MyFileField(models.FileField):
sizes = new Array({{ product_sizes|safe }});
function filterSizeSelectField()
{
product_type = $("#id_product_type").val();
fields = $("select[id*='-size']").serializeArray();
size_options = '<option value="">---------</option>';
$.each(sizes,
function(i, size)
{
$(document).ready(function() {
$("select[id*='id_products-']").css("width", "145px");
function getSizeSelectField()
{
product_type = $("#id_product_type").val();
fields = $("select[id*='-size']").serializeArray();
$("select[id*='-size']").load('{% url shop.views.getSelectField %}' + '?type=size&object_id=' + product_type,
function() {
$.each(fields, function(i, field) {
# Самое элегантное решение (доступно с версии Python 2.6)
class Requisite(models.Model):
requisite = models.CharField(max_length=100, verbose_name=u'реквизиты')
@property
def requisite_dict(self):
return json.loads(self.requisite)
@requisite_dict.setter
def requisite_dict(self, value=None):
self.requisite = json.dumps(value)
class MultiTextInputWidget(forms.TextInput):
"""
A widget that is composed of multiple TextInput widgets.
Its render() display multiple TextInput widgets.
The ``value`` argument supposes to be a dictionary in json format or string
This widget can be used together with MultiTextInputField.
"""
def __init__(self, attrs=None):