![]() fetch_20newsgroups has already differentiated subset of train and test dataset so we can fetch that. Now, we define the categories and training & testing data from the dataset to make our Naive Bayes Classifier. ['alt.atheism', 'aphics', 'comp.os.ms-windows.misc', '.hardware', This are the target_names in which the text is classified into sub-categories, there are 20 different classes: import numpy as npįrom sklearn.datasets import fetch_20newsgroups Then we assigned the imported dataset to 'data' variable and targetnames will print all the categories in which the dataset is categorized. We start with importing the fetch_20newsgroups dataset, this dataset is very common for working with tokenized texts and exploring how word categorized in a document. And will predict the class of the text that the text belong based on the target classes available in fetch_20newsgroups. Classification of text can be seen like Hate Speech classification used in various social media platform to limit the hate speech on the Internet.įor text classification we will make a Naive Bayes Classifier that will use the fetch_20newsgroups dataset available in sklearn.datasets to train on. ![]() Text ClassificationĪnother awesome application of NLP is to classify the text into certain categories. Though this module looks modest but you can use for various purpose as per your need as it make the process simple for the demanding task of translation. Sentence to convert: It is an example of translation. Print("Translated Sentence: ", translatedSent.text) TranslatedSent= anslate(sentence, src='en', dest='hi') ![]() text sentence= input("Sentence to convert: ") We will use the translate() method to translate the sentence which accept the parameters as text-> text to translate, src-> source language code(it is automatically recognized by the module) and dest-> destination language code the sentence have to be translated into.Īnd to extract the converted text from the output use the. Install the googletrans module and import the Translator from it and create an object of it. Language Translation is another application where the power of NLP can be utilized.įor Language Translation task we are going to use the module GoogleTrans for the conversion of any language to the destination language the user choose. Natural Language can be defined as any human readable language and for this another amazing module is there in Python that can be used in various purpose. There are so many methods available with this package and you can utilize that for your own purpose. That is how you can work with PDF file in Python using PyPDF2. pdf_writer= pdf.PdfFileWriter()Ībove code will create and save a PDF named as Pages1&15 that will only contain first and last pages of the original file and have same style as of the original PDF text. Then to save the PDF we will open a new file using Python and write the pdf_writer information to the new PDF. We will extract text data of pages that we want to merge using pdf_reader and then add that pages in pdf_writer object. Make a write object so that PyPDF can write in a file. For that we will merge the first and last page of the extracted text data and will merge them to make a new PDF file. Now we will write a PDF file from the text data. But getPage() will return the text in binary form to extract the information we will use extractText() for readable text. Now lets extract the information of a specific page number using getPage()Īnd pass the page number as the parameter. But here we are using getNumPages() that return total pages in the file and getIsEncrypted() will return True based on whether PDF file is password protected or not. PyPDF give numerous method to work on PDF. Now create a object so that PyPDF can read text of the PDF and pass the file in parameter that we opened above. ![]() !pip install PyPDF2įile= open('/ASK THE RIGHT QUESTIONS.pdf', 'rb') We will install and import PyPDF2 module and open the PDF file in Python to start reading from the PDF file. Text from PDF cannot be extracted correctly always as PDF can sometime comprises of Diagrams, Tables etc. We are going to use PyPdf2 module to read and extract text of a PDF. NLP can be used to work with PDF, it can help to convert PDF to text file and other manipulation task. In this article we will be going to see applications of NLP like: Though there are numerous applications of NLP but in this article we are going to get brief about some more applications which can be seen in real world. In the previous article, we have gone through some of the applications of NLP.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |