【发布时间】:2020-04-16 14:37:51
【问题描述】:
我只是这个主题的初学者,我已经测试了一些用于图像识别的神经网络以及使用 NLP 进行序列分类。
第二个话题对我来说很有趣。 使用
sentences = [
'some test sentence',
'and the second sentence'
]
tokenizer = Tokenizer(num_words=100, oov_token='<OOV>')
tokenizer.fit_on_texts(sentences)
sentences = tokenizer.texts_to_sequences(sentences)
将产生一个大小为[n,1] 的数组,其中n 是句子中的单词大小。假设我已经正确实现了填充,集合中的每个训练示例的大小将是 [n,1],其中 n 是最大句子长度。
准备好的训练集我可以传入 keras model.fit
当我的数据集中有多个特征时怎么办? 假设我想构建一个事件优先级算法,我的数据结构如下所示:
[event_description, event_category, event_location, label]
尝试对此类数组进行标记将导致 [n,m] 矩阵,其中 n 是最大字长,m 是特征数
如何准备这样的数据集,以便可以根据这些数据训练模型?
这种方法可以吗:
# Going through training set to get all features into specific ararys
for data in dataset:
training_sentence.append(data['event_description'])
training_category.append(data['event_category'])
training_location.append(data['event_location'])
training_labels.append(data['label'])
# Tokenize each array which contains tokenized value
tokenizer.fit_on_texts(training_sentence)
tokenizer.fit_on_texts(training_category)
tokenizer.fit_on_texts(training_location)
sequences = tokenizer.texts_to_sequences(training_sentence)
categories = tokenizer.texts_to_sequences(training_category)
locations = tokenizer.texts_to_sequences(training_location)
# Concatenating arrays with features into one
training_example = numpy.concatenate([sequences,categories, locations])
#ommiting model definition, training the model
model.fit(training_example, training_labels, epochs=num_epochs, validation_data=(testing_padded, testing_labels_final))
我还没有测试它。我只是想确定我是否正确理解了所有内容以及我的假设是否正确。
这是使用 NN 创建 NPL 的正确方法吗?
【问题讨论】:
标签: python tensorflow machine-learning deep-learning neural-network