Posts

Showing posts from 2017

Building an AI chatbot (part 1)

Image
I am currently working on a personal assistant AI chatbot. https://github.com/luweizhang/ai-buddy-node Architecture: wit.ai Node.js (backend request hander) Python Flask (backend ai layer - TensorFlow, Keras, NLTK) PostgreSQL Hosted on Heroku For the chatbot, I will be using a retrieval based system.   I will have a database of possible responses.  A neural network will be trained to output the right response.  The inputs into the neural network will be the conversation context , user context , and the user response , the output will be the chat bot response.   Conversation context : history of the conversation User context : information about the user User response: most recent response from the user Here's a rough outline of the steps that need to be taken in order to build this AI. Step 1:  Set up a server on Heroku.   Step 2: Setup up page on Facebook and tie into webhook Step 3: Set up PostgreSQL database, and populate with p...

Recommendation system approaches with pyspark

I am currently exploring building recommendation systems using PySpark.  Spark is an in memory processing engine that allows for real time distributed computing. Different techniques for building a recommendation system: Similarity Approach Cosine Similarty Calculate the cosine angle between two feature vectors (such as # of times songs were listened to between two users) Jaccard Similarity / Index Compute the intersection over the union:  wiki Collaborative Filtering Approach Matrix Factorization Find two dense matrices (which represent latent features) that when multiplied together recreate the original sparse matrix K nearest neighbors find the k nearest vector points and use that to classify the new observation Setup Spark: import pyspark from pyspark.context import SparkContext from pyspark.ml.feature import HashingTF, IDF, Tokenizer from pyspark.sql.types import * from pyspark.sql import Row from sklearn.metrics.pairwise import cosine_simil...

grandmaster level chess AI using python - Part 3 - Some additional thoughts

Image
Architecture of a Chess AI (note: the writing below is mostly stream of consciousness and hasn't been revised yet) A pretty typical architecture for a game playing AI consists of two components, a heuristic algorithm  and tree search. The heuristic algorithm is basically the equivalent of human intuition.  Intuition is something that is learned from experience.  As we experience more of the world around us, we become wiser and learn to make quick and accurate judgment calls just from a few quick glances.  For example, a seasoned car mechanic can quickly diagnose whats wrong with a car after having inspected it for a few minutes. A seasoned VC investor can quickly identify good startups to invest in just by having a brief conversation with the founders.  If they have decades of experience, then they can quickly make these judgment calls although they may seem biased from an outsiders perspective. The tree search aspect of a game playing AI is the logical co...

grandmaster level chess AI using python - Part 2 (the code)

Image
In continuation of part 1, I will now building my chess AI in python.  As mentioned before, my goal is to create a chess AI at the Grandmaster level (elo > 2500) Here is the code for the chess AI. https://github.com/luweizhang/chess_ai Key components of the chess game / AI: Python Classes: ChessGame instantiates the chessboard and pieces keeps track of whose turn it is RulesEnforcer Logic for how all the pieces move, castling Makes sure you cant make illegal moves Used in the chess AI to generation possible positions ChessAi Tree generator generates the tree of position moves Position Evaluator evaluates the quality of chess positions Minimax Determines the optimum move from the chess tree ChessDB Opening database Explanation of the tree generator: The tree generator component of the chess AI generates the possible future board positions based on the possible moves that the pieces can make.  At any given position, there are o...

grandmaster level chess ai using python - Part 1: Outlining the Rough Design

Inspired by AlphaGo, I am starting to work on building a basic chess computer using Python. I will design this chess computer based off of first principles.  I will try not to consult any online guides.  I won't use any libraries and will only rely on basic data structures and algorithms to build it. The first iteration of this chess computer will work by brute force alongside a simple heuristic algorithm.  After the first iteration is complete, I will try to improve on it. My goal here is to create a grandmaster level chess ai (elo > 2500).  I think the key to creating a very strong chess ai is the combination of the tree search and the heuristic algorithm. Below is a rough outline of how I will design this engine.  This design will compute N moves into the future, and then use a simple scoring method to choose the best moves out of the future states. Chess set design A 2D 8x8 matrix to represent all the spaces on the chess board. letters ...

Best Resources for Machine Learning and AI

As I learn more about ML and AI, I will try to compile the best resources that I come across here. Machine Learning Theory: Andrew NG machine learning course https://www.coursera.org/learn/machine-learning comment: Andrew Ng is an excellent teacher and explains complicated machine learning concepts in a very simple way.  This course will teach the basics of machine learning including the core algorithms and the mathematics behind them.  This is an essential course for any person interested in machine learning. machine learning notes:  http://www.holehouse.org/mlclass/ comment: invaluable notes to complement Andrew Ng's machine learning course.  Refer to these to review what you learned in the video lectures Neural Networks and Artificial Intelligence: Coursera Deep Learning http://deeplearning.ai This course is amazing!  Another gem from Andrew Ng.  Gives you a comprehensive deep dive into neural networks. Backwards Propagatio...

Using sqldf and RPostgreSQL for data manipulation in R

In R, I prefer to use the sqldf library to manipulate data.  Sqldf allows me to use SQL syntax to directly query and manipulate dataframes.  It works by connecting to RDBMS of your choosing and using that to manipulate your dataframes. I personally like to use PostgreSQL with sqldf but you can use many others depending on what you are used to(mysql, sqlite, etc.) Below are instructions on how to configure sqldf using PostgreSQL: 1. Install PostgreSQL and setup on your computer. 2. Install RPostgreSQL and sqldf packages in R install.packages("RPostgreSQL") install.packages("sqldf") 3. Now you can directly query data frames in R!  Post in the comments if you run into any issues! library(RPostgreSQL) library(sqldf) options(sqldf.driver = "RPostgreSQL") options(sqldf.RPostgreSQL.user = "postgres", sqldf.RPostgreSQL.password = <your password here>, sqldf.RPostgreSQL.dbname = "postgres", sqldf.RPostgreSQL.hostname ...