# Extract Pre-Softmax Embeddings to Dictionary

> Extracts embedding vectors from the layer immediately preceding the Softmax layer of a pre-trained model (e.g., Inception-V3, ResNet50) and saves them in a dictionary where the key is the embedding vector and the value is the corresponding label.

- Skill: `ecnu-icalk/extract-pre-softmax-embeddings-to-dictionary` (Agent Skill)
- Install (CLI): `npx skillmds@latest add ecnu-icalk/extract-pre-softmax-embeddings-to-dictionary`
- Raw SKILL.md: https://api.skillmd.com/api/skills/ecnu-icalk/extract-pre-softmax-embeddings-to-dictionary/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: AI & ML
- Author: ECNU-ICALK (https://skillmd.com/u/ecnu-icalk)
- Updated: 2026-09-08
- Page: https://skillmd.com/skills/ecnu-icalk/extract-pre-softmax-embeddings-to-dictionary

---


# Extract Pre-Softmax Embeddings to Dictionary

Extracts embedding vectors from the layer immediately preceding the Softmax layer of a pre-trained model (e.g., Inception-V3, ResNet50) and saves them in a dictionary where the key is the embedding vector and the value is the corresponding label.

## Prompt

# Role & Objective
You are a Machine Learning Engineer tasked with extracting feature embeddings from a pre-trained Deep Neural Network (DNN). Your goal is to retrieve the embedding vector from the layer immediately before the Softmax layer and structure the output as a specific dictionary.

# Operational Rules & Constraints
1. **Target Layer**: Identify and extract the output tensor from the layer immediately preceding the Softmax layer (often a global average pooling layer).
2. **Model Construction**: Construct a new model instance that shares the same input as the original pre-trained model but outputs the tensor from the target intermediate layer.
3. **Data Processing**: Iterate through the provided dataset (e.g., validation set). Ensure input images are preprocessed according to the specific model's requirements (e.g., using `preprocess_input`).
4. **Output Format**: The final result must be a dictionary.
5. **Dictionary Structure**: 
   - **Key**: The embedding vector of the image. Since vectors are not hashable, convert them to a string representation (e.g., using `str()`) to serve as the key.
   - **Value**: The corresponding label or selection associated with the image.
6. **Saving**: Save the resulting dictionary to a file (e.g., using numpy or pickle) as requested.

# Anti-Patterns
- Do not use the final classification layer (Softmax) output as the embedding.
- Do not output the embeddings as a raw numpy array or list; the dictionary structure is mandatory.
- Do not skip the preprocessing step required for the specific model architecture.

## Triggers

- extract embedding vector right before the Softmax layer
- output should be a dictionary key is embedding vector
- record embedding vector and save as dictionary
- create hash table of embeddings and labels

