Skip to main content

Twikenizer

This repository hosts the code for a tokenizer of tweets. It's main purpose is to identify subtle profanity, so it should obtain better performance on data containing hidden profanity (e.g. 'f*ck').

Disclaimer: The following paragraphs may contain profanity.

Description

Python offers a set of sentence tokenizers for different purposes: nltk's word tokenizer, spacy's, scikit-learn's default and TweetTokenizer, among others. All but TweetTokenizer disregard hashtags and mentions by separating the symbols from the rest of the token(s). Although TweetTokenizer considers the Twitter dialect, it fails to tokenize subtle hidden profanity.

For the word f*ck,the tokens considered are [f, *, ck]. The word g@y is tokenized as [g, @y], considering a single token g and a wrongly identified mention @y. While the hashtag #hash_tag is correctly tokenized as [#hash_tag], regular tokens are not underscore separated: love_twitter is tokenized as ['love_twitter'] instead of ['love', '_', 'twitter'].

Twikenizer was created in order to enable a proper identification of hidden profane words, considering the features detailed above. Applying distance related features, i.e. levenshtein distance to slang words should output better results using this tokenizer.

Installation

Using pip

pip install twikenizer

Clone repository

git clone https://github.com/Guilherme-Routar/Twikenizer.git

Usage

> import twikenizer as twk
> twk = twk.Twikenizer()
> tweet = 'This is an #hashtag'
> twk.tokenize(tweet)
['This', 'is', 'an', '#hashtag']

Twikenizer has a built-in function examplify which demonstrates how it tokenizes different kind of words/tokens.

> twk.examplify()
Generated tweet
###############
Tw33t # @dude_really #hash_tag $hit (g@y) retard#d @dude. 😀😀 !😀abc %😀lol #hateit #hate.it $%&/ f*ck-

Generated tokens
################
['Tw33t', '#', '@dude_really', '#hash_tag', '$hit', '(', 'g', '@', 'y', ')', 'retard#d', '@dude', '.', '😀', '😀', '!', '😀', 'abc', '%', '😀', 'lol', '#hateit', '#hate', '.', 'it', '$', '%', '&', '/', 'f*ck', '-']
´´´

Metadata

Release files for twikenizer 1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for twikenizer 1.0
File Size Uploaded
twikenizer-1.0.tar.gz 4.4 kB Details

Release files / twikenizer-1.0.tar.gz

Download URL twikenizer-1.0.tar.gz
Size 4.4 kB
Tags Source
SHA-256 checksum
How to use checksums
678d7fc2adef86f6e9e2693c8710ef31b76a342923558a37d87ec09f8f97a33f
BLAKE2b-256 checksum
How to use checksums
d2517aee33630b948f0716efae7a96c4fd8f859b348694058c380fd899a4227e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.5

Release history Release notifications | RSS feed

This release

1.0 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page