{"id":19146478,"url":"https://github.com/kahsolt/youroqnet","last_synced_at":"2026-06-25T09:31:09.205Z","repository":{"id":178556044,"uuid":"646640730","full_name":"Kahsolt/YouroQNet","owner":"Kahsolt","description":"Official implementaion of YouroQNet, a toyish quantum text classifier implemented with pyVQNet and pyQPanda","archived":false,"fork":false,"pushed_at":"2023-07-14T14:30:40.000Z","size":7375,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-22T19:49:41.813Z","etag":null,"topics":["contest-solution","quantum-classifier","text-classification","vqnet"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Kahsolt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-29T02:20:27.000Z","updated_at":"2025-01-02T02:56:09.000Z","dependencies_parsed_at":null,"dependency_job_id":"b16c6dc2-9704-4a2d-b3ed-99b287dfe533","html_url":"https://github.com/Kahsolt/YouroQNet","commit_stats":null,"previous_names":["kahsolt/youroqnet"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Kahsolt/YouroQNet","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kahsolt%2FYouroQNet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kahsolt%2FYouroQNet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kahsolt%2FYouroQNet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kahsolt%2FYouroQNet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kahsolt","download_url":"https://codeload.github.com/Kahsolt/YouroQNet/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kahsolt%2FYouroQNet/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34769610,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-25T02:00:05.521Z","response_time":101,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["contest-solution","quantum-classifier","text-classification","vqnet"],"created_at":"2024-11-09T07:44:14.951Z","updated_at":"2026-06-25T09:31:09.160Z","avatar_url":"https://github.com/Kahsolt.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# YouroQNet: Quantum Text Classification with Context Memory\n\n    Official implementaion of YouroQNet, a toyish quantum text classifier implemented with pyVQNet and pyQPanda\n\n----\n\nThis repo contains code for the final problem of the OriginQ's [2nd CCF \"Pilot Cup\" contest](https://contest.originqc.com.cn/contest/4/contest:introduction) (Professional Group - Quantum Machine Learning Track).\n\n\u003e Oh yes yes child, we've run a hard time struggling.\n\nThe final total score is **79.2**, and ranking unknown; but why the fuck you owe me a point of 0.8?? 🐱\n\nAnd, code repo for the qualifying stage is here: [第二届“司南杯”初赛](https://github.com/Kahsolt/CCF-2nd-Pilot-Cup-first-stage)\n\n\n![YouroQNet](img/YouroQNet_arch.png)\n\n\n### Quickstart\n\n⚪ install\n\n- `conda create -n q python==3.8` (pyvqnet requires Python 3.8)\n- `conda activate q`\n- `pip install -r requirements.txt`\n\n⚪ for contest problem (👈 **Follow this to reproduce our contest results!!**)\n\n- `python answer.py` for preprocess \u0026 train (⚠ VERY VERY SLOW!!)\n- `python check.py` for evaluate\n\n⚪ for quick peek of YouroQNet components\n\n- `python vis_tokenizer.py` for adaptive k-gram tokeinzer interactive demo\n- `python vis_youroqnet.py` for YouroQNet interactive demo\n  - `run_quantum_toy.cmd` (👈 run the toy version out of box before all)\n\n⚪ for full development\n\n- download the full dataset [simplifyweibo_4_moods](https://github.com/SophonPlus/ChineseNlpCorpus/blob/master/datasets/simplifyweibo_4_moods/intro.ipynb), unzip `simplifyweibo_4_moods.csv` to `data` folder\n- `pip install -r requirements_dev.txt` for extra dependencies\n- `pushd repo \u0026 init_repos.cmd \u0026 popd` for extra git repos\n  - fasttext==0.9.2 requires numpy\u003c1.24 (things might changed)\n- `start_shell.cmd` to enter deveolp run command env\n  - `start_shell.cmd py` to get a ipy console that quick refering to `pyvqnet`'s fucking undocumented-documentation with `help()`\n- `mk_preprocess.cmd` for making clean datasets, stats, plots \u0026 vocabs etc... (~7 minutes)\n- `python vis_project.py` to see 3d data projection (you will understand what the fuck this dataset is 👿)\n- `run_baseline.cmd` to run classic models\n- `run_quantum.cmd` to run quantum models\n\n⚠ The training sometimes might fail due to ill random parameter initialization, when trainset loss not tends to decay or quickly go overfit, just kill it \u0026 retry 😅\n\n⚪ core idea \u0026 contributions\n\n- adaptive k-gram tokenizer (see [mk_vocab.py](mk_vocab.py), interactivate demo [vis_tokenizer.py](vis_tokenizer.py))\n- YouroQNet for text clf (see [run_quantum.py](run_quantum.py), interactivate demo [vis_youroqnet.py](vis_youroqnet.py))\n- theoretical analysis of why \u0026 how QNN works (see [vis_qc_apriori.py](vis_qc_apriori.py))\n\nℹ See our PPT [YouroQNet.pdf](ref/YouroQNet.pdf) for more conceptual understanding 🎉\n\n\n#### Dataset\n\nA subset from [simplifyweibo_4_moods](https://github.com/SophonPlus/ChineseNlpCorpus/blob/master/datasets/simplifyweibo_4_moods/intro.ipynb): `1600` samples for train, `400` samples for test. Class label names: `0 - joy`, `1 - angry`, `2 - hate`, `3 - sad`, however is not very semantically corresponding in the datasets :(\n\n⚠ File naming rule: `train.csv` is train set, `test.csv` is valid set, and the generated `valid.csv` might be the real test set for this contest. **We use csv filename to refer to each split in the code**\n\n\n### Todo List\n\n- [x] data exploration\n  - [x] guess the target test set (`valid.txt`)\n  - [x] vocab \u0026 freq stats\n  - [x] pca \u0026 cluster\n  - [ ] data relabel (?)\n- [ ] data filtering\n  - [x] punctuation sanitize\n  - [ ] stop words removal\n  - [x] too short / long sententce\n- [x] feature extraction\n  - [x] tf-idf (syntaxical)\n  - [x] fasttext embedding (sematical)\n  - [x] adaptive tokenizer\n- [x] baseline models\n  - [x] sklearn\n  - [x] vqnet-classical\n- [ ] quantum models\n  - [ ] quantum embedding\n  - [ ] model route on different length\n  - [x] multi to binary clf\n  - [ ] contrastive learning\n  - [ ] learn the difference\n\n\n### Project layout\n\n```python\n# meterials\nref/                # thesis for dev\n  Question-ML.png   # problem sheet\n  YouroQNet.pdf     # solution PPT (YouroQNet)\n  init_thesis.cmd   # thesis donwloader\nrepo/               # git repos for research\n  init_repos.cmd    # git repo cloner\n  update_repos.cmd\ndata/               # dataset\n  simplifyweibo_4_moods.csv   # raw dataset (manually download)\n  train|test.csv    # context dataset\n  *_cleaned.csv\n  *_tokenized.txt\n  cc.zh.300.bin     # FastText pretrained word embedding (auto downloaded)\nlog/                # outputs\n  \u003canalyzer\u003e/       # aka. vocab\n    \u003cfeature\u003e/      # sklearn models\n    \u003cmodel\u003e/        # vqnet/torch models\ntmp/                # generated intermediate results for debug\n\n# contest related\nanswer.py           # run script for preprocessing \u0026 training\ncheck.py            # run script for evalution\n\n# preprocessors\nmk_*.py\nmk_preprocess.cmd   # run script for mk_*.py\n\n# models\nrun_baseline_*.py   # classical experiments\nrun_baseline.cmd    # run script for run_baseline_*.py\nrun_quantum.py      # quantum experiments\nrun_quantum.cmd     # run script for run_quantum.py\nrun_quantum_toy.cmd # toy QNN for debug and verify\n\n# misc\nvis_*.py            # intercative demos or debug scaffolds\nutils.py            # common utils\nstart_shell.cmd     # develop env entry\n\n# doc \u0026 lic\nREADME.md\nTECH.md             # techincal \u0026 theoretical stuff\nrequirements_*.txt\nLICESE\n```\n\nℹ For the contest, only these files are submitted: `answer.py`, `mk_vocab.py`, `run_quantum.py`, `utils.py`, `README.md`; it should be enough to run all quantum parts 😀\n\n\n### References\n\n- FastText: \n  - Enriching Word Vectors with Subword Information: [https://arxiv.org/abs/1607.04606](https://arxiv.org/abs/1607.04606)\n  - Bag of Tricks for Efficient Text Classification: [https://arxiv.org/abs/1607.01759](https://arxiv.org/abs/1607.01759)\n  - repo: [https://github.com/facebookresearch/fastText](https://github.com/facebookresearch/fastText)\n- QNN for text-clf:\n  - QNLP-DisCoCat: [https://arxiv.org/abs/2102.12846](https://arxiv.org/abs/2102.12846)\n  - QSANN: [https://arxiv.org/abs/2205.05625](https://arxiv.org/abs/2205.05625)\n- OriginQ: [https://originqc.com.cn/index.html](https://originqc.com.cn/index.html)\n  - QPanda: [https://github.com/OriginQ/QPanda-2](https://github.com/OriginQ/QPanda-2)\n  - pyQPanda: [https://pyqpanda-toturial.readthedocs.io/zh/latest/](https://pyqpanda-toturial.readthedocs.io/zh/latest/)\n  - pyVQNet: [https://vqnet20-tutorial.readthedocs.io/en/main/index.html](https://vqnet20-tutorial.readthedocs.io/en/main/index.html)\n- QCNN related:\n  - tensorflow-quantum impl: [https://www.tensorflow.org/quantum/tutorials/qcnn](https://www.tensorflow.org/quantum/tutorials/qcnn)\n  - pytorch + qiskit impl: [https://github.com/YPadawan/qiskit-hackathon](https://github.com/YPadawan/qiskit-hackathon)\n  - pytorch + pennylane impl: [https://github.com/christorange/QC-CNN](https://github.com/christorange/QC-CNN)\n- Tiny-Q: [https://github.com/Kahsolt/Tiny-Q](https://github.com/Kahsolt/Tiny-Q)\n\n=\u003e find thesis of related work in [ref/init_thesis.cmd](ref/init_thesis.cmd)  \n=\u003e find implementations of related work in [repo/init_repos.cmd](repo/init_repos.cmd)  \n\n\n### Citation\n\nIf you find this work useful, please give a star ⭐ and cite~ 😃\n\n```\n@misc{kahsolt2023,\n  author = {Kahsolt},\n  title  = {YouroQNet: Quantum Text Classification with Context Memory},\n  howpublished = {\\url{https://github.com/Kahsolt/YouroQNet}}\n  month  = {May},\n  year   = {2023}\n}\n```\n\n----\nby Armit\n2023/05/03 \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkahsolt%2Fyouroqnet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkahsolt%2Fyouroqnet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkahsolt%2Fyouroqnet/lists"}