Explain Skip gram with subwords models from word2vec in nlp

This recipe explains Skip gram with subwords models from word2vec in nlp

Recipe Objective

Explain Skip gram with subwords models from word2vec.

As we have discussed earlier about skip gram, which predicts the the surrounding context words within specific window given current word. The input layer contains the current word and the output layer contains the context words. The hidden layer contains the number of dimensions in which we want to represent current word present at the input layer. Subwords these are the woords which uses some letters of a subject. for e.g "gi","rl" are the subwords of "girl". Lets understand the skip gram with subword practically.

Step 1 - Install the required libraries

!pip install cython !pip install pyfasttext

Step 2 - Import the necessary libraries

from pyfasttext import FastText

Step 3 - load the sample dataset

sample = open("/content/alice_in_wonderland.txt", 'r') alice_data = sample.read()

Step 4 - load the model

model = FastText()

Step 5 - Train the model using skip gram

model.skipgram(input='alice_in_wonderland.txt', output='model', epoch=2, lr=0.7)

Step 6 - Get the subwords for some sample words

print("The subword for boy are:",model.get_all_subwords('boy'),'\n') print("The subword for girl are:",model.get_all_subwords('girl'),'\n')
The subword for boy are: ['boy', '', 'boy', 'boy>', 'oy>'] 
The subword for girl are: ['girl', '', 'gir', 'girl', 'girl>', 'irl', 'irl>', 'rl>']

What Users are saying..

profile image

Abhinav Agarwal

Graduate Student at Northwestern University
linkedin profile url

I come from Northwestern University, which is ranked 9th in the US. Although the high-quality academics at school taught me all the basics I needed, obtaining practical experience was a challenge.... Read More

Relevant Projects

Build Customer Propensity to Purchase Model in Python
In this machine learning project, you will learn to build a machine learning model to estimate customer propensity to purchase.

Build CNN for Image Colorization using Deep Transfer Learning
Image Processing Project -Train a model for colorization to make grayscale images colorful using convolutional autoencoders.

End-to-End Snowflake Healthcare Analytics Project on AWS-2
In this AWS Snowflake project, you will build an end to end retraining pipeline by checking Data and Model Drift and learn how to redeploy the model if needed

Deploy Transformer-BART Model on Paperspace Cloud
In this MLOps Project you will learn how to deploy a Tranaformer BART Model for Abstractive Text Summarization on Paperspace Private Cloud

Learn to Build a Siamese Neural Network for Image Similarity
In this Deep Learning Project, you will learn how to build a siamese neural network with Keras and Tensorflow for Image Similarity.

MLOps Project to Deploy Resume Parser Model on Paperspace
In this MLOps project, you will learn how to deploy a Resume Parser Streamlit Application on Paperspace Private Cloud.

PyTorch Project to Build a GAN Model on MNIST Dataset
In this deep learning project, you will learn how to build a GAN Model on MNIST Dataset for generating new images of handwritten digits.

Build an AI Chatbot from Scratch using Keras Sequential Model
In this NLP Project, you will learn how to build an AI Chatbot from Scratch using Keras Sequential Model.

Machine Learning Project to Forecast Rossmann Store Sales
In this machine learning project you will work on creating a robust prediction model of Rossmann's daily sales using store, promotion, and competitor data.

Detectron2 Object Detection and Segmentation Example Python
Object Detection using Detectron2 - Build a Dectectron2 model to detect the zones and inhibitions in antibiogram images.