Convert pytorch NLP model to onnx format - pytorch

I built a NLP model to extract named entities from raw text using flair sequencetagger algorithm. I'm not able to export it to onnx format. I don't know how to give dummy input for this model
I tried with torch.onnx.export but got errormessage as JIT scipts only accept list, tuples,etc.but what is given is sentence

Related

export an unfitted model to ONNX

I am building an API for training models, and figured I wanted to use ONNX to send the models back and forth.
I am testing with a sklearn XGboost model, and it seems that it is a requirement to fit the model before I can export it to onnx.
I want to define a custom or standard sklearn model, convert to onnx for transport, reopen and train, save in ONNX
Is this feasable at all?
My end goal is to have an API that can accept any sklearn, tensorflow or similar model in an untrained state and then train on the server.
Onnx is used to deliver model results, including pre and post-processing or other manipulations, "in production".
The assumption is the model is already trained and you only need to "predict" (or whatever similar action) on new data.
Sound like what you need is a Python (or other) code that will receive your API calls, translate them into the appropriate models, train the models, and then, if you want to be independent from an MLOps point of view, transform the result into Onnx.

Bart model inference results after converting from hugginface to onnx

I followed the instructions to convert BART-LARGE-CNN model to ONNX here (https://github.com/huggingface/transformers/blob/master/docs/source/serialization.rst) using transformers.onnx script. The model was exported fine and I can run inference.
However, the results of the inference, from the 'last_hideen_state' are in logits (I think)? How can I parse this output for summarization purposes?
Here are screenshots of what I've done.
This is the resulting output from those two states:
I have implemented fast-Bart. Which essentially converts Bart model from Pytorch to Onnx- with generate capabilities.
fast-Bart

How to evaluate pre-trained NER model on my domain specific text with stanza (for coreNLP)?

I am trying to get F1 scores for the pre-trained English model on my specific text domain without doing any training.
The docs mention the following command:
python -m stanza.utils.training.run_ete ${corpus} --score_${split}
However as I don't want to do any training, how can I evaluate the model as is?
Also, the format of ${corpus} is not stated in the docs.
I've got an annotated dataset for my domain in BIO format.

Extracting word embeddings for a xlnet calssification model in simple transformers?

I am trying to implement a xlnet transformer model using the Simple Transformers library. I am following this particular tutorial - https://simpletransformers.ai/docs/multi-class-classification/
According to this, I can train the model on the train_df and then produce results like accuracy, f1 score, etc. but is there a way to extract the word embedding produced by this model when trained on the training data? I would be interested in analyzing the plotting those embeddings for academic purposes but I am unable to figure out a way to do so in the Simple Transformers library.

How to convert Caffe weights to Keras

Is there a good way or a tool to convert .caffemodel weight files to HDF5 files that can be used with Keras?
I don't care so much about converting the Caffe model definitions, I can easily write those in Keras manually, I'm just interested in getting the trained weights out of that Caffe binary protocol buffer format and into the Keras format. I'm not a Caffe user, i.e. not very familiar with it.

Resources