You are on page 1of 30

INTRODUCTION By: Ms.

Sarah Ahmed
TO Email id: sara.ahmed@nu.edu.pk
ssarahahmedd@gmail.com
PYTHON FOR AI
NOTE
Being disciplined shows self-respect and a commitment to your education.
If anything I've shared doesn't click, please feel free to ask! I'm always happy to
clarify and can be reached via email at sara.ahmed@nu.edu.pk
KEY TERMS
Packages:
Definition: A package is a collection of related files (code, data, configuration) that
are bundled together for distribution and reuse. It acts as a container for other
components like libraries and modules.
Example: NumPy, a package for scientific computing in Python, includes modules
for arrays, matrices, and random number generation.
Key points:
 Provide organization and ease of distribution for related code.
 Can include various components like libraries, modules, data files, and documentation.
 Often managed through package managers like pip.
KEY TERMS
KEY TERMS
Libraries:
Definition: A library is a collection of pre-written code that provides specific
functions and functionalities for developers to use in their programs. It acts as a
building block for higher-level applications.
Example: TensorFlow, a library for machine learning in Python, offers functions for
building and training neural networks.
Key points:
 Offer reusable code blocks for specific tasks.
 Improve development efficiency by avoiding writing common code from scratch.
 Can be included within packages or exist independently.
KEY TERMS
KEY TERMS

APIs (Application Programming Interfaces):


Definition: An API is a set of defined methods and protocols that allow different
software programs to communicate and exchange data. It acts as a bridge between
systems.
Example: The Google Maps API allows developers to integrate maps and directions
functionalities into their applications.
Key points:
 Define how programs interact and share data.
 Enable building applications on top of existing platforms and services.
 Can be internal (within a system) or external (exposed for other developers to use).
KEY TERMS:

Both pip and PyPI are essential parts of the Python package ecosystem, but they
serve different purposes:
PyPI (Python Package Index):
A repository containing thousands of open-source Python packages for various
tasks like data science, web development, machine learning, and more.
Think of it as a library or app store for Python code.
Packages are uploaded and maintained by individual developers or organizations.
Users can browse, search, and download packages from PyPI.
KEY TERMS:
pip (Package Installer for Python): Use pip if you're working with Python code and
need packages for scientific computing, data analysis, machine learning, or general
Python development.
A tool used to install, uninstall, and manage packages from PyPI.
Think of it as a package manager similar to apt in Linux or npm in JavaScript.
Allows you to specify packages by name and version, and pip takes care of
downloading, installing, and resolving dependencies.
Integrates with virtual environments to isolate project dependencies.
KEY TERMS:
Frameworks:
Definition: A structured and pre-written codebase that defines an overall application
architecture and provides specific functionality.
Think of it as: A blueprint for building an application within a specific architecture.
Examples: Django for web development, Flask for microservices, TensorFlow for
machine learning.
Key features:
 Define application structure and workflows.
 Come with ready-made components and functionalities.
WHEN TO USE:
Use packages for modularity and organizing related code.
Use libraries for specific functionalities within your projects.
Use frameworks for building entire applications within a pre-defined structure.
Use APIs for interacting with external programs or platforms.
SIMULATION VS
PROGRAMMING
Simulation: Focuses on modeling and understanding the behavior of a system or
process. It's about how things interact and change over time.
It's the entire experience of setting up the model, defining the parameters, and analyzing the
generated data. Think of it as the "experiment" conducted using the simulator.
Programming: Focuses on creating instructions for a computer to perform specific
tasks. It's about defining operations and algorithms to achieve a desired outcome.
Approach:
Simulation: Often uses mathematical models, equations, and rules to define the behavior
of individual elements and their interactions.
Programming: Uses code and data structures to define specific steps and procedures for
the computer to execute.
SIMULATOR
Simulator:
Refers to the tool or software used to run a simulation. It's the platform that
implements the model, defines the rules, and executes the interactions between
elements. Think of it as the "engine" driving the simulation.
Can be a specific program or a general-purpose platform. Examples include flight
simulators or traffic simulators
HOW DOES PYTHON HELP TO BUILD AI THINKING
HUMANLY, RATIONALLY, AND ACTING ACCORDINGLY?

