Human-like cognitive generalization for large models via mental representation-guided supervision.
5 blocks of code here have a permanent identifier (oscr:b:…), listed with the matches below: citable for good, with a page of its own. Select a match and press Cite to copy it. What a block identifier is.
The 7 matches · 1 of them tie a paragraph to a whole file without given lines: a weak match, whose lines are not tinted
- [1] § Methods › Mental representation-guided supervised learning › Correspondence construction via optimal transport (OT) ↔ modules/LSP/optimal_Transport.py, lines 4 to 93 · score 0.78 · optimal transport plan, Sinkhorn algorithm, regularized OT, Wasserstein, iterative, matrix · block
oscr:b:EADF6DJRW0K5K-N· Report a mismatch - [2] § Methods › Architecture and optimization › Loss function ↔ modules/LSP/optimal_Transport.py, lines 4 to 93 · score 0.74 · Sinkhorn iterations, regularized OT, transport plan, cost matrix · block
oscr:b:EADF6DJRW0K5K-N· Report a mismatch - [3] § Methods › Datasets › fMRI data ↔ data/data_config.py, the whole file · a weak match · score 0.62 · ImageNet, fMRI, FFA, LOC, PPA, stimuli · block
oscr:b:MEPAZM4QB5M1P-V· Report a mismatch - [4] § Methods › Architecture and optimization › Loss function ↔ modules/LSP/encoder.py, lines 30 to 127 · score 0.59 · fMRI encoders, cost matrix, kernel, OT, iterations, Loss · block
oscr:b:XH4TGFBP0ABZ7-4· Report a mismatch - [5] § Methods › Architecture and optimization › Model architecture ↔ modules/LSP/encoder.py, lines 30 to 127 · score 0.59 · Gumbel Softmax, GNN, sampler, scores, head, encoders · block
oscr:b:XH4TGFBP0ABZ7-4· Report a mismatch - [6] § Methods › Architecture and optimization › Loss function ↔ modules/LSP/GW_OT.py, lines 269 to 286 · score 0.53 · probability vectors, GW distance · block
oscr:b:1FC7N0E5653VT-C· Report a mismatch - [7] § Methods › Mental representation-guided supervised learning › Correspondence construction via optimal transport (OT) ↔ modules/LSP/GW_OT.py, lines 8 to 19 · score 0.51 · cosine distance, cost matrix, OT, transport · block
oscr:b:E4DRET5JJREKW-Z· Report a mismatch
Paper
Loaded from Europe PMC by your browser; OSCR does not store it: doi.org · Europe PMC
The paper is loaded when this pane is shown.
The authors' code
Python · 134 lines · 4.9 KB · no license · 2 matches
- import torch
- import torch.nn as nn
- # Adapted from https://github.com/gpeyre/SinkhornAutoDiff
- class SinkhornDistance(nn.Module):
- r"""
- Given two empirical measures each with :math:`P_1` locations
- :math:`x\in\mathbb{R}^{D_1}` and :math:`P_2` locations :math:`y\in\mathbb{R}^{D_2}`,
- outputs an approximation of the regularized OT cost for point clouds.
- Args:
- eps (float): regularization coefficient
- max_iter (int): maximum number of Sinkhorn iterations
- reduction (string, optional): Specifies the reduction to apply to the output:
- 'none' | 'mean' | 'sum'. 'none': no reduction will be applied,
- 'mean': the sum of the output will be divided by the number of
- elements in the output, 'sum': the output will be summed. Default: 'none'
- Shape:
- - Input: :math:`(N, P_1, D_1)`, :math:`(N, P_2, D_2)`
- - Output: :math:`(N)` or :math:`()`, depending on `reduction`
- """
- def __init__(self, eps, max_iter, reduction='none'):
- super(SinkhornDistance, self).__init__()
- self.eps = eps
- self.max_iter = max_iter
- self.reduction = reduction
- def forward(self, x, y):
- # The Sinkhorn algorithm takes as input three variables :
- C = self._cost_matrix(x, y) # Wasserstein cost function
- x_points = x.shape[-2]
- y_points = y.shape[-2]
- if x.dim() == 2:
- batch_size = 1
- else:
- batch_size = x.shape[0]
- # both marginals are fixed with equal weights
- mu = torch.empty(batch_size, x_points, dtype=torch.float,
- requires_grad=False).fill_(1.0 / x_points).squeeze()
- nu = torch.empty(batch_size, y_points, dtype=torch.float,
- requires_grad=False).fill_(1.0 / y_points).squeeze()
- u = torch.zeros_like(mu)
- v = torch.zeros_like(nu)
- # To check if algorithm terminates because of threshold
- # or max iterations reached
- actual_nits = 0
- # Stopping criterion
- thresh = 1e-1
- # Sinkhorn iterations
- for i in range(self.max_iter):
- u1 = u # useful to check the update
- u = self.eps * (torch.log(mu+1e-8) - torch.logsumexp(self.M(C, u, v), dim=-1)) + u
- v = self.eps * (torch.log(nu+1e-8) - torch.logsumexp(self.M(C, u, v).transpose(-2, -1), dim=-1)) + v
- err = (u - u1).abs().sum(-1).mean()
- actual_nits += 1
- if err.item() < thresh:
- break
- U, V = u, v
- # Transport plan pi = diag(a)*K*diag(b)
- pi = torch.exp(self.M(C, U, V))
- # Sinkhorn distance
- cost = torch.sum(pi * C, dim=(-2, -1))
- if self.reduction == 'mean':
- cost = cost.mean()
- elif self.reduction == 'sum':
- cost = cost.sum()
- return cost, pi, C
- def M(self, C, u, v):
- "Modified cost for logarithmic updates"
- "$M_{ij} = (-c_{ij} + u_i + v_j) / \epsilon$"
- return (-C + u.unsqueeze(-1) + v.unsqueeze(-2)) / self.eps
- @staticmethod
- def _cost_matrix(x, y, p=2):
- "Returns the matrix of $|x_i-y_j|^p$."
- x_col = x.unsqueeze(-2)
- y_lin = y.unsqueeze(-3)
- C = torch.sum((torch.abs(x_col - y_lin)) ** p, -1)
- return C
- @staticmethod
- def ave(u, u1, tau):
- "Barycenter subroutine, used by kinetic acceleration through extrapolation."
- return tau * u + (1 - tau) * u1
- def log_sinkhorn_iterations(Z, log_mu, log_nu, iters: int):
- """ Perform Sinkhorn Normalization in Log-space for stability"""
- u, v = torch.zeros_like(log_mu), torch.zeros_like(log_nu)
- for _ in range(iters):
- u = log_mu - torch.logsumexp(Z + v.unsqueeze(1), dim=2)
- v = log_nu - torch.logsumexp(Z + u.unsqueeze(2), dim=1)
- return Z + u.unsqueeze(2) + v.unsqueeze(1)
- def log_optimal_transport(scores, alpha, iters: int, use_bin = False):
- """ Perform Differentiable Optimal Transport in Log-space for stability"""
- b, m, n = scores.shape
- one = scores.new_tensor(1)
- ms, ns = (m*one).to(scores), (n*one).to(scores)
- if(use_bin):
- bins0 = alpha.expand(b, m, 1)
- bins1 = alpha.expand(b, 1, n)
- alpha = alpha.expand(b, 1, 1)
- couplings = torch.cat([torch.cat([scores, bins0], -1),
- torch.cat([bins1, alpha], -1)], 1)
- norm = - (ms + ns).log()
- log_mu = torch.cat([norm.expand(m), ns.log()[None] + norm])
- log_nu = torch.cat([norm.expand(n), ms.log()[None] + norm])
- log_mu, log_nu = log_mu[None].expand(b, -1), log_nu[None].expand(b, -1)
- else:
- couplings = scores
- norm = - (ms + ns).log()
- log_mu = norm.expand(m)
- log_nu = norm.expand(n)
- log_mu, log_nu = log_mu[None].expand(b, -1), log_nu[None].expand(b, -1)
- Z = log_sinkhorn_iterations(couplings, log_mu, log_nu, iters)
- Z = Z - norm # multiply probabilities by M+N
- return Z
optimal_Transport.py at commit 9bf6b66, no license · at the source
Overview
- College of Computer Science and Technology, Zhejiang University, Hangzhou, China
- State Key Lab of Brain-Machine Intelligence, Zhejiang University, Hangzhou, China
- Affiliated Mental Health Center and Hangzhou Seventh People’s Hospital, MOE Frontier Science Center for Brain Science and Brain-Machine Integration, Zhejiang University, Hangzhou, China
Abstract
The abstract is not reproduced here: the paper's license (CC BY-NC-ND) does not allow it. Read it in the paper, at the publisher or on Europe PMC.
Repository
Its files are read in the Code ↔ Paper reader above, with 7 matches between paragraphs and lines of code.
JxuanC/mental-representation-guided-learning
9bf6b6629033823e786142eaa00eff332d2bd929, 14 August 2026Availability: 1 check, the latest on 28 September 2026: the link answers
- 28 September 2026: the link answers
34 files
- brain2image.py, Python, 98 lines
- brain_in_the_loop_traini
ng.py , Python, 97 lines - data/
BMDataset.py , Python, 39 lines - data/
DIR.py , Python, 115 lines - data/
data_augment.py , Python, 269 lines - data/
data_config.py , Python, 41 lines, 1 match - data/
data_handle.py , Python, 102 lines - download.py, Python, 43 lines
- extract_brain_in_the_loo
p_features.py , Python, 60 lines - extract_clip_features.py
, Python, 84 lines - extract_coco_features.py
, Python, 90 lines - extract_dinov2_features.
py , Python, 86 lines - extract_simclr_features.
py , Python, 121 lines - gpt_decoder_training.py, Python, 167 lines
- modules/
LSP/ , Python, 344 lines, 2 matchesGW_OT.py - modules/
LSP/ , Python, 127 lines, 2 matchesencoder.py - modules/
LSP/ , Python, 119 linesgnn.py - modules/
LSP/ , Python, 134 lines, 2 matchesoptimal_Transport.py - modules/
LSP/ , Python, 28 linessampler.py - modules/
LSP/ , Python, 126 linesvit.py - modules/
blip_models.py , Python, 419 lines - modules/
matching_evaluation.py , Python, 32 lines - modules/
matching_loss.py , Python, 22 lines - smallcap/
src/ , Python, 1 line__init__.py - smallcap/
src/ , Python, 54 linesextract_features.py - smallcap/
src/ , Python, 165 linesget_indexed_caps.py - smallcap/
src/ , Python, 167 linesgpt2.py - smallcap/
src/ , Python, 696 linesopt.py - smallcap/
src/ , Python, 146 linesretrieve_caps.py - smallcap/
src/ , Python, 132 linesutils.py - smallcap/
src/ , Python, 562 linesvision_encoder_decoder.p y - smallcap/
src/ , Python, 269 linesxglm.py - utils.py, Python, 59 lines
- README.md, Text, 111 lines
Code availability statement
The paper has a code availability statement. Its license (CC BY-NC-ND) does not allow reproducing it here; in short, from what the harvester recognized in it:
- it points to the authors' code: JxuanC/
mental-representation-gu ided-learning
Read it in the paper: doi.org/10.1038/s41467-026-71267-5.
Tracing map
Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.
What the map holds:
- 1 repository of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
- 33 scripts, each with its path and the digest of its content;
- 7 matches between paragraphs of the paper and lines of the code (method lexical-v1);
- neither the text of the paper nor the code itself.
Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.
Data
Datasets cited
- figshare:7033577, at figshare; found in “Data availability”
- kaggle.com/
datasets/ , at Kaggle; found in the referencesawsaf49 - openneuro:ds001506, at OpenNeuro; found in “Data availability”
- osf:f5rn6, at OSF; found in “Data availability”
Data availability statement
The paper has a data availability statement. Its license (CC BY-NC-ND) does not allow reproducing it here; in short, from what the harvester recognized in it:
- it points to 3 datasets: figshare 7033577, OpenNeuro ds001506, OSF f5rn6
Read it in the paper: doi.org/10.1038/s41467-026-71267-5.
Versions
The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.
Version 1, 28 September 2026: the first record
Recorded: type, language, journal, volume, issue, pages, dates, 4 authors, 2 keywords, 8 MeSH terms, 2 funders, 25 references.
Cite
This paper
Chen, J., Qi, Y., Wang, Y., & Pan, G. (2026). Human-like cognitive generalization for large models via mental representation-guided supervision. Nature communications, 17(1), 4709. https://
BibTeX
@article{chen2026human,
author = {Chen, Jiaxuan and Qi, Yu and Wang, Yueming and Pan, Gang},
title = {{Human-like cognitive generalization for large models via mental representation-guided supervision}},
journal = {Nature communications},
year = {2026},
month = apr,
volume = {17},
number = {1},
pages = {4709},
publisher = {Nature Portfolio},
issn = {2041-1723},
doi = {10.1038/
url = {https://
pmid = {41922362},
pmcid = {PMC13212952}
}
RIS
TY - JOUR
AU - Chen, Jiaxuan
AU - Qi, Yu
AU - Wang, Yueming
AU - Pan, Gang
TI - Human-like cognitive generalization for large models via mental representation-guided supervision
T2 - Nature communications
J2 - Nat Commun
PY - 2026
DA - 2026/
VL - 17
IS - 1
SP - 4709
SN - 2041-1723
PB - Nature Portfolio
DO - 10.1038/
UR - https://
LA - en
ER -
CSL-JSON
{
"id": "10.1038/
"type": "article-journal",
"title": "Human-like cognitive generalization for large models via mental representation-guided supervision",
"container-title": "Nature communications",
"author": [
{
"family": "Chen",
"given": "Jiaxuan"
},
{
"family": "Qi",
"given": "Yu"
},
{
"family": "Wang",
"given": "Yueming"
},
{
"family": "Pan",
"given": "Gang"
}
],
"container-title-short":
"volume": "17",
"issue": "1",
"page": "4709",
"DOI": "10.1038/
"PMID": "41922362",
"PMCID": "PMC13212952",
"ISSN": "2041-1723",
"publisher": "Nature Portfolio",
"URL": "https://
"language": "en",
"issued": {
"date-parts": [
[
2026,
4,
1
]
]
}
}
The tracing map gets a citation of its own once an author has validated it and it has a DOI.
Similar papers
The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.
- [1] doi:10.1073/pnas.2512514122 [code]
- Revealing emergent human-like conceptual representations from language prediction.Journal: Proceedings of the National Academy of Sciences of the United States of AmericaIn common: Hugging Face Transformers, PyTorch, scikit-learn, 4 other tools, OSF f5rn6, cognitive, 7 references
- [2] doi:10.1038/s42003-026-09685-w [code]
- Achieving more human brain-like vision via human EEG representational alignment.Journal: Communications biologyIn common: Hugging Face Transformers, h5py, Pillow, 6 other tools, figshare 7033577, cognitive, 4 references
- [3] doi:10.1126/sciadv.adj3906 [code]
- Reconstructing visual illusory experiences from human brain activity.Journal: Science advancesIn common: scikit-image, h5py, Pillow, 6 other tools, OpenNeuro ds001506, 2 references
- [4] doi:10.3389/fnins.2021.795488 [code]
- Natural Image Reconstruction From fMRI Using Deep Learning: A Survey.Journal: Frontiers in neuroscienceIn common: h5py, Pillow, scikit-learn, 4 other tools, OpenNeuro ds001506, 4 references
- [5] doi:10.1038/s42003-021-02975-5 [code]
- Attention modulates neural representation to render reconstructions according to subjective appearance.Journal: Communications biologyIn common: scikit-image, h5py, Pillow, 5 other tools, OpenNeuro ds001506, cognitive, 2 references
- [6] doi:10.1016/j.neuroimage.2022.119754 [code]
- A large and rich EEG dataset for modeling human visual object recognition.Journal: NeuroImageIn common: Pillow, PyTorch, scikit-learn, 4 other tools, 7 references
- [7] doi:10.1038/s41467-026-69345-9 [code]
- A 7T fMRI dataset of synthetic images for out-of-distribution modeling of vision.Journal: Nature communicationsIn common: h5py, Pillow, PyTorch, 5 other tools, 6 references
- [8] doi:10.1038/s42003-026-10144-9 [code]
- Low-power differencing feature extracts spiking-band activities for high-performance intracortical brain-computer interfaces.Journal: Communications biologyIn common: PyTorch, scikit-learn, SciPy, 2 other tools, 2 authors
- [9] doi:10.1162/imag.a.1299 [code]
- A modular semantic-structural pipeline for visual decoding from primate spiking data via selective temporal integration.Journal: Imaging neuroscience (Cambridge, Mass.)In common: Hugging Face Transformers, scikit-image, h5py, 7 other tools, 3 references
- [10] doi:10.7554/elife.107933 [code]
- Modality-agnostic decoding of vision and language from fMRI.Journal: eLifeIn common: Hugging Face Transformers, scikit-image, h5py, 7 other tools, cognitive, 3 references
Contribute
The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.
Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.
Claim this paper
Correct its record
Say what each link of this record is, remove the ones that are not the paper's, add the ones that are missing. The correction becomes a new version of the record, in its Versions section.
Validate its tracing map
You validate the map as this page shows it: 1 repository of the authors' code, each at its verified commit and with its license, 33 scripts, and 7 matches between paragraphs and code (see the Code and Map sections). It then receives a DOI on Zenodo, with you (your ORCID iD) and OSCR as its creators; the code itself is not deposited.
The map's fingerprint: sha256:3fc1332c8509167e…
Add the badge to the code's README
If you are an author or a maintainer of this paper's code, you can add this badge. It says what OSCR knows of the paper (its code, its validated tracing map) and links the code to this page. Paste one of these snippets under the README's title. Keep the two marks around it, so that the badge can be replaced in place and is never added twice. OSCR changes nothing in your repository.
Markdown
<!-- oscr-badge:start -->
[](https://openscicode.org/badge/doi/10.1038/s41467-026-71267-5)
<!-- oscr-badge:end -->reStructuredText
.. oscr-badge:start
.. image:: https://openscicode.org/badge/doi/10.1038/s41467-026-71267-5.svg
:target: https://openscicode.org/badge/doi/10.1038/s41467-026-71267-5
:alt: OSCR
.. oscr-badge:endHTML
<!-- oscr-badge:start -->
<a href="https://openscicode.org/badge/doi/10.1038/s41467-026-71267-5"><img src="https://openscicode.org/badge/doi/10.1038/s41467-026-71267-5.svg" alt="OSCR"></a>
<!-- oscr-badge:end -->On GitHub, open the README, choose Edit (the pencil), paste the snippet under the title, then "Commit changes".
If you choose to, you can have the badge kept up to date for you, with oscr badge --write from the command line or with the GitHub Action in your repository's workflows. Every other form and option (a card, AsciiDoc, LaTeX, shields.io) is on the badge page.
Request its removal
To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).
Discussion, reproductions, activity
Discussion: code errors and mismatches between the code and the paper about this paper and its code, from readers and its authors, beside the paper and its tracing map.
Report a mismatch between the code and the paper · Report a code error (signed in)
Reproductions: reports from readers who ran the authors' code and did not get the paper's result, what they ran, with which environment, commit and data.
Report a reproduction failure (signed in)
Versions of its code: the releases of its code tied to a version of this paper (the preprint, the accepted manuscript, the version of record…), each with the tracing map versioned with it.
Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.
