Skip to content

Instantly share code, notes, and snippets.

View sailist's full-sized avatar
🏠
Working from home

Haozhe sailist

🏠
Working from home
  • Sophgo
View GitHub Profile
@strubell
strubell / plot_attn.py
Last active March 17, 2019 02:11
plot attention
from __future__ import division
from __future__ import print_function
import numpy as np
import matplotlib.pyplot as plt
import os
import re
import string
def sorted_alphanum(l):
@mbollmann
mbollmann / attention_lstm.py
Last active June 26, 2023 10:08
My attempt at creating an LSTM with attention in Keras
class AttentionLSTM(LSTM):
"""LSTM with attention mechanism
This is an LSTM incorporating an attention mechanism into its hidden states.
Currently, the context vector calculated from the attended vector is fed
into the model's internal states, closely following the model by Xu et al.
(2016, Sec. 3.1.2), using a soft attention model following
Bahdanau et al. (2014).
The layer expects two inputs instead of the usual one:
@upsuper
upsuper / tree.md
Created April 28, 2012 10:38 — forked from hrldcpr/tree.md
一行 Python 实现树

一行 Python 实现树

使用 Python 内置的 defaultdict,我们可以很容易的定义一个树形数据结构:

def tree(): return defaultdict(tree)

就是这样!