Coder Social home page Coder Social logo

npl_sentiment_analysis-pickle_-_module-'s Introduction

NPL_Sentiment_Analysis (Pickle & Module)

Natural Language Processing --- Movie review Sentiment Analysis Learn how to convert python object into a byte stream (more efficient programming)


Why pickling

With training models, we often need to store the trained model so that the model can be read directly when making decisions without retraining the model, which saves time.


Installation

pip install pickle

The Basics

The pickle module in Python is used to store document information in the program and store it locally in binary form and can be read out. There are two basic methods:

pickle.dump(obj,file)    #save
pickle.load(file)        #read

Here is a quick example of how to save and load .pickle file.

import pickle
dataList = [[1, 5, 'yes'],
            [2, 4, 'yes'],
            [3, 3, 'no'],
            [4, 2, 'no'],
            [5, 1, 'no']]
dataDic = { 0: [1, 2, 3, 4, 5],
            1: ('yes', 'no'),
            2: {'1':'yes','2':'yes','3':'yes','4':'no','5':'no'}}
 
# Using dump to save the object by serialization
fw = open('dataFile.txt','wb')
# Pickle the list using the highest protocol available.
pickle.dump(dataList, fw, -1)
# Pickle dictionary using protocol 0.
pickle.dump(dataDic, fw)
fw.close()
 
# Using load to read the serialized .pickle file
fr = open('dataFile.txt','rb')
data1 = pickle.load(fr)
print(data1)
data2 = pickle.load(fr)
print(data2)
fr.close()

The results is shown below:

[[1, 5, 'yes'], [2, 4, 'yes'], [3, 3, 'no'], [4, 2, 'no'], [5, 1, 'no']]
{0: [1, 2, 3, 4, 5], 1: ('yes', 'no'), 2: {'1': 'yes', '2': 'yes', '3': 'yes', '4': 'no', '5': 'no'}}

A Example of comment snetiment analysis

import sentiment_mod as s
print(s.sentiment("This movie was awesome! The acting was great, plot was wonderful, and there were pythons...so yea!"))
print(s.sentiment("This movie was utter junk. There were absolutely 0 pythons. I don't see what the point was at all. Horrible movie, 0/10"))
('pos', 1.0)
('neg', 1.0)
We can see that the first comment we created is showing 100% confident as a positive review, and the second one is 100% negative.

@Copyright The review files were re-written based on Sentdex turorials from python programming.

npl_sentiment_analysis-pickle_-_module-'s People

Contributors

parrently avatar

Stargazers

 avatar

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.