Human-like cognitive generalization for large models via mental representation-guided supervision.
The 7 matches · 1 of them tie a paragraph to a whole file, not to 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–93 · score 0.78 · optimal transport plan, Sinkhorn algorithm, regularized OT, Wasserstein, iterative, matrix
- [2] § Methods › Architecture and optimization › Loss function ↔ modules/LSP/optimal_Transport.py, lines 4–93 · score 0.74 · Sinkhorn iterations, regularized OT, transport plan, cost matrix
- [3] § Methods › Datasets › fMRI data ↔ data/data_config.py, the whole file · a weak match · score 0.62 · ImageNet, fMRI, FFA, LOC, PPA, stimuli
- [4] § Methods › Architecture and optimization › Loss function ↔ modules/LSP/encoder.py, lines 30–127 · score 0.59 · fMRI encoders, cost matrix, kernel, OT, iterations, Loss
- [5] § Methods › Architecture and optimization › Model architecture ↔ modules/LSP/encoder.py, lines 30–127 · score 0.59 · Gumbel Softmax, GNN, sampler, scores, head, encoders
- [6] § Methods › Architecture and optimization › Loss function ↔ modules/LSP/GW_OT.py, lines 269–286 · score 0.53 · probability vectors, GW distance
- [7] § Methods › Mental representation-guided supervised learning › Correspondence construction via optimal transport (OT) ↔ modules/LSP/GW_OT.py, lines 8–19 · score 0.51 · cosine distance, cost matrix, OT, transport
Paper
Loaded from Europe PMC by your browser, not stored by OSCR: 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 Publishing Group},
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 Publishing Group
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 Publishing Group",
"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.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
- [2] 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
- [3] doi:10.1371/journal.pcbi.1014263 [code]
- MIRAGE: Robust multi-modal architectures translate fMRI-to-image models from vision to mental imagery.Journal: PLoS computational biologyIn common: Hugging Face Transformers, UMAP, scikit-image, 8 other tools, 1 reference
- [4] 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
- [5] doi:10.1038/s42003-026-10169-0 [code]
- Shared representations in brains and models reveal a two-route cortical organization during scene perception.Journal: Communications biologyIn common: Hugging Face Transformers, h5py, Pillow, 6 other tools, cognitive, 3 references
- [6] doi:10.1038/s41467-026-70536-7 [code]
- Cortical representation of multidimensional handwriting movement and implications for neuroprostheses.Journal: Nature communicationsIn common: PyTorch, scikit-learn, SciPy, 1 other tool, 2 authors
- [7] doi:10.21203/rs.3.rs-9676637/v1 [code]
- A Comprehensive Benchmarking of Spatial Deconvolution and Domain Detection Methods across Diverse Tissues and Spatial Transcriptomic TechnologiesJournal: Research Square (preprint)In common: PyTorch Geometric, UMAP, scikit-image, 8 other tools
- [8] doi:10.1038/s41593-026-02285-1 [code]
- Fixation duration on natural scenes is explained by memory encoding not processing demand.Journal: Nature neuroscienceIn common: scikit-image, h5py, Pillow, 6 other tools, cognitive, 2 references
- [9] doi:10.1007/s12021-026-09803-3 [code]
- NeuroFusion: A Unified Framework for Generalized Visual Stimulus Decoding from fMRI Across Datasets and Subjects.Journal: NeuroinformaticsIn common: scikit-image, h5py, Pillow, 6 other tools, 2 references
- [10] doi:10.1002/advs.202520220 [code]
- Learnable Diffusion Framework for Mouse V1 Neural Decoding.Journal: Advanced science (Weinheim, Baden-Wurttemberg, Germany)In common: UMAP, scikit-image, h5py, 7 other tools, 1 reference
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:03334cd685b21c93…
Add the badge to its README
The badge links the code to this page. Copy one of these into the README of the paper's code: only you decide where it goes, and nothing is changed for you.
Markdown
[, paste the snippet at the top, then “Commit changes…” and, to review it first, “Create a new branch and start a pull request”. You open the pull request; OSCR asks for no permission.
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: questions and error reports about this paper and its code, from signed-in readers and its authors. It opens with sign-in.
Reproductions: reports from readers who ran the authors' code: what they reproduced, with which environment, commit and data. It opens with sign-in.
Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.
