Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

{
"embeddings": [
{
"tensorName": "My tensor",
"tensorShape": [
52420,
200
],
"tensorPath": "https://entilzha-us-west-2.s3-us-west-2.amazonaws.com/shifeng/proto_tensors.tsv",
"metadataPath": "https://entilzha-us-west-2.s3-us-west-2.amazonaws.com/shifeng/proto_metadata.tsv",
import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
color_name = 'color{}'
define_color = '\definecolor{{{}}}{{HTML}}{{{}}}'
box = '\\mybox{{{}}}{{\strut{{{}}}}}'
cmap = plt.cm.get_cmap('RdBu')
@ihsgnef
ihsgnef / colorize_text.py
Last active January 17, 2024 02:01
Visualize attention over text with background colors
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
def colorize(words, color_array):
# words is a list of words
# color_array is an array of numbers between 0 and 1 of length equal to words
cmap = matplotlib.cm.get_cmap('RdBu')
template = '<span class="barcode"; style="color: black; background-color: {}">{}</span>'
colored_string = ''
import random
import numpy as np
from collections import defaultdict
import torch
from torch.autograd import Variable
from vocab import PAD_ID
class Iterator(object):