How to use trained BERT model to predict new data?

Dear All,

I am currently using the workflow developed by BBC Documents classification with BERT extension. I replaced BBC documents with my own data and trained the fine tuned BERT model. Upon here, everything works fine.

My question is: I actually want to use the fine tuned model to process a large amount of articles and generate predictions for every article. How would I amend the workflow to achieve this? I know this sounds not challenging at all, but, I am new to KNIME, so I look forward to see your help.

My initial plan as follows:
Perhaps I after trained Bert model, I can disconnect BERT PREDICTOR (btw, the disconnect botton turned grey and does not work) from the model. And I dock it with my own large dataset (stored as txt files, same as the uploading format of this model) at the front. After processing, I output the results with column appender or domain calculator? Will that work?

I sincerely thank you for any hints you can provide.

Hi @Mark_Zheng -

One way to approach this would be to have separate workflows for training your model, and deployment of that model. During the training workflow, you just make sure to use the Model Writer as you are already doing.

Then, in the deployment workflow, you use a Model Reader, along with your new dataset and any other preprocessing nodes you might need, to pass into the BERT Predictor.

(If you wanted to get even more sophisticated, you could use Integrated Deployment to approach this as well, but I would leave that until you’re more comfortable with the manual approach first.)

1 Like

Hi Scott,

Thank you so much for timely reply. One follow up question (although looks primitive): if I want a table that records the content as one column, and predictions (categories) as another column, so that I can make a summary of predictions. What might be the ideal node that conncects to the Bert Predictor as output?

Thank you so much.

I thought that the BERT Predictor output the model features along with the predictions already, but maybe I’m wrong about that (I can’t easily check on my current machine). If that’s not correct, I suppose you could always use a Joiner to join the predictions back to the original dataset based on the RowID or similar.

(@Redfield please feel free to correct me or provide additional info here.)


Hello @Mark_Zheng

I believe @ScottF 's answer is correct. In order to use BERT Predictor node you only need to have 1 column with a raw text, other columns are optional and not needed for the input of the BERT Predictor.

As the output BERT Predictor will return you the same table as input table with extra columns depending on the settings of the node. By default it will be a column with document class predictions. In the settings of BERT Predictor you can also activate the checkbox to return the class probabilities as well.

And as Scott mentioned you can then use Joiner node in case you would like to combine the predictions with another table.

1 Like