Skip to main content

politenessr

Project description

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 (wujj38@mail2.sysu.edu.cn)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

politenessr-1.3.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

politenessr-1.3-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file politenessr-1.3.tar.gz.

File metadata

  • Download URL: politenessr-1.3.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.18.4 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.6.5

File hashes

Hashes for politenessr-1.3.tar.gz
Algorithm Hash digest
SHA256 1f0ff4efa78ab66433f22f592a0aa01fa6dc068412ecd3d13cc2edd5b6846ace
MD5 f33e704653e76a8676bd7aaa52da2419
BLAKE2b-256 20c12aafedfb4af833412c2593e589bf7633481cfcceaaef553c50a275eb6ea0

See more details on using hashes here.

File details

Details for the file politenessr-1.3-py3-none-any.whl.

File metadata

  • Download URL: politenessr-1.3-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.18.4 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.6.5

File hashes

Hashes for politenessr-1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 79b4572ee7e8bd340dadf4c556fb69755b34ed2f9923d4a35a4606776328210e
MD5 9917987639c3bc18607463982c3f5eeb
BLAKE2b-256 5e203f1cdb65d30e34d32bc48b9ead81bf564c67f890e26b25698c22524619d3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page