tensorflow-deep-learning — Cursor rule for TensorFlow models
This rule guides Cursor through TensorFlow project structure, data checks, model training, evaluation, and export. Use it when you want these practices applied to your Python files and notebooks.
.cursor/rules/tensorflow-deep-learning.mdcWhat tensorflow-deep-learning does
The rule targets *.py, *.ipynb, pyproject.toml, requirements*.txt, and environment*.yml. It recommends keeping data loading, model code, training, and evaluation in separate parts of a project. For input processing, it points to tf.data; repeatable notebook work belongs in modules, while model settings can live in typed configs.
Before training, check tensor shapes and types, label ranges, and class balance. The rule calls for splitting data before augmentation or fitting normalization, then using validation data for tuning and a separate test set for final results. This separation helps prevent leakage. Choose metrics that fit the task, and save the checkpoint with the strongest validation score rather than the last epoch.
For serving, keep preprocessing aligned with training, export a clear input signature, and smoke-test the saved model on sample inputs. The rule also calls for tracking latency, memory, and prediction drift. Mixed precision should wait until numerical stability has been checked; GPU runs may remain nondeterministic.
What it helps with
- separate data loading, training, and evaluation code
- check labels and class balance before fitting a model
- prevent validation leakage during preprocessing
- select a checkpoint by validation performance
- smoke-test an exported model on sample inputs
Example prompts for the agent
- Review this TensorFlow pipeline for data leakage between training and validation.
- Move repeatable training code out of the notebook and into project modules.
- Prepare the exported model with an input signature and a sample inference test.
How to install tensorflow-deep-learning
Manually: put the files in place
.cursor/rules/tensorflow-deep-learning.mdcFrontmatter: description, globs, alwaysApply
Manually: put the files in place
.claude/rules/tensorflow-deep-learning.mdThe paths frontmatter field limits the files: move globs from the source into paths
AGENTS.md
Codex reads AGENTS.md: paste the rule text there
Manually: put the files in place
.github/instructions/tensorflow-deep-learning.instructions.mdThe applyTo field sets which files it applies to: move globs from the source into applyTo
Manually: put the files in place
.devin/rules/tensorflow-deep-learning.mdManually: put the files in place
.clinerules/tensorflow-deep-learning.mdStep by step, with commands for each platform: Cursor rules: .mdc files, four modes and what replaced .cursorrules
Questions about tensorflow-deep-learning
How do I install tensorflow-deep-learning in Cursor?
Add the rule file at .cursor/rules/tensorflow-deep-learning.mdc.
What does tensorflow-deep-learning do?
It gives Cursor guidance for structuring TensorFlow projects, checking datasets, training and evaluating models, and preparing exports for inference.
How does the rule address data leakage?
It recommends splitting the dataset before augmentation or fitting normalization, and keeping the test set separate from validation used for tuning.
Source text
tensorflow-deep-learning.mdc · CC0-1.0
--- description: TensorFlow and deep learning rules for building, training, evaluating, and deploying neural network models globs: ["**/*.py", "**/*.ipynb", "pyproject.toml", "requirements*.txt", "environment*.yml"] alwaysApply: false --- # TensorFlow and Deep Learning Rules ## Project Structure - Separate data loading, model definition, training, evaluation, and serving code. - Use `tf.data` pipelines for scalable input processing. - Keep model hyperparameters in typed config files or dataclasses. - Store checkpoints, logs, and exported models outside source directories. - Keep notebooks exploratory; move repeatable training code into modules. ## Model Development - Start with a small baseline model and a tiny overfit test before scaling. - Use Keras layers and models unless lower-level TensorFlow APIs are required. - Prefer explicit input shapes and named inputs/outputs. - Use callbacks for checkpointing, early stopping, learning-rate scheduling, and TensorBoard logging. - Use mixed precision only after validating numerical stability. - Pin random seeds where reproducibility matters, while documenting nondeterministic GPU behavior. ## Training - Validate data shapes, dtypes, label ranges, and class balance before training. - Split data before augmentation or normalization fitting. - Use validation data for tuning and a separate test set for final reporting. - Track loss curves, metrics, learning rate, and resource use. - Save the best checkpoint by validation metric, not by final epoch. ## Evaluation - Report task-appropriate metrics such as AUROC, F1, calibration, perplexity, BLEU/ROUGE, or MAE/RMSE. - Include confusion matrices or error slices for classification tasks. - Evaluate on edge cases and distribution shifts when data allows. - Compare against non-neural baselines when the dataset is small or tabular. ## Deployment - Export models with clear input signatures. - Keep preprocessing consistent between training and serving. - Add smoke tests that load the exported model and run inference on sample inputs. - Monitor latency, memory, prediction drift, and input schema changes. ## Common Mistakes - Do not tune architecture before verifying labels and data quality. - Do not leak validation data through preprocessing or augmentation. - Do not rely on accuracy alone for imbalanced data. - Do not deploy a notebook-only model. - Do not ignore batch size, dtype, and device differences between training and inference.
© PatrickJS · CC0-1.0 · PatrickJS/awesome-cursorrules