简体   繁体   English

如何使用非文本分类注意机制为RNN建模?

[英]How to model RNN with Attention Mechanism for Non-Text Classification?

Recurrent Neural Networks (RNN) With Attention Mechanism is generally used for Machine Translation and Natural Language Processing. 具有注意力机制的递归神经网络(RNN)通常用于机器翻译和自然语言处理。 In Python, implementation of RNN With Attention Mechanism is abundant in Machine Translation (For Eg. https://talbaumel.github.io/blog/attention/ , however what I would like to do is to use RNN With Attention Mechanism on a temporal data file (not any textual/sentence based data). 在Python中,机器翻译中RNN With Attention机制的实现非常丰富(例如, https://talbaumel.github.io/blog/attention/ ,但是我想做的是在时间上使用RNN With Attention机制数据文件(不是任何基于文本/句子的数据)。

I have a CSV file with of dimensions 21392 x 1972, which I have converted to a Dataframe using Pandas. 我有一个尺寸为21392 x 1972的CSV文件,已使用熊猫将其转换为数据框。 The first column is of Datetime Format and last column consists of target classes like "Class1", "Class2", "Class3" etc. which I would like to identify. 第一列是“日期时间格式”,最后一列包含目标类,例如“ Class1”,“ Class2”,“ Class3”等,我想对其进行标识。 So in total, there are 21392 rows (instances of data in 10 minutes time-steps) and 1971 features. 因此,总共有21392行(10分钟时间步长的数据实例)和1971个功能。 The last (1972th column) is the label column, with 14 different classes in total. 最后一列(第1972列)是标签列,共有14个不同的类。

I have looked into available implementation documentation on Keras ( https://medium.com/datalogue/attention-in-keras-1892773a4f22 ) as well as on Tensorflow ( Visualizing attention activation in Tensorflow ), but none of them seem to be doing what I want to accomplish. 我已经研究了Keras( https://medium.com/datalogue/attention-in-keras-1892773a4f22 )和Tensorflow(在Tensorflow中可视化注意力激活 )上的可用实现文档,但是它们似乎都没有做什么我想完成。 I understand that this is an unusual approach, but would want to try this and use the attention mechanism because many of my features are presumably redundant in the data. 我知道这是一种不寻常的方法,但是我想尝试一下并使用注意力机制,因为我的许多功能可能在数据中都是多余的。

import pandas as pd
mydataset = pd.read_csv('final_merged_data.csv')

It is predominant from existing literature that an Attention Mechanism works quite well when coupled into the RNN. 从现有文献中可以看出,当将注意力机制与RNN耦合时,它的工作原理非常好。 I am unable to locate any such implementation of RNN with Attention Mechanism, which can also provide a visualisation as well. 我无法通过Attention机制找到RNN的任何此类实现,该机制也可以提供可视化。 I am also unable to understand how I can convert my data into a sequence (or a list of lists) so that I can use it with One Hot Encoding afterwards for using RNN with Attention. 我也无法理解如何将数据转换为序列(或列表列表),以便以后可以将其与One Hot Encoding一起使用,以将RNN与Attention一起使用。 I am new to using Python as well as Keras/Tensorflow, and am quite confused on the procedure to convert my data/typecast it to a form which will be able to mimic the sequence classification problem. 我对使用Python以及Keras / Tensorflow并不陌生,并且对将数据转换/转换成可以模拟序列分类问题的形式的过程感到很困惑。 My problem is basically of multi-class classification, like one would normally do using Machine Learning Classifiers to predict the labels, but using RNN with Attention. 我的问题基本上是多类分类,就像通常使用机器学习分类器来预测标签一样,但是将RNN与Attention一起使用。 Any help in this regard would be highly appreciated. 在这方面的任何帮助将不胜感激。 Cheers! 干杯!

Kindly refer to this paper for using Sequence to Sequence Model with attention for time series classification. 请参考本文以使用序列到序列模型,并注意时间序列分类。

https://www.computer.org/csdl/proceedings/icdmw/2016/5910/00/07836709.pdf https://www.computer.org/csdl/proceedings/icdmw/2016/5910/00/07836709.pdf

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM