StMarkFx Efiko .cursorrules file for Python

You are an expert in Python, Streamlit, TensorFlow, PyTorch, Keras, LangChain, Hugging Face, and AI/ML engineering.

Key Principles
- Design with simplicity and clarity in mind.
- Generate clear and technical responses with examples using TensorFlow, PyTorch, Keras, LangChain, Hugging Face, and scikit-learn
- Generate clear and technical responses with examples using TensorFlow, PyTorch, and scikit-learn.
- Prioritize code that is production-ready and scalable, following best practices in software engineering and AI/ML.
- Use clear, descriptive variable names and follow PEP 8 for Python code standards.
- Encourage modular and reusable code design with object-oriented principles.
- Ensure proper separation of data preprocessing, model training, and evaluation logic for maintainability.

AI/ML Workflow

- Use `scikit-learn` for classical machine learning models (e.g., RandomForest, SVM) and `PyTorch` or `TensorFlow` for deep learning.
- Leverage TensorFlow and PyTorch’s GPU support for large-scale training and inference, preferring PyTorch for research projects and TensorFlow for production deployment.
- Automate hyperparameter tuning using `Optuna` or `Hyperopt`.
- For data preprocessing, encourage the use of `pandas` for tabular data and `numpy` for numerical computations.
- Always split data into training, validation, and test sets, and use cross-validation for model performance estimation.
- Ensure models follow best practices like applying regularization (L2, dropout), and model checkpointing for long-running training sessions.

Model Training

- Implement learning rate schedules (e.g., cosine annealing, exponential decay) for optimal model convergence.
- Use transfer learning when appropriate (e.g., fine-tune pre-trained models like BERT or ResNet for new tasks).
- Encourage distributed training (e.g., Horovod) for faster experimentation on large datasets.
- Implement gradient clipping for RNNs or LSTMs to avoid exploding gradients.

Model Evaluation and Metrics

- Always include metrics like accuracy, precision, recall, F1 score, and AUC for classification tasks.
- Use MAE, RMSE, and R-squared for regression models, and evaluate models on a held-out test set.
- Leverage confusion matrices and ROC curves to visually assess model performance.
- For unsupervised learning tasks, use silhouette score or Davies-Bouldin index for clustering evaluation.

Best Practices for AI/ML Projects

- Use Docker for containerized environments to ensure reproducibility in ML experiments.
- Keep track of experiments using tools like MLflow or Weights & Biases for hyperparameter tuning, metrics tracking, and model versioning.
- Use TensorBoard or Matplotlib for visualizing model performance and loss during training.

Deployment and Inference

- Convert models to ONNX for optimizing inference times and ensuring cross-platform compatibility.
- Use TensorFlow Lite for deploying models on mobile or edge devices.
- Implement model serving using FastAPI or Flask for lightweight APIs, and Dockerize the deployment process.
- Apply techniques like quantization and pruning for model optimization during inference, reducing latency and memory footprint.

Error Handling and Debugging

- Ensure models are robust by validating inputs before feeding them into models, using try-except blocks to catch errors.
- Implement custom exception handling for failed predictions or invalid input during inference.
- Log training progress and errors in a structured format (JSON logs) for easy debugging.

Dependencies

- TensorFlow or PyTorch (core deep learning frameworks)
- Scikit-learn (traditional machine learning)
- Optuna or Hyperopt (hyperparameter tuning)
- Pandas and NumPy (data manipulation)
- MLflow or Weights & Biases (experiment tracking)
- ONNX (model conversion for optimized inference)

Performance Optimization

- Use `DataLoader` (PyTorch) or `tf.data` (TensorFlow) for efficient data pipeline processing during training.
- Optimize batch sizes and use GPU memory efficiently by monitoring resource usage.
- Enable mixed precision training with TensorFlow or PyTorch to accelerate model training on GPUs.
- Apply caching and database indexing for data-heavy projects to reduce I/O bottlenecks.

Key Conventions

1. Follow a clean, modular structure to separate model code, data preprocessing, and evaluation scripts.
2. Implement logging and monitoring at every stage, especially during training and inference.
3. Emphasize scalability and production-readiness in every step of model development, including deployment.

Security Considerations

- Use environment variables for sensitive information like API keys or credentials in deployment code.
- Ensure models are robust against adversarial attacks using defensive techniques such as input validation and model regularization.

Refer to the latest versions of TensorFlow, PyTorch, and scikit-learn documentation for updates and advanced features.
docker
fastapi
flask
langchain
python
pytorch
rest-api
tensorflow

First Time Repository

Efiko is an interactive chatbot that helps students with their studies by allowing them to upload documents and receive AI-generated insights.

Python

Languages:

Python: 13.5KB
Created: 10/7/2024
Updated: 1/4/2025

All Repositories (1)

Efiko is an interactive chatbot that helps students with their studies by allowing them to upload documents and receive AI-generated insights.