Skip to content

TabishShahMohsin/CS50AI

Repository files navigation

CS50AI Projects Repository

This repository contains the code and problem sets from the Harvard CS50 Artificial Intelligence course (CS50AI). Each folder is a self-contained project implementing foundational AI concepts and algorithms in Python, ranging from logic and inference to deep learning and NLP.

Below is a guide to each project: what it does, what topics it covers, and how you can run or use the code yourself.


Contents


Crossword (Constraint Satisfaction)

  • Concepts: Constraint Satisfaction Problem (CSP), AC-3 arc consistency, backtracking search, domain heuristics.
  • Description: Generates and solves crossword puzzles by modeling empty slots as variables and filling in words under length, overlap, and uniqueness constraints. Implements variable selection and ordering heuristics for efficient solving.
  • Run:
    python crossword/generate.py [structure.txt] [words.txt] [outputfile]
    You provide a board structure and word list, and the solver fills the crossword, optionally saving the solution as an image if [outputfile] is provided.

Minesweeper (Logical Inference)

  • Concepts: Knowledge bases, propositional inference.
  • Description: An AI agent maintains a set of logical sentences about the state of the game, inferring which squares are safe or contain mines based on known information and deductive logic.
  • Run:
    • Text version and Pygame version included.
    • For GUI, run:
      python minesweeper/runner.py
    Play manually or let the AI make moves.

Degrees (Graph Search)

  • Concepts: Breadth-First Search (BFS), shortest paths in graphs.
  • Description: Models connections between actors in films as a graph, then computes degrees of separation and shortest connection paths between actors.
  • Run:
    python degrees/degrees.py [directory]
    On startup, it loads the data and asks for two actors' names, outputting the sequence of starring roles that link them.

Tic-Tac-Toe (Minimax)

  • Concepts: Minimax algorithm, adversarial search, game AI.
  • Description: AI plays Tic-Tac-Toe optimally by building a game tree and recursively choosing moves that maximize the chance of winning or minimize loss/draw.
  • Run: Run the main Python file in the tictactoe folder (python tictactoe/tictactoe.py). The AI will play against a human or itself.

Heredity (Bayesian Networks)

  • Concepts: Conditional/joint probability, Bayesian inference, genetic inheritance, mutation probabilities.
  • Description: Models family genetic data using Bayesian networks and computes probabilities of having a gene or trait via recursive enumeration of all possible scenarios.
  • Run:
    python heredity/heredity.py [data.csv]
    Provide a CSV with family data; outputs probabilities for each person.

PageRank (Markov Chains)

  • Concepts: Markov chains, stochastic processes, iterative convergence.
  • Description: Computes PageRank scores for a set of webpages using both sampling (random walks) and iterative update methods. Demonstrates the mathematical process underlying Google's original ranking algorithm.
  • Run:
    python pagerank/pagerank.py [corpus_folder]
    Point to a folder of HTML files; outputs estimated PageRank for each file.

Shopping (Machine Learning)

  • Concepts: K-Nearest Neighbors (KNN) classifier, train/test split, feature engineering, model evaluation (sensitivity and specificity).
  • Description: Uses session data from an e-commerce site to predict if a visitor will generate revenue, with the data loaded from CSV and split for training/test.
  • Run:
    python shopping/shopping.py [data.csv]
    Outputs classification results and performance metrics.

Nim (Reinforcement Learning)

  • Concepts: Q-learning, temporal-difference updates, epsilon-greedy, self-play agent training.
  • Description: Implements an agent that learns optimal strategies for the game of Nim through repeated self-play using Q-learning, then allows you to play against the trained AI.
  • Run:
    python nim/play.py
    The code first trains the AI for 10,000 games, then lets you play as human.

Parser (Context-Free Grammar)

  • Concepts: NLTK grammar parsing, context-free grammars (CFG), parse trees, phrase chunking.
  • Description: Uses NLTK to parse sentences according to a custom CFG, printing the parse tree(s) and extracting all noun phrases in the sentence.
  • Run:
    python parser/parser.py [sentence or input file]
    If no file is given, type a sentence at the prompt.

Traffic (Deep Learning and CNNs)

  • Concepts: Convolutional Neural Networks (CNN), TensorFlow, Keras, multiclass image classification.
  • Description: Trains various CNN models to recognize traffic signs from images, documents model architectures and their accuracy in traffic/README.md.
  • Run:
    python traffic/traffic.py [data_directory] [model_output_file]
    • Place images in category-labeled folders, and optionally save the trained network.
    • Example model summaries and experimental details are in the README for model performance, design choices, and layer specifics.

Attention (Neural Machine Translation)

  • Concepts: Transformers, masked language models (BERT), attention visualization.
  • Description: Implements a BERT-based masked language model using TensorFlow and Huggingface Transformers. Visualizes attention weights over tokens, showing which words the model focuses on to predict missing words.
  • Run:
    python attention/mask.py
    • Enter text with the [MASK] token to see predictions and attention diagrams.
    • Requires Huggingface Transformers, TensorFlow, and PIL for visualizing attention heads.

Dependencies & Setup

  • Most projects assume Python 3.x and use pip packages such as scikit-learn (shopping), TensorFlow/Keras (traffic, attention), NLTK (parser), and pygame (minesweeper runner GUI).
  • You may need to install project-specific packages:
    pip install -r requirements.txt
    or install the relevant library for each folder.

Attribution and License

This repo provides educational implementations of the official CS50AI assignments. Code and design inspired by Harvard's CS50AI course (cs50.harvard.edu/ai), provided here for study and extension.


Explore

Open any project folder for the main Python files, supporting data, and code comments. Many projects come with their sample datasets or structures for ease of experimentation.

Feel free to use, experiment, and learn AI from real, working code!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors