Skip to content
This repository has been archived by the owner on May 4, 2020. It is now read-only.

ServiceInnovationLab/bagel-TextBlob

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bagel-TextBlob

Getting started

Step 1: Clone the repo

git clone https://github.com/ServiceInnovationLab/bagel-TextBlob.git
cd bagel-TextBlob

Step 2: Install python using pyenv

We want to use the exact version of python this project recommends.

 pyenv install < .python-version

To check the current version after installation:

 python --version # This should match the version in .python-version file

Step 3: Install Dev dependencies

pip install -r requirements.txt

Building a Text Classification System

Adding Data

First we’ll create some training and test data: Using/editing the dummmy data from train.json & test.json.

Loading Data from Files

Example: Passing the opened file into the constructor

with open('train.json', 'r') as fp:
    cl = NaiveBayesClassifier(fp, format="json")

Creating a Classifier & Training it

from textblob import TextBlob
from textblob.classifiers import NaiveBayesClassifier
with open('train.json', 'r') as fp:
    cl = NaiveBayesClassifier(fp, format="json")

Classifying Text

Call the classify(text) method to use the classifier.

Example:

cl.classify("This is an amazing library!")

Or if you have more than 1 line of text:

blob = TextBlob("The beer is good. But the hangover is horrible.", classifier=cl)
for s in blob.sentences:
    print(s)
    print(s.classify())

For Sentiment Analysis

Example of positive:

from textblob import TextBlob
from textblob.sentiments import NaiveBayesAnalyzer
blob = TextBlob("I love this library", analyzer=NaiveBayesAnalyzer())
blob.sentiment

Example of negative:

from textblob import TextBlob
from textblob.sentiments import NaiveBayesAnalyzer
blob = TextBlob("My boss is horrible.", analyzer=NaiveBayesAnalyzer())
blob.sentiment

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published