Uma introdução · por Gabriel Lucas BarbosaAn introduction · by Gabriel Lucas Barbosa

Inteligência artificial que se explica.Artificial intelligence that explains itself.

Uma introdução sem jargão ao campo que pesquiso no grupo CBio da UFPR. A jargon-free introduction to the field I research at UFPR's CBio group.

01 · O PROBLEMA01 · THE PROBLEM

A caixa-pretaThe black box

Um modelo de aprendizado de máquina hoje consegue acertar quase sempre e, mesmo assim, não saber te explicar por quê. São milhões de números lá dentro, e nem quem treinou o modelo consegue apontar o que fez a resposta ser essa e não outra.

E acertar sem saber o porquê é arriscado: fica fácil confiar demais numa coisa que ninguém consegue explicar. IA Explicável (ou XAI, de Explainable AI) é o esforço de abrir essa caixa e responder três perguntas simples sobre cada resposta: o que, na entrada, puxou pra esse lado? O quanto? Em que direção?

A machine learning model today can be right almost every time and still not be able to tell you why. There are millions of numbers inside it, and not even the person who trained it can point to what made the answer this and not that.

And being right without knowing why is risky: it gets easy to trust too much something no one can explain. Explainable AI (XAI) is the effort to open that box and answer three simple questions about each answer: what, in the input, pulled it this way? How much? In which direction?

Pense num banco que nega um empréstimo usando um modelo. "O modelo disse não" não é resposta aceitável, nem para o cliente, nem para o regulador. Com XAI, a resposta vira: "a renda pesou contra, o histórico pesou a favor, e o primeiro pesou mais". A decisão pode continuar a mesma; a diferença é que agora ela pode ser questionada. Think of a bank denying a loan with a model. "The model said no" is not an acceptable answer, neither for the customer nor for the regulator. With XAI, the answer becomes: "income weighed against, credit history weighed in favor, and the first weighed more". The decision may stay the same; the difference is that now it can be challenged.

É disso que tratam as demonstrações na minha página inicial: o modo explicabilidade esconde o meu curso e tenta adivinhá-lo pelas pistas do texto, repartindo contribuições do jeito que o SHAP faz, e o "desenhe um dígito" usa Grad-CAM de verdade para colorir onde a rede olhou. Os dois métodos aparecem logo abaixo. That is what the demos on my homepage are about: the explainability mode hides my degree and tries to guess it from the clues in the text, splitting contributions the way SHAP does, and the "draw a digit" one uses real Grad-CAM to color where the network looked. Both methods appear right below.

02 · MÉTODOS02 · METHODS

Os métodos que estudoThe methods I study

SHAP

Empresta uma ideia da teoria dos jogos: imagine que cada informação que entrou no modelo é um jogador, e a previsão é o prêmio que eles ganharam juntos. O SHAP calcula quanto cada jogador contribuiu de verdade, como se dividisse o prêmio de forma justa. É o método com a base matemática mais bem-amarrada da área. It borrows an idea from game theory: picture each piece of information that went into the model as a player, and the prediction as the prize they won together. SHAP works out how much each player really contributed, as if splitting the prize fairly. It has the most tightly-argued mathematical basis in the field.

Lundberg & Lee · 2017 · arXiv:1705.07874

Grad-CAM

Esse é para redes que enxergam imagens. Ele pega os sinais das últimas camadas da rede e pinta um mapa de calor por cima da foto, mostrando onde ela estava olhando na hora de decidir. É o método por trás daquelas imagens com manchas quentes em cima do gato, e é ele que roda ao vivo na demonstração da minha página inicial. This one is for networks that see images. It takes the signals from the network's last layers and paints a heatmap over the photo, showing where it was looking when it decided. It is the method behind those pictures with warm blobs over the cat, and it is the one running live in the demo on my homepage.

Selvaraju et al. · 2017 · arXiv:1610.02391 · veja ao vivo na página inicialsee it live on my homepage

Integrated Gradients

Vai de uma entrada "em branco" até a entrada de verdade em pequenos passos, somando o quanto cada pedacinho empurra a resposta ao longo do caminho. Ele segue algumas regras de bom senso que métodos mais apressados acabam quebrando, e por isso é bem visto quando se quer rigor. It goes from a "blank" input to the real input in small steps, adding up how much each little piece pushes the answer along the way. It follows a few common-sense rules that hastier methods end up breaking, which is why it is trusted when you want rigor.

Sundararajan, Taly & Yan · 2017 · arXiv:1703.01365

Esses são os que eu estudo mais de perto, mas a área é grande: existem vários outros métodos, cada um com o seu jeito de espiar dentro do modelo. These are the ones I look at most closely, but the field is big: there are several other methods, each with its own way of peeking inside the model.

