Skip to content

Instantly share code, notes, and snippets.

View Cheneng's full-sized avatar
🎯
Focusing

ColeChen Cheneng

🎯
Focusing
  • China
View GitHub Profile
@Cheneng
Cheneng / pp_tutorial.py
Created March 13, 2018 02:29
The tutorial of the pack_padded_sequence and pad_packed_sequence in PyTorch.
import torch
import torch.nn as nn
import torch.autograd as autograd
from torch.nn.utils.rnn import pad_packed_sequence, pack_padded_sequence
# Create some fake sorted data with 0 pad
data = autograd.Variable(torch.LongTensor([[3, 4, 5, 1, 9],
[3, 1, 3, 4, 0],
[5, 3, 6, 0, 0]]))
@Cheneng
Cheneng / visdom_multiple_line.py
Created June 21, 2018 02:13
draw multiple lines in visdom
def draw_line(vis, step, lines, names):
# draw multiple lines in one panel.
"""
:param vis: the object of the visdom.Visdom
:param step: the step of the line
:param lines: the lines tuple, (line1, line2, ...)
:param names: the names tuple, (name1, name2, ...)
:return: None
"""
@Cheneng
Cheneng / weight_init.py
Created July 16, 2019 06:41 — forked from jeasinema/weight_init.py
A simple script for parameter initialization for PyTorch
#!/usr/bin/env python
# -*- coding:UTF-8 -*-
import torch
import torch.nn as nn
import torch.nn.init as init
def weight_init(m):
'''