This repository contains a C-based library built from scratch, designed to handle essential mathematical functions and operations for AI, machine learning, deep learning (CNN), and natural language processing (NLP) projects. The library provides implementations of matrix operations, activation functions, loss functions, neural network components, convolution layers, NLP utilities, and optimizers. It aims to offer an in-depth understanding of the core mechanics underlying popular AI libraries like TensorFlow and PyTorch.
This project is divided into multiple stages, beginning with basic mathematical operations and progressing through more advanced deep learning algorithms, including convolutional neural networks (CNNs) and natural language processing (NLP) models. The library serves as both a learning tool and a robust foundational library that can be extended for more complex projects.
At the foundation of AI and machine learning are matrix and vector computations. These functions allow for basic manipulations that are critical in implementing AI algorithms.
- Functions Included:
create_matrix,add_matrices,multiply_matrices,transpose_matrixdot_product,scalar_multiply_vector,scalar_multiply_matrix
Activation functions introduce non-linearity to neural networks, while loss functions calculate errors that guide the learning process.
- Activation Functions:
sigmoid,relu,tanh,softmax - Loss Functions:
mean_squared_error,binary_cross_entropy,categorical_cross_entropy
These functions are the building blocks for implementing custom neural networks from scratch.
- Functions Included:
dense_layer_forward,dense_layer_backwardgradient_descent_optimizer,sgd_optimizer
This stage introduces deep learning concepts, including Convolutional Neural Networks (CNN) and Recurrent Neural Networks (RNN).
-
Convolutional Neural Network (CNN) Functions:
convolution2d,max_pooling2d,average_pooling2drelu_activation,flatten,batch_normalization_cnn
-
Recurrent Neural Network (RNN) Functions:
forward_rnn,backpropagate_rnngenerate_text_rnn
This section covers the essential NLP functions, from text preprocessing to more advanced models like Word2Vec and transformers.
-
Basic NLP Functions:
tokenize_sentence,remove_stopwords,stem_word,lowercase_sentencecount_word_frequencies,one_hot_encode,build_vocabulary
-
Advanced NLP Models:
tf_idf,cosine_similarity,word2vec,skip_gram,cbown_gram,predict_next_word,transformer_encoder,transformer_decoder
This stage enhances the neural network's performance using advanced optimization algorithms and regularization techniques to prevent overfitting.
- Functions Included:
adam_optimizer,rmsprop_optimizerl2_regularization,dropout,batch_normalization
For high-performance computation, the library provides support for parallel processing and hardware acceleration.
- Functions Included:
multithreaded_matrix_multiplicationgpu_accelerated_convolution
Here's a summary of key AI functions included in the library:
-
Matrix and Vector Operations:
- Perform essential operations on matrices and vectors, which are fundamental to any machine learning algorithm.
-
Activation & Loss Functions:
- Functions like
relu,softmax,sigmoid, and cross-entropy are key components of neural networks.
- Functions like
-
Neural Networks:
- Implement custom neural networks with forward and backward passes for fully connected layers (
dense_layer).
- Implement custom neural networks with forward and backward passes for fully connected layers (
-
CNN & RNN Functions:
- Implement convolutional layers (
convolution2d,pooling) for image-based tasks and recurrent layers (forward_rnn) for sequential data.
- Implement convolutional layers (
-
Convolution Layers:
convolution2dandpoolingoperations allow for building deep CNN architectures.
-
Activation Functions:
relu_activationapplies a non-linear transformation after each convolution.
-
Pooling Layers:
max_pooling2dandaverage_pooling2dreduce spatial dimensions while preserving important features.
-
Advanced Techniques:
batch_normalization_cnnnormalizes outputs between layers, speeding up training.
-
Tokenization & Preprocessing:
- Basic NLP functions like
tokenize_sentenceandremove_stopwordshelp in text preprocessing.
- Basic NLP functions like
-
Word Embeddings:
- Functions like
word2vecandskip_gramcreate embeddings for words, which are useful for language models.
- Functions like
-
Transformer Models:
transformer_encoderandtransformer_decoderfunctions enable transformer-based models for state-of-the-art NLP applications.
- Additional deep learning architectures (e.g., LSTM, GRU).
- Transformer-based models like BERT and GPT.
- GPU support for more AI-related operations.
Contributions are welcome! Whether it’s optimizing the code, adding new features, or improving documentation, feel free to open a pull request or submit an issue.