SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2207.11463 · ECCV · 2022

When Counting Meets HMER: Counting-Aware Network for Handwritten Mathematical Expression Recognition

Wenyu Liu, Ye Yuan, Bohan Li, Xiao Liu, Xiang Bai, Zhilong Ji, Jinfeng Bai, Dingkang Liang

arXiv · PDF · Open in the Atlas

Code that ran

5 of 6 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 5 have no contract verdict; 0 failures of our instrument; 1 no recorded run), measured 2026-11-22; repository links from the Papers with Code archive attributed under CC BY-SA, no affiliation; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2207.11463.json · badge: /api/ran/2207.11463.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
LBH1024/CAN canonical (classifier label)
classifier basis not recorded on the link
5 ran · 1 no recorded run
FunctionStatusWhere it lives
cal_score Ran
ran on a synthesized input
LBH1024/CAN/utils.py
code served (permissive licence) · get_code("02d543693c5cbc61")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned tuple, ndim 1, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import numpy as np

torch.manual_seed(0)

# Create small test tensors
batch_size = 2
seq_len = 4
vocab_size = 3

# word_probs: shape (batch_size, seq_len, vocab_size) - logits/probabilities
word_probs = torch.randn(batch_size, seq_len, vocab_size)

# word_label: shape (batch_size, seq_len) - integer labels
word_label = torch.randint(0, vocab_size, (batch_size, seq_len))

# mask: shape (batch_size, seq_len) - binary mask with float values
mask = torch.ones(batch_size, seq_len)
mask[0, 3] = 0  # Make one position masked out
mask[1, 2:] = 0  # Mask out some positions in second batch

