[英]How to give one sample text input to a pre-trained LSTM model
I am trying to do toxic comment classification.我正在尝试进行有毒评论分类。 I found a dataset in https://www.kaggle.com/c/jigsaw-toxic-comment-classification-challenge .我在https://www.kaggle.com/c/jigsaw-toxic-comment-classification-challenge找到了一个数据集。 It has many comments with corresponding values for label class "toxic", "severe_toxic" ..etc.它有许多注释以及标签类别“毒性”、“严重毒性”..等的相应值。 I want to classify my single text input to the corresponding labeled class.我想将我的单个文本输入分类到相应的标记类。 I have created and trained a model using LSTM.我已经使用 LSTM 创建并训练了一个模型。 Now I want to give a single text sentence as input to the model to predict the output.现在我想给一个单一的文本句子作为模型的输入来预测输出。 But I don't know how to convert the text input and give it to the trained model.但我不知道如何转换文本输入并将其提供给经过训练的模型。
The source-code has been obtained from kaggle challange .源代码已从kaggle challange获得。
Prediction can be done using predict()
function as below:可以使用predict()
函数进行predict()
,如下所示:
y_predict = model.predict(X_te, batch_size=batch_size)
Where, X_te
is the pre-processed test-set. y_predict = model.predict(X_te, batch_size=batch_size)
其中, X_te
是预处理的测试集。 The pre-processing is generally same for training-set and test-set.训练集和测试集的预处理通常相同。
In case, if you want to predict for a single instance from the test set, the input has to be reshaped, as given below:如果您想从测试集中预测单个实例,则必须重新调整输入,如下所示:
y_pred = model.predict(X_te[0].reshape(200,))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.