{"about":{"site":"https://codewithpapers.app","non_affiliation":"Code with Papers and Syntology are not affiliated with, endorsed by, or sponsored by Papers with Code, Meta, or the pwc-archive mirror.","licence":"CC BY-SA 4.0","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","attribution":"https://codewithpapers.app/attribution","modified":"archive material modified by Syntology; see the attribution page"},"url":"/paper/contrastive-active-inference","title":"Contrastive Active Inference","arxiv_id":"2110.10083","date":"2021-10-19","proceeding":"NeurIPS 2021 12","authors":["Pietro Mazzaglia","Tim Verbelen","Bart Dhoedt"],"abstract":"Active inference is a unifying theory for perception and action resting upon the idea that the brain maintains an internal model of the world by minimizing free energy. From a behavioral perspective, active inference agents can be seen as self-evidencing beings that act to fulfill their optimistic predictions, namely preferred outcomes or goals. In contrast, reinforcement learning requires human-designed rewards to accomplish any desired outcome. Although active inference could provide a more natural self-supervised objective for control, its applicability has been limited because of the shortcomings in scaling the approach to complex environments. In this work, we propose a contrastive objective for active inference that strongly reduces the computational burden in learning the agent's generative model and planning future actions. Our method performs notably better than likelihood-based active inference in image-based tasks, while also being computationally cheaper and easier to train. We compare to reinforcement learning agents that have access to human-designed reward functions, showing that our approach closely matches their performance. Finally, we also show that contrastive methods perform significantly better in the case of distractors in the environment and that our method is able to generalize goals to variations in the background. Website and code: https://contrastive-aif.github.io/","url_abs":"https://arxiv.org/abs/2110.10083v4","url_pdf":"https://arxiv.org/pdf/2110.10083v4.pdf","source":{"archive":"pwc-archive (Hugging Face), CC BY-SA 4.0","snapshot":"2025-07-28","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","row_kind":"abstracts"},"code_links":[{"paper_slug":"contrastive-active-inference","repo_url":"https://github.com/mazpie/contrastive-aif","is_official":1,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":null}],"tasks":[{"task_slug":"reinforcement-learning","task_name":"Reinforcement Learning"},{"task_slug":"reinforcement-learning-1","task_name":"Reinforcement Learning (RL)"},{"task_slug":"reinforcement-learning-2","task_name":"reinforcement-learning"}],"methods":[],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2110.10083","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2110.10083"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-24T18:15:14+00:00","read_at_is":"when the build read Syntology's graph, not when any sample ran","claim":"Per-sample execution status on synthesized fixtures; not a correctness claim about the paper. Samples come from repositories linked to the paper, official or community; repo_kind says which.","repos":[{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/mazpie/contrastive-aif","reach":null}],"summary":{"ran":2,"ran_draft_wrong":7,"unverified":1},"by_repo_kind":{"official":{"samples":10,"ran":9,"repositories":1}},"repo_kind_vocabulary":{"official":"The archive marks this repository official for the paper","named_in_paper":"The archive records that the paper mentions this repository; it is not marked official","listed":"In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper","found_in_text":"Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted","community":"Not in the archive's code links for this paper; a community repository Syntology harvested"},"n_pointer_only_for_licence":0,"samples":[{"code_sha256_prefix":"21a1b62a3b1d50d8","entry":"FreezeParameters","repo":"mazpie/contrastive-aif","repo_kind":"official","path":"agents.py","file_url":"https://github.com/mazpie/contrastive-aif/blob/HEAD/agents.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"21a1b62a3b1d50d8"}},{"code_sha256_prefix":"09d1b0e1811952ff","entry":"RunningMeanStd","repo":"mazpie/contrastive-aif","repo_kind":"official","path":"agents.py","file_url":"https://github.com/mazpie/contrastive-aif/blob/HEAD/agents.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"09d1b0e1811952ff"}},{"code_sha256_prefix":"445535640638841c","entry":"detach_state","repo":"mazpie/contrastive-aif","repo_kind":"official","path":"agents.py","file_url":"https://github.com/mazpie/contrastive-aif/blob/HEAD/agents.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"445535640638841c"}},{"code_sha256_prefix":"97920ad76eb461ca","entry":"expand_state","repo":"mazpie/contrastive-aif","repo_kind":"official","path":"agents.py","file_url":"https://github.com/mazpie/contrastive-aif/blob/HEAD/agents.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"97920ad76eb461ca"}},{"code_sha256_prefix":"7bd437277f3c1ca4","entry":"flatten_state","repo":"mazpie/contrastive-aif","repo_kind":"official","path":"agents.py","file_url":"https://github.com/mazpie/contrastive-aif/blob/HEAD/agents.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"7bd437277f3c1ca4"}},{"code_sha256_prefix":"49f065db9df001d7","entry":"get_dist","repo":"mazpie/contrastive-aif","repo_kind":"official","path":"agents.py","file_url":"https://github.com/mazpie/contrastive-aif/blob/HEAD/agents.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"49f065db9df001d7"}},{"code_sha256_prefix":"3091e1fe6e877363","entry":"get_parameters","repo":"mazpie/contrastive-aif","repo_kind":"official","path":"agents.py","file_url":"https://github.com/mazpie/contrastive-aif/blob/HEAD/agents.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"3091e1fe6e877363"}},{"code_sha256_prefix":"1ad74b47dfca89f6","entry":"lambda_dreamer_values","repo":"mazpie/contrastive-aif","repo_kind":"official","path":"agents.py","file_url":"https://github.com/mazpie/contrastive-aif/blob/HEAD/agents.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"1ad74b47dfca89f6"}},{"code_sha256_prefix":"37e6eb67b71c9c45","entry":"stack_states","repo":"mazpie/contrastive-aif","repo_kind":"official","path":"agents.py","file_url":"https://github.com/mazpie/contrastive-aif/blob/HEAD/agents.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"37e6eb67b71c9c45"}},{"code_sha256_prefix":"75ec50fcae15b56d","entry":"Agent","repo":"mazpie/contrastive-aif","repo_kind":"official","path":"agents.py","file_url":"https://github.com/mazpie/contrastive-aif/blob/HEAD/agents.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"75ec50fcae15b56d"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}