ARGS = {
    "word_probs": word_probs,
    "word_label": word_label,
    "mask": mask,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple, ndim 1, dtype family float — a tuple output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
collate_fn Ran
ran on a synthesized input
LBH1024/CAN/dataset.py
code served (permissive licence) · get_code("9de8449fe1430ac2")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned tuple. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

torch.manual_seed(0)

# Create a batch of items where each item is a tuple of (image_tensor, label_tensor)
# Images: shape (channels, height, width)
# Labels: shape (sequence_length,)

batch_images = [
    (torch.randn(3, 8, 12), torch.randint(0, 100, (5,))),  # 3 channels, 8 height, 12 width, 5 label length
    (torch.randn(3, 6, 10), torch.randint(0, 100, (4,))),  # 3 channels, 6 height, 10 width, 4 label length
]

ARGS = {
    "batch_images": batch_images
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple — a tuple output has no array shape of its own; none is stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
gen_counting_label Ran
ran on a synthesized input
LBH1024/CAN/counting_utils.py
code served (permissive licence) · get_code("d60c6502d12a92c0")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Tensor, ndim 2, dtype family float, shape (2, 111) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

torch.manual_seed(0)

# Create labels tensor: batch_size=2, sequence_length=4
# Values should be valid label indices (0-110)
labels = torch.tensor([
    [2, 5, 10, 3],
    [7, 2, 15, 20]
], dtype=torch.long)

# channel: number of output channels (must be > max label index)
channel = 111

# tag: boolean flag that determines which indices to ignore
tag = True

ARGS = {
    "labels": labels,
    "channel": channel,
    "tag": tag
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 2, dtype family float, shape (2, 111) — shape (2, 111) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
get_crohme_dataset Ran
ran on a synthesized input
LBH1024/CAN/dataset.py
code served (permissive licence) · get_code("f00a1fbee53a83e2")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned tuple, ndim 1, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import pickle as pkl
import tempfile
import os

torch.manual_seed(0)

# Create temporary directory for test files
tmpdir = tempfile.mkdtemp()

# Create a minimal words file
words_file = os.path.join(tmpdir, 'words.txt')
with open(words_file, 'w') as f:
    f.write('a\n')
    f.write('b\n')
    f.write('c\n')
    f.write('eos\n')

# Create minimal image data (pickled dict)
train_images_file = os.path.join(tmpdir, 'train_images.pkl')
eval_images_file = os.path.join(tmpdir, 'eval_images.pkl')

# Create simple image tensors (height=32, width=64, stored as numpy arrays)
import numpy as np
train_images = {
    'img1': np.random.randint(0, 256, (32, 64), dtype=np.uint8),
    'img2': np.random.randint(0, 256, (32, 64), dtype=np.uint8),
}
eval_images = {
    'img3': np.random.randint(0, 256, (32, 64), dtype=np.uint8),
    'img4': np.random.randint(0, 256, (32, 64), dtype=np.uint8),
}

with open(train_images_file, 'wb') as f:
    pkl.dump(train_images, f)

with open(eval_images_file, 'wb') as f:
    pkl.dump(eval_images, f)

# Create label files
train_labels_file = os.path.join(tmpdir, 'train_labels.txt')
with open(train_labels_file, 'w') as f:
    f.write('img1 a b\n')
    f.write('img2 b c\n')

eval_labels_file = os.path.join(tmpdir, 'eval_labels.txt')
with open(eval_labels_file, 'w') as f:
    f.write('img3 a c\n')
    f.write('img4 b a\n')

# Create params dict
ARGS = {
    'params': {
        'word_path': words_file,
        'train_image_path': train_images_file,
        'train_label_path': train_labels_file,
        'eval_image_path': eval_images_file,
        'eval_label_path': eval_labels_file,
        'batch_size': 2,
        'workers': 0,
        'collate_fn': 'collate_fn',
    }
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple, ndim 1, dtype family float — a tuple output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
load_config Ran
ran on a synthesized input
LBH1024/CAN/utils.py
code served (permissive licence) · get_code("6f75ee616b44ea28")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned dict. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import tempfile
import os
import yaml

# Create a temporary YAML file with valid configuration
temp_dir = tempfile.mkdtemp()
yaml_path = os.path.join(temp_dir, 'config.yaml')

config_data = {
    'experiment': 'test_experiment',
    'train_image_path': '/path/to/train/images',
    'train_label_path': '/path/to/train/labels',
    'word_path': '/path/to/word/dict',
    'train_parts': 2,
    'valid_parts': 1,
    'valid_start': 0,
    'attention': {
        'word_conv_kernel': 3
    }
}

with open(yaml_path, 'w') as f:
    yaml.dump(config_data, f)

ARGS = {
    'yaml_path': yaml_path
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
yaml — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
save_checkpoint Not yet run
unverified (harvested, no recorded run)
LBH1024/CAN/utils.py
code served (permissive licence) · get_code("beb2b433b3cefd2f")
How it ran

no invocation recorded.

Also present in other papers' code

Of 6 samples lifted from this paper's linked repositories, 6 carry a function identity and 0 do not. Of the 6 distinct functions with an identity, 0 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 0 later) and 6 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-22.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

Recently, most handwritten mathematical expression recognition (HMER) methods adopt the encoder-decoder networks, which directly predict the markup sequences from formula images with the attention mechanism. However, such methods may fail to accurately read formulas with complicated structure or generate long markup sequences, as the attention results are often inaccurate due to the large variance of writing styles or spatial layouts. To alleviate this problem, we propose an unconventional network for HMER named Counting-Aware Network (CAN), which jointly optimizes two tasks: HMER and symbol counting. Specifically, we design a weakly-supervised counting module that can predict the number of each symbol class without the symbol-level position annotations, and then plug it into a typical attention-based encoderdecoder model for HMER. Experiments on the benchmark datasets for HMER validate that both joint optimization and counting results are beneficial for correcting the prediction errors of encoder-decoder models, and CAN consistently outperforms the state-of-the-art methods. In particular, compared with an encoder-decoder model for HMER, the extra time cost caused by the proposed counting module is marginal. The source code is available at https://github.com/LBH1024/CAN.

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2207.11463")
get_code_for_paper("2207.11463")
have("2207.11463")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2207.11463.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2207.11463.svg)](https://syntology.ai/paper/2207.11463)

Connect an agent — have() is free.