huckiyang / QuantumSpeech-QCNN

IEEE ICASSP 21 - Quantum Convolution Neural Networks for Speech Processing and Automatic Speech Recognition
90 stars 17 forks source link

Random Quantum Circuits Lead to Unstable Model Performance #8

Closed cyx617 closed 2 years ago

cyx617 commented 3 years ago

Dear authors.

In a hybrid quantum-classical neural network, the quantum layer composed of parameterized quantum circuit usually integrates with other classical layers (e.g. convolutional layers, dense layers) and the parameters of these quantum circuits are updated together with those of classical layers through classical optimization method like SGD. But in this project, it seems that the parameterized quantum circuits do not directly integrate with other classical layers and they are not trainable. Each time when performing quantum feature extraction from Mel-spectrogram inputs, the parameters of the quantum circuits are randomly initialized and then kept fixed. So the quantum features extracted in this way are also random each time and will not be optimized any more before feeding into the latter parts of the model. Actually, I've run your code (python main_qsr.py --sr 16000 --port 100 --mel 1 --quanv 1 --eps 100) for a few times and got different model performance each time in terms of converged val accuracy (e.g. 0.19, 0.57). I guess this unstable performance is due to the random quantum feature extracted by quantum circuits. My question is how we could make sure these random features are optimal for the current task without being further optimized. Many thanks!

huckiyang commented 3 years ago

Dear Yixiong @cyx617,

Thank you for this question. At the beginning of this project, I did not tune the feature but instead increase the data scale. (e.g., set all the data by using --port 1) I only did decode once and used around a month to decode all the acoustic feature in the Google SpeechCommands. But I did observe if the data scale could not represent the full speech dataset, the random sample features would not be enough to train a speech model during the small-scale data re-runs.

For evaluating the stability of acoustic modeling, please use --port 1. But if your task belongs to an image classification, the data scale could be smaller. See https://pennylane.ai/qml/demos/tutorial_quanvolution.html with only 100 examples with random circuit to train the model.

In short, this issue can come from two perspectives from my empirical experience.

Note, we will give QuantumNN Tutorial in IJCAI 2021. Feel free to check.

cyx617 commented 3 years ago

@huckiyang 非常感谢您的回答以及您分享的链接!我看您的名字,感觉您可能会中文,所以就直接用中文给您留言吧。您的意思是说,如果数据量足够大,即便我们使用 random circuit对原始数据提取到的特征是随机特征,这些随机特征也可以保证模型的性能是吧?

我去年也尝试运行过这个链接中的demo,但是似乎每次运行后的结果(validation accuracy for quantum model)不是很稳定,有时候性能会比classical model要差,并没有像原始demo中显示的那样。不知道这是不是也是因为random circuit的原因。

我在colab上又运行了您的code,并按照您的建议使用了--port 1。但由于这次的数据量是之前的100倍,而且量子线路的操作也只能在cpu上运行,所以Quanvolution Encoding的时间非常久,colab由于长时间没有操作,已经自动断开。我在想是否可以在dev = qml.device('default.qubit', wires= n_w, noise_model=noise_model)中添加 interface='torch'或者使用QnodeCollection中的并行计算模式,这样量子线路的运行速度是否会更快。

关于为什么random circuit适用于大规模数据的特征提取,我可能还需要看一下您分享的那些资料。另外,我也会关注您的QuantumNN Tutorial in IJCAI 2021!非常期待!

huckiyang commented 3 years ago

@cyx617 Hello Yixiong

非常感谢您的回答以及您分享的链接!我看您的名字,感觉您可能会中文,所以就直接用中文给您留言吧。您的意思是说,如果数据量足够大,即便我们使用 random circuit对原始数据提取到的特征是随机特征,这些随机特征也可以保证模型的性能是吧?

You are welcome. Yes, feel free to use the language you are more comfortable with for asking the question. (I am on Linux dev-desktop only with English for answering) The understanding of the scale effect on the random features is correct.

我去年也尝试运行过这个链接中的demo,但是似乎每次运行后的结果(validation accuracy for quantum model)不是很稳定,有时候性能会比classical model要差,并没有像原始demo中显示的那样。不知道这是不是也是因为random circuit的原因。

This is coming from both the size training data. For the demo data, we do not provide all the QVC-encoded features owing to the size limit. For example, if you use a subset of MNIST to train a DNN model, this instability will also appear due to the shallow data.

我在colab上又运行了您的code,并按照您的建议使用了--port 1。但由于这次的数据量是之前的100倍,而且量子线路的操作也只能在cpu上运行,所以Quanvolution Encoding的时间非常久,colab由于长时间没有操作,已经自动断开。我在想是否可以在dev = qml.device('default.qubit', wires= n_w, noise_model=noise_model)中添加 interface='torch'或者使用QnodeCollection中的并行计算模式,这样量子线路的运行速度是否会更快。

I have to say the code is not designed for Colab because VQC usually takes one to two weeks for random features encoding on a large-scale speech corpus.

But for the information you provided, I think it makes sense and might be the new function from PennyLane this year.

Cheers!

huckiyang commented 3 years ago

@cyx617 The quantum ml tutorial will be host tomorrow. Feel free to join https://huckiyang.github.io/quantum-ml-main/

cyx617 commented 3 years ago

@huckiyang 非常感谢您的回答!您这边是否尝试过把Quanvolution Encoding嵌入到您的模型中,做出一个hybrid quantum-classical model,这样quantum circuit中的参数可以随着模型的训练,动态地去更新。不过这样的话,可能会导致模型训练速度明显下降很多,因为目前pennylane在执行quantum circuit的计算过程中,并不支持vectorization,而且很多的simulator(例如pennylane中的default.qubit)是不能在GPU上运行的。

另外,也很感谢您的邀请, 我会关注并参与这个quantum ml tutorial! 非常期待!

cyx617 commented 3 years ago

@huckiyang 这次的quantum ml tutorial非常精彩!学了很多东西!也非常感谢您对我那三个问题的详细回答!

huckiyang commented 2 years ago

Thank you for the great questions and keep in touch!