Python plays a crucial role in the quest to build AI that thinks and acts like humans.
Here's how it contributes to each aspect:
Thinking Humanly:
Natural Language Processing (NLP): Python libraries like NLTK and spaCy facilitate
text analysis, sentiment detection, and dialogue generation, allowing AI to understand
and respond to human language nuances like context and emotions.
Machine Learning (ML): Libraries like scikit-learn and TensorFlow enable building
AI models that learn from vast amounts of data, mimicking human-like knowledge
acquisition and adaptation.
Symbolic AI: Libraries like PySymbolics allow manipulating symbols and building
knowledge graphs, essential for simulating human reasoning and inferential thinking.
HOW DOES PYTHON HELP TO BUILD AI THINKING
HUMANLY, RATIONALLY, AND ACTING
ACCORDINGLY?

Thinking Rationally:
Logic Programming: Package like PySWI-Prolog enable AI to express reasoning
rules and problem-solving strategies, promoting logical, deductive thinking.
SWI-Prolog is a free implementation of the programming language Prolog,
commonly used for semantic web applications.
Planning and Scheduling: Packages like PyPlanning and ai2 planning allow
building AI agents that make decisions and perform actions based on logical
constraints and goals, mimicking rational planning and execution.
Probabilistic Reasoning: Libraries like NumPy and SciPy enable building AI
models that reason with uncertainty and handle incomplete information, mimicking
human decision-making under limited knowledge.
HOW DOES PYTHON HELP TO BUILD AI THINKING
HUMANLY, RATIONALLY, AND ACTING
ACCORDINGLY?

Acting Humanly:
Computer Vision (CV): Libraries like OpenCV and PyTorch allow building AI
models that interpret visual information and extract meaning from images and
videos, simulating human visual perception.
Robotics: Libraries like Pyrobot and RobotPy enable programming robot
movements and interactions with the physical world, leading to AI that can act and
manipulate objects human-like.
Reinforcement Learning (RL): Libraries like Gym and Stable Baselines3 allow
building AI agents that learn through trial-and-error, gradually developing human-
like skills and strategies for achieving goals.
HOW DOES PYTHON HELP TO BUILD AI
THINKING HUMANLY, RATIONALLY,
AND ACTING ACCORDINGLY?
Acting Rationally:
Optimization: Libraries like SciPy and Optuna enable AI to find optimal solutions
to complex problems with numerous constraints, mimicking rational decision-
making and resource allocation.
Game Playing: Libraries like PySC2 and DeepMind Lab provide platforms for
building AI agents that learn to play games strategically, requiring rational planning
and action selection.
Agent Simulation: Libraries like Mesa and RLlib allow building and simulating
multi-agent systems, enabling the study of AI interactions and the emergence of
collective intelligence, promoting rational coordination and behavior.
PYTHON
Python is a high-level, general-purpose programming language.
Key Characteristics:
Readability: Python's syntax is remarkably clear and resembles natural English, making it easy to learn and
comprehend, even for those new to programming.
Versatility: Python empowers you to tackle a wide array of tasks across diverse fields, including:
 Web development: Build dynamic websites and web applications using frameworks like Django and Flask.
 Data science: Analyze and visualize data effectively with libraries like NumPy, Pandas, and Matplotlib.
 Machine learning: Develop intelligent systems capable of learning from data using libraries like
TensorFlow and scikit-learn.
 Automation: Streamline repetitive tasks and workflows, saving time and effort.
 Scientific computing: Perform complex mathematical computations and simulations.
