Angela  Dickens

Angela Dickens

1599202560

Text Classification on Disaster Tweets with LSTM and Word Embedding

This was my first Kaggle notebook and I thought why not write it on Medium too?

Full code on my Github.

In this post, I will elaborate on how to use fastText and GloVe as word embedding on LSTM model for text classification. I got interested in Word Embedding while doing my paper on Natural Language Generation. It showed that embedding matrix for the weight on embedding layer improved the performance of the model. But since it was NLG, the measurement was objective. And I only used fastText too. So in this article, I want to see how each method (with fastText and GloVe and without) affects to the prediction. On my Github code, I also compare the result with CNN. The dataset that i use here is from one of competition on Kaggle, consisted of tweets and labelled with whether the tweet is using disastrous words to inform a real disaster or merely just used it metaphorically. Honestly, on first seeing this dataset, I immediately thought about BERT and its ability to understand way better than what I proposed on this article (further reading on BERT).

But anyway, in this article I will focus on fastText and GloVe.

Let’s go?


Data + Pre-Processing

The data consisted of 7613 tweets (columns Text) with label (column Target) whether they were talking about a real disaster or not. With 3271 rows informing real disaster and 4342 rows informing not real disaster. The data shared on kaggle competition, and if you want to learn more about the data you can read it here.

Image for post

Example of real disaster word in a text :

“ Forest fire near La Ronge Sask. Canada “

Example of the use of disaster word but not about disaster:

“These boxes are ready to explodeExploding Kittens finally arrived! gameofkittens #explodingkittens”

The data will be divided for training (6090 rows) and testing (1523 rows) then proceed to pre-processing. We will only be using the text and target columns.

#data-science #lstm #word-embeddings #nlp #text-classification #data analysis

What is GEEK

Buddha Community

Text Classification on Disaster Tweets with LSTM and Word Embedding
Angela  Dickens

Angela Dickens

1599202560

Text Classification on Disaster Tweets with LSTM and Word Embedding

This was my first Kaggle notebook and I thought why not write it on Medium too?

Full code on my Github.

In this post, I will elaborate on how to use fastText and GloVe as word embedding on LSTM model for text classification. I got interested in Word Embedding while doing my paper on Natural Language Generation. It showed that embedding matrix for the weight on embedding layer improved the performance of the model. But since it was NLG, the measurement was objective. And I only used fastText too. So in this article, I want to see how each method (with fastText and GloVe and without) affects to the prediction. On my Github code, I also compare the result with CNN. The dataset that i use here is from one of competition on Kaggle, consisted of tweets and labelled with whether the tweet is using disastrous words to inform a real disaster or merely just used it metaphorically. Honestly, on first seeing this dataset, I immediately thought about BERT and its ability to understand way better than what I proposed on this article (further reading on BERT).

But anyway, in this article I will focus on fastText and GloVe.

Let’s go?


Data + Pre-Processing

The data consisted of 7613 tweets (columns Text) with label (column Target) whether they were talking about a real disaster or not. With 3271 rows informing real disaster and 4342 rows informing not real disaster. The data shared on kaggle competition, and if you want to learn more about the data you can read it here.

Image for post

Example of real disaster word in a text :

“ Forest fire near La Ronge Sask. Canada “

Example of the use of disaster word but not about disaster:

“These boxes are ready to explodeExploding Kittens finally arrived! gameofkittens #explodingkittens”

The data will be divided for training (6090 rows) and testing (1523 rows) then proceed to pre-processing. We will only be using the text and target columns.

#data-science #lstm #word-embeddings #nlp #text-classification #data analysis

Text Classification Using Long Short Term Memory & GloVe Embeddings

Preparing textual data for machine learning is a little different than the preparation of tabular data. What makes text data different is the fact that it’s majorly in string form. Therefore, we have to find the best way to represent it in numerical form. In this piece, we’ll see how we can prepare textual data using TensorFlow. Eventually, we’ll build a bidirectional long short term memory  model to classify text data.

#text-classification #text-preprocessing #lstm #machine-learning #heartbeat

Oleta  Becker

Oleta Becker

1604329740

Documents embeddings and text classification without coding

Text is described by the sequence of character. Since every machine learning algorithm needs numbers, we need to transform the text into vectors of real numbers before we can continue with the analysis. To do this, we can use various approaches. The most known approach before the evolution of deep learning was the bag of words which is still widely used because of its advantages. The recent boom in the deep learning brought us new approaches such as word and document embeddings. In this post, we explain what document embedding is, why it is useful, and show its usage on the classification example without coding. For the analysis, we will use the Orange open-source tool.

Word embedding and document embedding

Before we can understand document embeddings, we need to understand the concept of word embeddings. Word embedding is a representation of a word in multidimensional space such that words with similar meanings have similar embedding. It means that each word is mapped to the vector of real numbers that represent the word. Embedding models are mostly based on neural networks.

Document embedding is usually computed from the word embeddings in two steps. First, each word in the document is embedded with the word embedding then word embeddings are aggregated. The most common type of aggregation is the average over each dimension.

Why and when should we use embedders?

Compared to bag-of-words, which counts the number of appearances of each token (word) in the document, embeddings have two main advantages:

  • They do not have a dimensionality problem. The result of bag-of-words is a table which has the number of features equal to the number of unique tokens in all documents in a corpus. Large corpora with long texts result in a large number of unique tokens. It results in huge tables which can exceed the computer memory. Huge tables also increase the learning and evaluation time of machine learning models. Embeddings have constant dimensionality of the vector, which is 300 for fastText embeddings that Orange uses.
  • **Most of the preprocessing is not required. **In the case of the bag-of-words approach, we solve the dimensionality problem with the text preprocessing where we remove tokens (e.g. words) that seems to be less important for the analysis. It can also cause the removal of some important tokens. When using embedders, we do not need to remove tokens, so we are not losing accuracy. Also most of the basic preprocessing can be omitted (such as normalization) in case of fastText embedding.
  • Embeddings can be pretrained on large corpora with billions of tokens. That way, they capture the significant characteristics of the language and produce the embeddings of high quality. Pretrained models are then used to obtain embeddings of smaller datasets.

The shortcoming of the embedders is that they are difficult to understand. For example, when we use a bag-of-words, we can easily observe which tokens are important for classification since tokens themselves are features. In the case of document embeddings, features are numbers which are not understandable to human by themselves.

#embedding #data-science #text-analysis #machine-learning #text-embedding

Daron  Moore

Daron Moore

1598404620

Hands-on Guide to Pattern - A Python Tool for Effective Text Processing and Data Mining

Text Processing mainly requires Natural Language Processing( NLP), which is processing the data in a useful way so that the machine can understand the Human Language with the help of an application or product. Using NLP we can derive some information from the textual data such as sentiment, polarity, etc. which are useful in creating text processing based applications.

Python provides different open-source libraries or modules which are built on top of NLTK and helps in text processing using NLP functions. Different libraries have different functionalities that are used on data to gain meaningful results. One such Library is Pattern.

Pattern is an open-source python library and performs different NLP tasks. It is mostly used for text processing due to various functionalities it provides. Other than text processing Pattern is used for Data Mining i.e we can extract data from various sources such as Twitter, Google, etc. using the data mining functions provided by Pattern.

In this article, we will try and cover the following points:

  • NLP Functionalities of Pattern
  • Data Mining Using Pattern

#developers corner #data mining #text analysis #text analytics #text classification #text dataset #text-based algorithm

Alec  Nikolaus

Alec Nikolaus

1596635640

Text Classification With PyTorch

A baseline model with LSTMs

The question remains open: how to learn semantics? what is semantics? would DL-based models be capable to learn semantics?

Introduction

The aim of this blog is to explain how to build a text classifier based on LSTMs as well as how it is built by using the PyTorch framework.

I would like to start with the following question: how to classify a text? Several approaches have been proposed from different viewpoints under different premises, but what is the most suitable one?. It’s interesting to pause for a moment and question ourselves: how we as humans can classify a text?what do our brains take into account to be able to classify a text?. Such questions are complex to be answered.

Currently, we have access to a set of different text types such as emails, movie reviews, social media, books, etc. In this sense, the text classification problem would be determined by what’s intended to be classified (e.g. _is it intended to classify the polarity of given text? Is it intended to classify a set of movie reviews by category? Is it intended to classify a set of texts by topic? _). In this regard, the problem of text classification is categorized most of the time under the following tasks:

  • Sentiment analysis
  • News categorization
  • Topic analysis
  • Question answering
  • Natural language inference

In order to go deeper into this hot topic, I really recommend to take a look at this paper: Deep Learning Based Text Classification: A Comprehensive Review.

Methodology

The two keys in this model are: tokenization and recurrent neural nets. Tokenization refers to the process of splitting a text into a set of sentences or words (i.e. tokens). In this regard, tokenization techniques can be applied at sequence-level or word-level. In order to understand the bases of tokenization you can take a look at: Introduction to Information Retrieval.

In the other hand, RNNs (Recurrent Neural Networks) are a kind of neural network which are well-known to work well on sequential data, such as the case of text data. In this case, it’s been implemented a special kind of RNN which is LSTMs (Long-Short Term Memory). LSTMs are one of the _improved _versions of RNNs, essentially LSTMs have shown a better performance working with _longer sentences. _In order to go deeper about what RNNs and LSTMs are, you can take a look at: Understanding LSTMs Networks.

Since the idea of this blog is to present a baseline model for text classification, the text preprocessing phase is based on the tokenization technique, meaning that each _text sentence _will be tokenized, then each _token _will be transformed into its index-based representation. Then, each _token sentence based indexes _will be passed sequentially through an embedding layer, this embedding layer will output an embedded representation of each token whose are passed through a two-stacked LSTM neural net, then the last LSTM’s hidden state will be passed through a two-linear layer neural net which outputs a single value filtered by a sigmoid activation function. The following image describes the model architecture:

Image for post

#pytorch #text-mining #lstm #text-classification #python