I am looking for a library that can overlay a text with a heatmap. I.e., add a highlight with gradient. I would simply define a value for each character: the value would define the highlight/heatmap intensity.


enter image description here

Ideally I should be able to easily call it from python.

  • Sounds good. I would also like ot see it handle words, not just characters. And, as well as user-defined, have an option to auto-heat map word frequency.
    – Mawg
    Commented Feb 9, 2017 at 9:21

1 Answer 1


You could define a new command LaTeX:

Example from https://arxiv.org/abs/1603.01547 :

enter image description here

\newcommand{\attvis}[2]{\definecolor{att}{rgb}{1, #2, #2} \colorbox{att}{#1}}


\begin{tabular}{| p{\dimexpr0.47\textwidth-2\tabcolsep-\arrayrulewidth\relax}|   }
%according to a entity21 lawmaker (education policy is super gay, obviously); %\attvis{entity25}{0.86},
%who an op-ed writer for entity28, entity29, claims is being used by entity30 to 
%"attract young girls" to her show (uh-huh); the entity36 princess movie "entity40"
%according to radio hosts in entity38 (that dress!); and now, according to a 
%potential 2016 entity34 presidential contender, \attvis{entity32}{0.81}, there's prison. yep, %prison. 
%stay away from crime, kids. turns ya gay. \attvis{entity32}{0.705}, who ,let me reiterate , 
%is a potential presidential candidate from a major entity54 party 
what was supposed to be a fantasy sports car ride at \attvis{@entity3}{0.97} turned deadly when a \attvis{@entity4}{0.47} crashed into a guardrail . the crash took place sunday at the @entity8 , which bills itself as a chance to drive your dream car on a racetrack . the \attvis{@entity4}{.99} 's passenger , 36 - year - old @entity14 of @entity15 , @entity16 , died at the scene , @entity13 said . the driver of the \attvis{@entity4}{0.98} , 24 - year - old @entity18 of @entity19 , @entity16 , lost control of the vehicle , the \attvis{@entity13}{0.82} said .

% \caption{See that the ....}
% \label{fig:attention_1}

officials say the driver , 24 - year - old @entity18 , lost control of a \_\_\_\_\_

\caption{Attention in an example with anonymized entities where our system selected the correct answer. Note that the attention is focused only on named entities.}
  • Is it easily callable form Python, as you requested (from yourself, apparently ;-)? Would I need any Latex knoweldge to use i?
    – Mawg
    Commented Feb 9, 2017 at 9:23
  • @Mawg as far as I know it isn't easily callable from Python :( just needs very limited Latex knoweldge. Commented Feb 9, 2017 at 18:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.