Tencent / NeuralNLP-NeuralClassifier

An Open-source Neural Hierarchical Multi-label Text Classification Toolkit

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

"predict.py" produces blank output file

caruofc opened this issue · comments

Hi,

I compiled your source code and performed the following:

  1. edit "conf/train.hmcn.json" and set "task_info --> hierarchical" to false, and "model_name" to "HMCN"
  2. ran "train.py conf/train.hmcn.json"

Above command produced "HMCN_1" to "HMCN_50" files and "HMCN_best" file in "checkpoint_dir_rcv1" folder.
Then, I created a json file for prediction called "predict.json" and add the following line and save it

{"doc_label": ["Computer--MachineLearning--DeepLearning","Neuro--ComputationalNeuro"],"doc_token": ["I", "love", "deep", "learning"],"doc_keyword": ["deep learning"],"doc_topic": ["AI", "Machine learning"]}

After that I ran "predict.py conf/train.hmcn.json predict.json"
The program ran with exit code 0 and it also produced the output "predict.txt". However, there is nothing in the txt file. it is completely blank.

Could you please tell me what I am doing wrong?

And by the way, I had to make the following changes in the "predict.py" file to make it work.

line# 80 had to change to:
if self.model_name == "HMCN":
(global_logits, local_logits, logits) = self.model(batch_texts)
else:
logits = self.model(batch_texts)

and I also had to add "from model.classification.hmcn import HMCN" after line# 39.

UPDATE:
I downloaded the code again compiled and ran it. It now shows this classification: GCAT--GCRIM, for the sample input:

{"doc_label": ["Computer--MachineLearning--DeepLearning","Neuro--ComputationalNeuro"],"doc_token": ["I", "love", "deep", "learning"],"doc_keyword": ["deep learning"],"doc_topic": ["AI", "Machine learning"]}

is it correct? anybody can confirm, please?

Also, it seems training the model with the same dataset multiple times does not produce the same prediction result. Is it what we expect? I am confused.

Last question. In the training dataset the doc_labels are like "CCAT--C31--C312" which is what the algorithm learns to classify when "doc_token" is given. But why do we need "doc_label" (isn't the "doc_label" we are trying to predict?) in the input that we want to predict? and why the "doc_label" texts are in "word" format rather than "code" format? It might be a trivial question to someone who is familiar with the work but I am kind of new in this area. Any input would be highly appreciated. Thanks in advance.

UPDATE:
I downloaded the code again compiled and ran it. It now shows this classification: GCAT--GCRIM, for the sample input:

{"doc_label": ["Computer--MachineLearning--DeepLearning","Neuro--ComputationalNeuro"],"doc_token": ["I", "love", "deep", "learning"],"doc_keyword": ["deep learning"],"doc_topic": ["AI", "Machine learning"]}

is it correct? anybody can confirm, please?

If you only edit hierarchical and model_name in train.hmcn.json, your training is still using the default toy dataset data/rcv1_train.hierar.json and vocabulary data/rcv1.taxonomy. Of course your model can only output labels defined in data/rcv1.taxonomy.

BTW, HMCN is a model designed for hierarchical classification, so you should not set hierarchical to false when using HMCN.

Last question. In the training dataset the doc_labels are like "CCAT--C31--C312" which is what the algorithm learns to classify when "doc_token" is given. But why do we need "doc_label" (isn't the "doc_label" we are trying to predict?) in the input that we want to predict? and why the "doc_label" texts are in "word" format rather than "code" format? It might be a trivial question to someone who is familiar with the work but I am kind of new in this area. Any input would be highly appreciated. Thanks in advance.

In prediction, the label you provide is actually not used, we need it because training and prediction share the same code, and we need label in training.