GithubHelp home page GithubHelp logo

bothe / politenessr Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wujunjie1998/politenessr

0.0 0.0 0.0 22 KB

This is a python package which is used to predict politeness values of texts.

License: MIT License

Python 100.00%

politenessr's Introduction

Politenessr

Intro

Politenessr is a package used to predict the value of politeness of texts.

It is based on a fine tuned BERT model.

Install

Use pip

If pip is installed, politenessr could be installed directly from it:

pip install politenessr

Dependencies

python>=3.6.0
torch>=0.4.1
numpy
pandas
unidecode
pytorch-pretrained-bert
pytorch-transformers

Usage and Example

Notes: During your first usage, the package will download a model file automatically, which is about 400MB.

predict

predict is the core method of this package, which takes a single text of a list of texts, and returns a list of raw values in [1,5] (higher means more politeness, while lower means less).

Simplest usage

You may directly import politenessr and use the default predict method, e.g.:

>>> import politenessr
>>> politenessr.predict(["I am totally agree with you"])
[4.3568916]

Construct from class

Alternatively, you may also construct the object from class, where you could customize the model path and device:

>>> from politenessr import Politenessr
>>> pr = Politenessr()

# Predict a single text
>>> pr.predict(["I am totally agree with you"])
[3.5638056]

# Predict a list of texts
>>> preds = pr.predict(['I am totally agree with you','I hate you'])
>>> f"Raw values are {preds}"
[3.5638053 2.2007465]

More detail on how to construct the object is available in docstrings.

Model using multiprocessing when preprocessing a large dataset into BERT input features

If you want to use several cpu cores via multiprocessing while preprocessing a large dataset, you may construct the object via

>>> pr = Politenessr(CPU_COUNT=cpu_cpunt, CHUNKSIZE=chunksize)

If you want to faster the code through multi gpus, you may construct the object via

>>> pr = Politenessr(is_paralleled=True, BATCH_SIZE = batch_size)

Contact

Junjie Wu ([email protected])

politenessr's People

Contributors

wujunjie1998 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.