PYTHON
Open-source and free: Python is freely available for anyone to use, modify, and
distribute, fostering a vibrant community of developers.
Extensive libraries and frameworks: Python boasts a rich ecosystem of pre-written
code modules that extend its functionality, saving you time and effort.
Cross-platform compatibility: Python code can run smoothly on
Windows, macOS, Linux, and even embedded systems, ensuring flexibility.
PYTHON DISTRIBUTIONS
Imagine them as pre-packaged bundles of the Python interpreter, essential libraries, and tools,
tailored for specific needs and purposes. They simplify setup and provide a ready-to-use environment
for developers. They also provide at least one integrated development environment (IDE).
Anaconda: Anaconda is a powerhouse for data science and scientific computing.
ActivePython: A commercial distribution focusing on security and stability, popular for enterprise
use.
Miniconda: A smaller version of Anaconda, ideal for lighter deployments or embedding Python in
other applications.
PyPy: A just-in-time (JIT) compiled Python interpreter offering faster execution speed compared to
the standard CPython interpreter.
MicroPython: Designed for running Python on microcontrollers and embedded systems.
Windows 10/11 built-in Python: A basic Python installation included in recent Windows versions.
PLATFORMS FOR PYTHON
CODING
Integrated Development Environments (IDEs)- are like all-in-one toolboxes for programmers,
combining various functionalities within a single, unified interface.
PyCharm: Powerful and feature-rich IDE with excellent Python support, code completion,
debugging, and project management tools. Excellent for professional development.
Visual Studio Code: Highly customizable and lightweight code editor with extensive Python
extensions for debugging, linting, and code completion. Offers great flexibility for individual
preferences.
Spyder: Open-source scientific Python IDE with integrated tools for data analysis, scientific
computing, and interactive coding. Ideal for data scientists and researchers.
Linting is the process of using a lint tool to automatically check source code for errors. A lint tool,
also known as a linter, is a basic static code analyzer.
PLATFORMS FOR PYTHON
CODING
Code Editors:
Sublime Text: Powerful and fast code editor with a minimalist interface and
extensive plugin ecosystem. Great for experienced developers who prefer
customization.
Atom: Open-source hackable editor with an extensive package manager offering
various Python features and functionalities. Popular choice for beginners and
intermediate users.
Vim: short for Vi IMproved, is a configurable text editor often used as a Python
development environment.
PLATFORMS FOR PYTHON
CODING
Online Platforms:
Repl.it: Online Python interpreter and coding environment.Perfect for quick
experimentation and learning the basics.
Google Colab: Free cloud-based Jupyter Notebook environment with pre-installed
libraries and GPUs for data science and machine learning projects. Ideal for
researchers and data enthusiasts.
Heroku: Cloud platform for deploying Python applications with one-click deploys
and automatic scaling. Ideal for web development and deploying projects online.
PYTHON LIBRARIES
•NumPy: Scientific computing library for advanced array manipulation, linear algebra, and
random number generation.
•pandas: Data analysis library for importing, processing, manipulating, and analyzing data in
various formats.
•Matplotlib and Seaborn: Data visualization libraries for creating various types of charts
and plots.
•Scikit-learn: Machine learning library for building and evaluating various machine learning
models.
•Beautiful Soup: Web scraping library for extracting data from HTML websites.
•Requests: HTTP library for making web requests and downloading content.
•Django and Flask: Web development frameworks for building web applications efficiently.
PYTHON FRAMEWORKS
Django: Full-stack web framework for building secure and scalable web
applications.
Flask: Lightweight web framework for building small to medium-sized web
applications rapidly.
Web2py: Rapid application development framework for building web applications
quickly and easily.
Kivy: Cross-platform framework for building desktop, mobile, and web applications
with a similar codebase.
PYTHON DEEP LEARNING
FRAMEWORKS
TensorFlow,
PyTorch,
 Keras
 Theano
When to use:
• Beginners: Keras or PyTorch are easier to learn with their concise APIs.
• Production deployment: TensorFlow has the most mature deployment tools and is widely used in real-world
applications.
• Research and experimentation: PyTorch's dynamic computation graph and flexibility make it ideal for
exploring new ideas.
• Scalability and large datasets: TensorFlow offers the best scalability and performance for demanding projects.
• Scientific computing: Theano might be a good choice for its research focus and fast computation.
OTHER FRAMEWORKS:

MXNet: Scalable and efficient framework favored for computer vision and natural
language processing.
Chainer: Flexible and easy-to-extend framework, popular among researchers for its
customizability.
CNTK: Microsoft's offering, known for its strong support for GPU acceleration.
PYTHON APIS
REST APIs: Popular API architecture focused on stateless HTTP requests and
responses with resources identified by URIs.
GraphQL: API query language that allows fetching specific data efficiently
without requiring pre-defined endpoints.
OpenAI API: Provides access to powerful language models like GPT-3 for
generating text, translating languages, and writing different kinds of creative content.
Twitter API: Allows access to Twitter data for analysis and research.
OPEN GOOGLECOLAB

You might also like