Giter Site home page Giter Site logo

arukemre / natural_language-processing-with-pytorch-kfold-optuna Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 823 KB

Predicting which Tweets are about real disasters and which ones are not

Jupyter Notebook 100.00%
data-science kfold-cross-validation nlp-machine-learning optimization-algorithms python pytorch

natural_language-processing-with-pytorch-kfold-optuna's Introduction

Natural Language Processing with Pytorch | KFold | Optuna

PyTorch

  • Pytorch is a machine learning framework based on the Torch library, used for applications such as computer vision and natural language processing, originally developed by Meta AI(facebook).Although the Python interface is more polished and the primary focus of development, PyTorch also has a C++ interface.

K fold Cross Validation

  • K fold Cross Validation is a technique used to evaluate the performance of your machine learning or deep learning model in a robust way.
  • It splits the dataset into k parts/folds of approximately equal size. Each fold is chosen in turn for testing and the remaining parts for training.
  • This process is repeated k times and then the performance is measured as the mean across all the test sets.

Optuna | A hyperparameter optimization framework

F1 Score

F1 is calculated as follows:

Screen Shot 2023-01-09 at 21 15 16

where:

  • True Positive [TP] = your prediction is 1, and the ground truth is also 1 - you predicted a positive and that's true!
  • False Positive [FP] = your prediction is 1, and the ground truth is 0 - you predicted a positive, and that's false.
  • False Negative [FN] = your prediction is 0, and the ground truth is 1 - you predicted a negative, and that's false.

Preprocessing steps

  • Train and Test dataframes contains tweet phrases.Target have consist of two class.We are predicting whether a given tweet is about a real disaster or not. If so, predict a 1. If not, predict a 0. First,We applied preprocessing function over tweets.This functions remove puncations from words and ignore some stopwords from tweets.We applied all function before split test data from train data. Theni,Added all words at a dictionary that contain uniuqe words and unique key. Namely, We labeled words like an integer value. Then we created new train and test dataframe accoridng this labeled data

Implementation with Pytorch and sklearn

  • The K Fold Cross Validation is used to evaluate the performance of the RNN(LSTM) model on the dataset. This method is implemented using the sklearn library, while the model is trained using Pytorch.Happening all of this we tuned parameters with optuna.

  • We define the Neural network architecture with one LSTM layers and one fully connected layer to classify the sentences into one of the two categories. We add two Dropout layers in the model to limit the risk of overfitting.

  • We initialize the nn.BCEWithLogitsLoss loss function for the classification, the device to utilize the GPU.

  • Moreover, we generate 4 folds using the Kfold function in each trails of objective function , where we have random splits and replicable results with random_state=0 . So, it divides the dataset into 3 parts for training and the remaining part for testing.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.