Transformer encoder architecture implementation
Use when when processing sequential spectroscopic data (1H NMR spectra) where both local chemical shift patterns and global spectral dependencies are needed for compound classification.From its SKILL.md
npx -y skills add HolobiomicsLab/asb-skill-collections --skill transformer-encoder-architecture-implementationAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 14 stars14 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its file declares
Copied from the file, not written here
The file declares its own license as CC-BY-4.0. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.
SKILL.md
6.8 KB, ~1.0k tokens by cl100k_base, as published. Nobody here has run it
Transformer Encoder Architecture Implementation
License: restricted — no clear open-source license detected for the underlying tool; verify licensing before commercial use or redistribution. <!-- asb-license-banner -->
Summary
Implement a multi-head Transformer encoder block that models global dependencies across sequences, integrated with CNN feature extraction to capture both local patterns and long-range spectral relationships in 1H NMR data. This hybrid approach enables compound identification in complex mixtures by fusing local convolutional features with attention-based global context.
When to use
When processing sequential spectroscopic data (1H NMR spectra) where both local chemical shift patterns and global spectral dependencies are needed for compound classification. Apply this skill when your input is a time-series or spectral tensor where convolutional layers alone cannot capture inter-peak relationships across the entire spectrum.
When NOT to use
- Input is already a pre-computed feature table or embedding; use the encoder only when raw or lightly-preprocessed spectral tensors are available.
- Task requires only local pattern detection without global context; a CNN-only architecture may be more efficient.
- Computational resources are severely constrained; Transformer components add quadratic complexity in sequence length.
Inputs
- 1H NMR spectral tensors (shape: [batch_size, sequence_length, channels])
- Pre-normalized or preprocessed NMR spectra in tensor format
Outputs
- Encoded spectral representations from the hybrid CNN-Transformer module
- Feature vectors compatible with bi-encoder and cross-encoder heads for compound identification
How to apply
First, define a CNN feature extractor using convolutional layers to capture local patterns in 1H NMR spectra. Then, implement a multi-head Transformer encoder block that processes the CNN-extracted features to model global dependencies across the spectral sequence. Integrate both components into a unified hybrid encoder module with appropriate feature fusion points, ensuring the output representations are compatible with downstream classification heads (bi-encoder and cross-encoder). Verify the module accepts 1H NMR spectral tensors as input and outputs encoded representations with dimensions suitable for similarity matching and compound identification tasks.
Related tools
- PyTorch (Deep learning framework for implementing multi-head Transformer encoder blocks and CNN layers)
- Python (Programming language for building and training the hybrid architecture)
- Anaconda (Environment manager for dependency isolation and reproducibility) — https://www.anaconda.com/
- FlavorFormer (Reference implementation combining CNN-Transformer hybrid encoder with bi-encoder/cross-encoder for compound identification) — https://github.com/yfWang01/FlavorFormer
Evaluation signals
- The encoder module accepts 1H NMR spectral tensors and produces output tensors with consistent, expected dimensions for downstream heads.
- Attention weights from the multi-head Transformer can be visualized and show meaningful spectral peak relationships (e.g., peaks at similar chemical shifts or coupled spin systems receive high attention).
- Encoded representations from the hybrid module are distinguishable between different compounds and mixture compositions when measured by cosine similarity or contrastive loss.
- The module integrates seamlessly with bi-encoder and cross-encoder heads without shape mismatches or gradient flow disruptions during backpropagation.
- Compound identification accuracy on held-out NMR mixture spectra meets or exceeds baseline CNN-only or Transformer-only models.
Limitations
- Identifying components in mixtures using NMR spectra remains inherently challenging due to spectral overlap and peak congestion in complex samples.
- Computational cost scales quadratically with spectral sequence length; very long spectra may require dimensionality reduction or windowing strategies.
- Hybrid architecture requires careful tuning of fusion points and feature alignment between CNN and Transformer components; misalignment can degrade performance.
- Performance depends on data availability; the FlavorFormer implementation uses paired NMR spectra and compound labels, which may be limited for novel compounds or rare mixtures.
Evidence
- [other] hybrid CNN and Transformer architecture that captures both local features and global dependencies from 1H NMR spectra as inputs to enable compound identification in flavor mixtures: "FlavorFormer uses a hybrid CNN and Transformer architecture that captures both local features and global dependencies from 1H NMR spectra as inputs to enable compound identification in flavor"
- [other] CNN feature extractor and multi-head Transformer encoder integration workflow: "1. Define a CNN feature extractor using convolutional layers to capture local patterns in 1H NMR spectra. 2. Implement a multi-head Transformer encoder block to model global dependencies across the"
- [readme] incorporation of hybrid CNN and Transformer architecture in FlavorFormer: "incorporating a hybrid CNN and Transformer architecture to capture both local features and global dependencies from 1H NMR spectra"
- [readme] combination of bi-encoder and cross-encoder for compound identification: "leverages a combination of a bi-encoder and cross-encoder, a fusion pooling strategy, and a weighted loss function to identify compounds correctly"
- [readme] PyTorch and Python version specifications: "Python 3.13.2 and Pytorch (version 2.7.0+cu118)"
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.