SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2207.05289 · 2022

PLM-ICD: Automatic ICD Coding with Pretrained Language Models

arXiv · PDF · Open in the Atlas

Code that ran

9 of 11 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 9 have no contract verdict; 0 failures of our instrument; 2 no recorded run), measured 2026-11-23; 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.05289.json · badge: /api/ran/2207.05289.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
miulab/plm-icd canonical (classifier label)
classifier basis not recorded on the link
2 ran · 1 no recorded run
innerNULL/PLM-ICD-multi-label-classifier community (classifier label)
classifier basis not recorded on the link
7 ran · 1 no recorded run
FunctionStatusWhere it lives
all_macro Ran
ran on a synthesized input
miulab/plm-icd/src/evaluation.py
code served (permissive licence) · get_code("31705066a68f09b9")
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 numpy as np

# Create sample binary predictions and ground truth labels
# yhat and y should be 2D arrays of binary values (0 or 1)
# Shape: (num_samples, num_classes)
np.random.seed(0)

yhat = np.array([
    [1, 0, 1, 0],
    [1, 1, 0, 1]
], dtype=int)

y = np.array([
    [1, 0, 0, 1],
    [1, 1, 1, 0]
], dtype=int)

ARGS = {
    "yhat": yhat,
    "y": y
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy — 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
all_metrics Ran
ran on a synthesized input
miulab/plm-icd/src/evaluation.py
code served (permissive licence) · get_code("8395cbccd644787f")
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 numpy as np

# Create small binary prediction matrices and ground truth matrices
# The function expects 2D binary arrays where:
# - rows are samples
# - columns are labels/classes

np.random.seed(0)

# Create sample data: 5 samples, 3 labels
num_samples = 5
num_labels = 3

# Binary predictions (0 or 1)
yhat = np.random.randint(0, 2, size=(num_samples, num_labels))

# Ground truth binary labels
y = np.random.randint(0, 2, size=(num_samples, num_labels))

# Prediction scores (floats between 0 and 1) for raw predictions
yhat_raw = np.random.rand(num_samples, num_labels)

# Ensure at least some positive labels for AUC computation
y[0, 0] = 1
y[1, 1] = 1
y[2, 2] = 1

ARGS = {
    'yhat': yhat,
    'y': y,
    'k': 2,
    'yhat_raw': yhat_raw,
    'calc_auc': True
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, sklearn — 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
bce_with_logits Ran
ran on a synthesized input
innerNULL/PLM-ICD-multi-label-classifier/src/plm_icd_multi_label_classifier/loss.py
code served (permissive licence) · get_code("508a7ef7c9efe649")
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 0, dtype family float, shape () 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
from torch import FloatTensor

torch.manual_seed(0)

# Create small tensors for the function
batch_size = 2
num_classes = 4

# logits: shape (batch_size, num_classes) - raw model outputs
logits = torch.randn(batch_size, num_classes, dtype=torch.float32)

# label_one_hot: shape (batch_size, num_classes) - one-hot encoded labels
label_one_hot = torch.zeros(batch_size, num_classes, dtype=torch.float32)
label_one_hot[0, 1] = 1.0
label_one_hot[1, 3] = 1.0

# bias: small float value to avoid log(0)
bias = 1e-10

ARGS = {
    "logits": logits,
    "label_one_hot": label_one_hot,
    "bias": bias,
}
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 0, dtype family float, shape () — shape () 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
focal_loss_with_logits Ran
ran on a synthesized input
innerNULL/PLM-ICD-multi-label-classifier/src/plm_icd_multi_label_classifier/loss.py
code served (permissive licence) · get_code("8498513641388fa5")
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 0, dtype family float, shape () 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)

# Construct valid arguments for focal_loss_with_logits
batch_size = 2
num_classes = 4

# Create logits tensor: shape (batch_size, num_classes)
logits = torch.randn(batch_size, num_classes, dtype=torch.float32)

# Create one-hot encoded labels: shape (batch_size, num_classes)
label_one_hot = torch.zeros(batch_size, num_classes, dtype=torch.float32)
label_one_hot[0, 0] = 1.0
label_one_hot[1, 2] = 1.0

# Optional alpha parameter for class weighting
alpha = 0.25

# Gamma parameter for focal term
gamma = 2.0

ARGS = {
    "logits": logits,
    "label_one_hot": label_one_hot,
    "alpha": alpha,
    "gamma": gamma
}
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 0, dtype family float, shape () — shape () 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
loss_factory Ran
ran on a synthesized input
innerNULL/PLM-ICD-multi-label-classifier/src/plm_icd_multi_label_classifier/loss.py
code served (permissive licence) · get_code("cf4a0ac446573d79")
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 function. 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
import torch.nn.functional as F

torch.manual_seed(0)

# Create a small config dict for loss_factory
configs = {
    'name': 'focal_loss',
    'alpha': 0.25,
    'gamma': 2.0
}

ARGS = {
    'configs': configs
}
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 function — a function output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a function 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
metrics_func Ran
ran on a synthesized input
innerNULL/PLM-ICD-multi-label-classifier/src/plm_icd_multi_label_classifier/metrics.py
code served (permissive licence) · get_code("6ed591738a7f905e")
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 torch

torch.manual_seed(0)

# Create small one-hot encoded tensors
# Shape: (batch_size=2, num_classes=4)
# These represent predictions and labels in one-hot format

# Predictions: 2 samples, 4 classes
preds_one_hot = torch.tensor([
    [1, 0, 1, 0],
    [0, 1, 0, 1]
], dtype=torch.int64)

# Labels: 2 samples, 4 classes
label_one_hot = torch.tensor([
    [1, 0, 1, 0],
    [0, 1, 1, 0]
], dtype=torch.int64)

# Bias parameter (default is 1e-06)
bias = 1e-06

ARGS = {
    "preds_one_hot": preds_one_hot,
    "label_one_hot": label_one_hot,
    "bias": bias
}
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 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
token_ids_chunking Ran
ran on a synthesized input
innerNULL/PLM-ICD-multi-label-classifier/src/plm_icd_multi_label_classifier/text.py
code served (permissive licence) · get_code("defb98c128a84614")
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 3, dtype family int; 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

# Examine the function signature and body:
# - text_ids: List[int] - a list of token IDs
# - attn_marks: List[int] - a list of attention marks (same length as text_ids)
# - chunk_size: int - size of each chunk
# - chunk_num: int - number of chunks
# - padding_idx: int - padding token ID
# - check: bool - whether to perform assertions

# The function pads text_ids and attn_marks to total_token_num = chunk_num * chunk_size
# Then splits them into chunks of size chunk_size

# Construct valid arguments
ARGS = {
    "text_ids": [101, 2054, 2003, 102],  # Small list of token IDs (4 tokens)
    "attn_marks": [1, 1, 1, 1],  # Attention marks for each token (4 marks)
    "chunk_size": 3,  # Each chunk will have 3 tokens
    "chunk_num": 2,  # We want 2 chunks total (total 6 tokens)
    "padding_idx": 0,  # Padding token ID
    "check": True,  # Enable checking
}
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 3, dtype family int — 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
tokenize_to_chunks Ran
ran on a synthesized input
innerNULL/PLM-ICD-multi-label-classifier/src/plm_icd_multi_label_classifier/text.py
code served (permissive licence) · get_code("c0e60fa6f11e5f1f")
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 3, dtype family int; 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.

from typing import Dict, List, Tuple
from transformers import AutoTokenizer

# Create a minimal mock tokenizer that behaves like AutoTokenizer
class MockTokenizer:
    def __init__(self):
        self.pad_token = "[PAD]"
    
    def __call__(self, text, padding=False, truncation=False):
        # Simulate tokenization output
        # Return a dict with input_ids and attention_mask
        if isinstance(text, str):
            # Simple mock: assign token ids based on text length
            token_ids = [101] + [i + 1000 for i in range(len(text.split()))] + [102]
            attention_mask = [1] * len(token_ids)
        else:
            token_ids = [101, 102]
            attention_mask = [1, 1]
        
        return {
            'input_ids': token_ids,
            'attention_mask': attention_mask
        }

# Set up the mock tokenizer
mock_tokenizer = MockTokenizer()

# Define the arguments dict for tokenize_to_chunks
ARGS = {
    'text': "Hello world this is a test",
    'tokenizer': mock_tokenizer,
    'chunk_size': 8,
    'chunk_num': 3
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
transformers — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple, ndim 3, dtype family int — 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
topk_metrics_func Ran
ran on a synthesized input
innerNULL/PLM-ICD-multi-label-classifier/src/plm_icd_multi_label_classifier/metrics.py
code served (permissive licence) · get_code("4198b53dcff76317")
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 torch

torch.manual_seed(0)

# Create small test tensors
# logits: FloatTensor of shape (batch_size, num_labels)
# label_one_hot: IntTensor of shape (batch_size, num_labels)
batch_size = 2
num_labels = 4

logits = torch.randn(batch_size, num_labels, dtype=torch.float32)
label_one_hot = torch.tensor([
    [1, 0, 1, 0],
    [0, 1, 1, 0]
], dtype=torch.int32)

top_k = 2
bias = 1e-06

ARGS = {
    'logits': logits,
    'label_one_hot': label_one_hot,
    'top_k': top_k,
    'bias': bias
}
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 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
all_micro Not yet run
unverified (harvested, no recorded run)
miulab/plm-icd/src/evaluation.py
code served (permissive licence) · get_code("6270d9b8cb7698a3")
How it ran

no invocation recorded.

json2limited_json Not yet run
unverified (harvested, no recorded run)
innerNULL/PLM-ICD-multi-label-classifier/bin/etl/etl_jsonl2limited_jsonl.py
code served (permissive licence) · get_code("6c608b8b4c90f237")
How it ran

no invocation recorded.

Also present in other papers' code

Of 11 samples lifted from this paper's linked repositories, 11 carry a function identity and 0 do not. Of the 11 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 11 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-23.

Repositories linked to this paper

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

Abstract

Automatically classifying electronic health records (EHRs) into diagnostic codes has been challenging to the NLP community. State-of-the-art methods treated this problem as a multilabel classification problem and proposed various architectures to model this problem. However, these systems did not leverage the superb performance of pretrained language models, which achieved superb performance on natural language understanding tasks. Prior work has shown that pretrained language models underperformed on this task with the regular finetuning scheme. Therefore, this paper aims at analyzing the causes of the underperformance and developing a framework for automatic ICD coding with pretrained language models. We spotted three main issues through the experiments: 1) large label space, 2) long input sequences, and 3) domain mismatch between pretraining and fine-tuning. We propose PLMICD, a framework that tackles the challenges with various strategies. The experimental results show that our proposed framework can overcome the challenges and achieves state-of-the-art performance in terms of multiple metrics on the benchmark MIMIC data. The source code is available at https://github.com/MiuLab/PLM-ICD

For agents

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

get_harvested_code_for_paper("2207.05289")
get_code_for_paper("2207.05289")
have("2207.05289")

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

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

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

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

Connect an agent — have() is free.