CQCL / lambeq

A high-level Python library for Quantum Natural Language Processing
https://cqcl.github.io/lambeq-docs
Apache License 2.0
449 stars 108 forks source link

Question : What does the Quantum_trainer output? #13

Closed ACE07-Sev closed 2 years ago

ACE07-Sev commented 2 years ago

Hi, I wish to use the Quantum_trainer to do a Depression Detection using a chatbot (the sentences would be the input for the QNLP module), and wish to then classify as whether the person has depression or not.

May I ask what is the input and what is the output in the sample trainer for the quantum module? Does it do binary classification or is it something I need to add as an additional layer?

Thommy257 commented 2 years ago

Hi, the QuantumTrainer provides a high level abstraction of a standard machine learning training routine. It stores the training statistics and takes a model as input. During the training, it saves the state of the model in checkpoint files, that can be used to instantiate a new model for inference through:

model = TketModel.from_checkpoint('path/to/checkpoint')
Thommy257 commented 2 years ago

The output of your model depends on your circuit/diagrams. If you have one open (qubit) wire, the output will be a 2-d array, if you have two output wires, the output will be a 4-d array, and so on. Currently, only the PytorchModel supports additional layers, however, we'll add Pennylane and tensorflow-quantum support soon.

ACE07-Sev commented 2 years ago

So imagining I have a dataset of 1 feature, and one label, if I feed the dataset to the quantum_trainer.ipynb version, can I extract predictions for binary classification?

ACE07-Sev commented 2 years ago

Is the quantum_trainer.ipynb basically creating and training the model on the dataset? If so, how can I extract predictions on new samples?

Thommy257 commented 2 years ago

The trainer only wraps the training routine of the model. You define an instance of the model first, pass it to the trainer and after training, you can predict the outcome of a new diagram through:

score = model(new_samples_diagrams)
ACE07-Sev commented 2 years ago

Understood, so to call the model on new instances I have to first pass them through the parser to be reformed as diagrams as well correct?

Thommy257 commented 2 years ago

That is correct. But bear in mind that you have to take care of word tokens that are unknown to the model. If you pass a diagram to the model that contains a word that wasn't part of the training process, it'll fail to calculate the output.

In classical NLP, one would for example deal with that by introducing an <unk> token, that replaces all rare words in your corpus.

y-richie-y commented 2 years ago

The original question has been answered, so this issue will be closed.