Attviz - Atenção de si mesmo simplesOs modelos de linguagem neural são o estado da arte para a maioria das tarefas relacionadas à linguagem. Uma das maneiras de explorar seu comportamento, no entanto, é via visualização . Apresentamos o AttViz, um servidor da web simples adequado para a exploração da atenção no nível da instância, online. O servidor está ao vivo na ATTVIZ.
Pré -impressão atual:
@inproceedings{skrlj-etal-2021-exploring,
title = "Exploring Neural Language Models via Analysis of Local and Global Self-Attention Spaces",
author = "{v{S}}krlj, Bla{v{z}} and
Sheehan, Shane and
Er{v{z}}en, Nika and
Robnik-{v{S}}ikonja, Marko and
Luz, Saturnino and
Pollak, Senja",
booktitle = "Proceedings of the EACL Hackashop on News Media Content Analysis and Automated Report Generation",
month = apr,
year = "2021",
address = "Online",
publisher = "Association for Computational Linguistics",
url = "https://www.aclweb.org/anthology/2021.hackashop-1.11",
pages = "76--83",
abstract = "Large pretrained language models using the transformer neural network architecture are becoming a dominant methodology for many natural language processing tasks, such as question answering, text classification, word sense disambiguation, text completion and machine translation. Commonly comprising hundreds of millions of parameters, these models offer state-of-the-art performance, but at the expense of interpretability. The attention mechanism is the main component of transformer networks. We present AttViz, a method for exploration of self-attention in transformer networks, which can help in explanation and debugging of the trained models by showing associations between text tokens in an input sequence. We show that existing deep learning pipelines can be explored with AttViz, which offers novel visualizations of the attention heads and their aggregations. We implemented the proposed methods in an online toolkit and an offline library. Using examples from news analysis, we demonstrate how AttViz can be used to inspect and potentially better understand what a model has learned.",
}

Para seguir o exemplo abaixo, instale os requisitos do requisitos.txt, fazendo por exemplo,
pip install -r requirements.txt
Attviz é totalmente compatível com a biblioteca Pytorch_transformers!
Attviz aceita espaço de atenção, codificado na forma de objetos JSON, que podem ser construídos usando os scripts fornecidos. Um exemplo de ponta a ponta, que primeiro treina um modelo baseado em Bert em uma tarefa de classificação multiclasse, e a próxima o usa para obter dados de atenção é fornecida a seguir.
## first build a model, then generate server input.
from generate_server_input import *
from build_bert_classifier import *
## STEP 1: A vanilla BERT-base model.
train_seq , dev_seq , train_tar , dev_tar = read_dataset ( "data" , "hatespeech" ) ## hatespeech or bbc are in the repo!
bert_model = get_bert_base ( train_seq , dev_seq , train_tar , dev_tar , weights_dir = "transformer_weights" , cuda = False ) ## for cuda, you might need the apex library
## STEP 2: Predict, attend to and generate final json.
weights = "transformer_weights" ## Any HuggingFace model dump can be used!
test_data = "data/hatespeech/test.tsv"
delimiter = " t "
text_field = "text_a"
label_field = "label"
number_of_attention_heads = 12
label_names = [ "no" , "some" , "very" , "disturbing" ] #['business','entertainment','politics','sport']
segment_delimiter = "|||"
## Obtain the attention information and create the output object.
## Subsample = True takes each 10th sample, useful for prototyping.
model = BertForSequenceClassification . from_pretrained ( weights ,
num_labels = len ( label_names ),
output_hidden_states = True ,
output_attentions = True )
tokenizer = BertTokenizer . from_pretrained ( "bert-base-uncased" )
out_obj = get_json_from_weights ( model ,
tokenizer ,
test_data = test_data ,
delimiter = delimiter ,
text_field = text_field ,
label_field = label_field ,
number_of_attention_heads = number_of_attention_heads ,
label_names = label_names ,
segment_delimiter = segment_delimiter ,
subsample = True )
## Output the extracted information to AttViz-suitable json.
with open ( 'generated_json_inputs/example_hatespeech_explanations.json' , 'w' ) as fp :
json . dump ( out_obj , fp )
## That's it! Simply upload this json to the attvis.ijs.si and explore!O servidor também vem com alguns exemplos pré-carregados (gerados_json_inputs), verifique-os também (envie para servidor e explorar).
Se, devido a preocupações com a privacidade, desejar se hospedar localmente, siga as instruções a seguir. Instale o Node.js. Então,
npm install express
Em seguida, é tão simples quanto:
node embViz.js
Vá para o navegador e digite "Localhost: 3310". Altere as portas à vontade.
A ferramenta está sob desenvolvimento ativo, as mudanças são pelo menos até certo ponto esperadas. Usar por risco.
Por favor, abra uma solicitação de tração, um problema ou escreva para nós se você tiver alguns casos de uso interessantes dessa metodologia!
O código foi desenvolvido com contribuições iguais de Nika eržen e blaž Škrlj