AI Development
What this covers
Concepts, tools, and practical techniques for AI development: embeddings and vector search, key Python AI libraries, and core machine learning fundamentals. For building a full retrieval-augmented generation pipeline, see RAG; for local model serving, see Ollama; for connecting an AI assistant to external tools, see MCP; for wiring AI into a Drupal site, see AI in Drupal.
When to use it
- Choosing an embedding model or vector similarity metric for a semantic search feature
- Deciding between
transformersandsentence-transformers, or picking another Python AI library, for an NLP task - Picking a machine learning technique (regression, SVM, random forest, nearest neighbors) for a predictive-modeling task
AI Fundamentals
Vector Databases and Embeddings
Vector databases store high-dimensional vectors for efficient semantic searches. Unlike traditional keyword-based databases, they allow similarity searches using embeddings.
Key Concepts:
- Embeddings: Numerical representations of text, images, or audio in vector space.
- Semantic Search: Retrieves information based on meaning, not exact keywords.
- Vector Similarity Metrics: Cosine similarity, Euclidean distance, Manhattan distance.
Recommended Resources:
For building the retrieval and generation pipeline on top of these fundamentals, see RAG.
Python AI Libraries
Transformers Library
from transformers import AutoModel, AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("bert-base-uncased")
model = AutoModel.from_pretrained("bert-base-uncased")
inputs = tokenizer("Hello world", return_tensors="pt")
outputs = model(**inputs)
Transformers vs Sentence Transformers:
| Feature | transformers | sentence-transformers |
|---|---|---|
| Focus | General NLP tasks | Sentence/document embeddings |
| Output | Token embeddings, logits | Semantic embeddings ready for similarity search |
| Ease of use | Requires manual pooling for sentences | encode() method for direct vectors |
| Models | BERT, GPT, T5 | MiniLM, mpnet, etc. |
Other Libraries
- PyTorch: Neural networks
- NumPy / Pandas: Data handling
- Scikit-learn: ML algorithms
- PEFT: Efficient fine-tuning of LLMs
AI Implementation Best Practices
- Choose models suited to task and hardware.
- Decide local (Ollama) vs cloud-based deployment based on privacy and scalability.
- Use efficient embeddings for semantic search.
- Combine retrieval systems with generative models (RAG) for knowledge-intensive tasks.
- Monitor resource usage and optimize performance.
Machine Learning Fundamentals
Core Concepts:
- Bias-Variance Tradeoff: Balance simplicity and flexibility.
- Central Limit Theorem: Sample means converge to normal distribution.
- Law of Large Numbers: Larger datasets provide more reliable estimates.
Supervised Learning:
- Linear Regression: Predict continuous values.
- R-squared: Model fit metric.
- SVM: Optimal hyperplane classification.
Ensemble Methods:
- Random Forest: Reduces overfitting, handles missing data, provides feature importance.
Unsupervised Learning:
- Nearest Neighbors: Classifies based on similarity, sensitive to irrelevant features.
Neural Networks:
- Layered structure, learns patterns via backpropagation, foundation for deep learning.
Data Visualization:
- Seaborn: Advanced statistical plots, integrates with pandas.
Practical Applications:
- Predictive modeling (e.g., elections)
- Trend analysis from demographic or historical data