Três painéis: a foto do Max, o Grad-CAM com um mapa de calor sobre o focinho e os olhos dele, e os Gradientes Integrados marcando os pixels importantes; abaixo, o top-5 de raças com Border Collie em primeiro / Three panels: a photo of Max, Grad-CAM with a heatmap over his snout and eyes, and Integrated Gradients marking the important pixels; below, the top-5 breeds with Border Collie first
Dá pra ver os dois trabalhando juntos numa foto de verdade. Aqui um modelo tentou adivinhar a raça do meu cachorro, o Max. No meio, o Grad-CAM esquentou em cima do focinho e dos olhos dele, mostrando onde a rede olhou pra decidir; à direita, os Gradientes Integrados marcam pixel a pixel o que puxou a resposta, contornando o formato do cachorro. Ele chutou Border Collie e depois Collie, que é a família certa, e o mais tranquilizador é ver que a rede olhou pro cachorro, não pra grama nem pro brinquedo laranja. You can see both of them working together on a real photo. Here a model tried to guess my dog Max's breed. In the middle, Grad-CAM went warm over his snout and eyes, showing where the network looked to decide; on the right, Integrated Gradients mark, pixel by pixel, what pulled the answer, tracing the dog's shape. It guessed Border Collie and then Collie, which is the right family, and the reassuring part is seeing that the network looked at the dog, not at the grass or the orange toy.
03 · MINHA PESQUISA03 · MY RESEARCH

O que eu faço com issoWhat I do with this

Na iniciação científica no grupo CBio, do Departamento de Informática da UFPR, estudo esses métodos com bolsa do CNPq e orientação da professora Aurora Pozo. A ideia é deixar modelos de aprendizado de máquina mais transparentes e mais fáceis de entender.

Conforme a pesquisa anda, esta página vai ganhando notas, experimentos e o que eu for descobrindo pelo caminho. Por enquanto, ela é o ponto de partida que eu queria ter achado quando comecei.

In my undergraduate research at the CBio group, at UFPR's Department of Informatics, I study these methods on a CNPq scholarship, advised by professor Aurora Pozo. The idea is to make machine learning models more transparent and easier to understand.

As the research moves along, this page grows with notes, experiments and whatever I learn on the way. For now, it is the starting point I wish I had found when I began.

04 · A MATEMÁTICA04 · THE MATH

A descida do gradienteGradient descent

Dois dos métodos ali de cima têm "gradiente" no nome, e não é à toa. Pra entender, pense na curva aqui embaixo como um gráfico do erro do modelo: quanto mais alto o ponto, mais ele está errando. Treinar é procurar o ponto mais fundo desse gráfico, lá onde o erro é o menor possível. É por isso que a gente quer descer.

O gradiente é só uma palavra chique pra inclinação: em cada ponto, ele diz pra que lado o erro sobe mais rápido. Se eu quero descer, é só andar no sentido contrário, um passinho de cada vez, e é exatamente assim que quase toda rede neural aprende. Essa mesma inclinação é a que o Grad-CAM e o Integrated Gradients reaproveitam na hora de explicar uma decisão.

Dá pra sentir na mão. Clique num ponto da curva e veja a bolinha rolar ladeira abaixo, atrás do fundo: a cada passo ela anda um pouquinho (o tal do η) no sentido contrário à inclinação.

Two of the methods up there have "gradient" in the name, and that is no accident. To picture it, think of the curve below as a graph of the model's error: the higher the point, the more it is getting wrong. Training is looking for the lowest point on that graph, where the error is as small as possible. That is why we want to go down.

The gradient is just a fancy word for slope: at each point, it tells you which way the error climbs fastest. If I want to go down, I just walk the other way, one small step at a time, and that is exactly how almost every neural network learns. That same slope is the one Grad-CAM and Integrated Gradients reuse when explaining a decision.

You can feel it by hand. Click a spot on the curve and watch the ball roll downhill, after the bottom: at each step it moves a little (that is the η) opposite to the slope.

xt+1 = xt − η · f ′(xt)

Repare que a bolinha para no primeiro buraco que encontra, que nem sempre é o mais fundo. Esse é o famoso mínimo local, e aprender a conviver com ele faz parte do jogo de treinar modelos. Com η grande demais, ela pula o buraco todo; pequeno demais, demora uma eternidade. Desenhe a sua própria curva e veja o que acontece. Notice the ball stops at the first dip it finds, which is not always the deepest. That is the famous local minimum, and learning to live with it is part of the game of training models. With η too large, it leaps right over the dip; too small, it takes forever. Draw your own curve and see what happens.

05 · POR ONDE COMEÇAR05 · WHERE TO START

Por onde começarWhere to start

Sendo honesto, não é que eu já tenha lido tudo isso de capa a capa. É a trilha que a área inteira aponta como ponto de partida, e é por ela que eu vou, na ordem que faz sentido pra mim: To be honest, it is not that I have read all of this cover to cover. It is the path the whole field points to as a starting point, and the one I am going to follow, in the order that makes sense to me:

  • Interpretable Machine Learning Christoph Molnar · livro aberto e de graça; o melhor lugar pra ter a visão geral antes de mergulharChristoph Molnar · free open book; the best place to get the big picture before diving in
  • Grad-CAM o artigo daquelas manchas quentes sobre a imagem; é o método que roda ao vivo na minha página inicialthe paper behind those warm blobs over the image; it is the method running live on my homepage
  • A Unified Approach to Interpreting Model Predictions o artigo do SHAP; junta vários métodos antigos numa base teórica sóthe SHAP paper; it ties several older methods together under one theory
  • Axiomatic Attribution for Deep Networks o artigo do Integrated Gradients; o mais matemático da lista, pra quem quiser rigorthe Integrated Gradients paper; the most mathematical of the list, for whoever wants rigor
  • Captum quando você quiser sair da teoria e testar esses métodos em código de verdadefor when you want to leave the theory and actually try these methods in code