<commit_before>from scipy.misc import imread
from wordcloud import WordCloud, STOPWORDS
import matplotlib.pyplot as plt
from functools import partial

tedmask = imread('./visualization/tedxbw.png', flatten=True)

def color_func(word=None, font_size=None, position=None,
                      orientation=None, font_path=None, random_state=None, dictionary=None):

    # val = max(0, min(255, font_size * 6 - 30))
    val = dictionary[word] * 42 - 50
    return "rgb(%d, %d, %d)" % (val, 0, 0)

def generate(words):
  """
  Words are supposed to be a list of tuples [(word, weight)]
  """

  words_dict = dict(words)
  words = " ".join(words_dict.keys())

  wordcloud = WordCloud(stopwords=STOPWORDS,
                        background_color='white',
                        width=400,
                        height=400,
                        scale=3,
                        mask=tedmask,
                        color_func=partial(color_func, dictionary=words_dict)).generate(words)

  img = wordcloud.to_image()
  pixdata = img.load()

  for y in xrange(img.size[1]):
      for x in xrange(img.size[0]):<commit_msg>KeyError corrected<commit_after>from scipy.misc import imread
from wordcloud import WordCloud, STOPWORDS
import matplotlib.pyplot as plt
from functools import partial

tedmask = imread('./visualization/tedxbw.png', flatten=True)

def color_func(word=None, font_size=None, position=None,
                      orientation=None, font_path=None, random_state=None, dictionary=None):

    # val = max(0, min(255, font_size * 6 - 30))
    try:
      val = dictionary[word] * 42 - 50
    except KeyError:
      val = 100
    return "rgb(%d, %d, %d)" % (val, 0, 0)

def generate(words):
  """
  Words are supposed to be a list of tuples [(word, weight)]
  """

  words = [str(word).lower() for words]
  words_dict = dict(words)
  words = " ".join(words_dict.keys())

  wordcloud = WordCloud(stopwords=STOPWORDS,
                        background_color='white',
                        width=400,
                        height=400,
                        scale=3,
                        mask=tedmask,
                        color_func=partial(color_func, dictionary=words_dict)).generate(words)

  img = wordcloud.to_image()
  pixdata = img.load()

  for y in xrange(img.size[1]):
      for x in xrange(img.size[0]):
{'fraction_non_alphanumeric': 0.11873124732104587, 'fraction_numerical': 0.020145735105015, 'mean_word_length': 2.4323529411764704, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2216301', 'n_tokens_mistral': 779, 'n_tokens_neox': 709, 'n_words': 175}