Skip to main content

Package to extract keywords in one of the classes of a dataset

Project description

Harmonic Mean of Relative Frequencies (HMRF)

HMRF is a method for automatic keyword extraction from a text corpus. This method favors words that maximize the difference between their frequency in one class (positive class) and their frequency in the rest of the classes.

Parameters

  • lang: str, default = 'english'. Language of the texts.

  • positive_class: str or int, default = 1

  • n: int, default = 50. Amount of keywords to extract.

  • phrases: bool, default = False. If phrases will be extracted.

  • n_phrases: int, default = 20. Amount of key phrases to extract.

  • phrases_by: {'Freq', 'PMI', 'TTEST', 'CHI'}, default = 'PMI'. Strategy to extract key phrases.

Usage (Python)

Example 1

import hmrf

texts = ["I absolutely loved this movie! The storyline was captivating, the acting was superb, and the cinematography was stunning.",
         "This restaurant exceeded my expectations. The food was delicious, the service was impeccable, and the ambiance was delightful.",
	 "I'm so happy with my purchase! The product arrived on time, it works perfectly, and the customer support was excellent.",
	 "The hotel stay was amazing. The room was spacious and clean, the staff was friendly and accommodating, and the amenities were top-notch.",
	 "I highly recommend this book. The writing style is beautiful, the characters are well-developed, and the story kept me hooked till the end.",
	 "I was extremely disappointed with the quality of this product. It broke within a week, and the customer service was unhelpful.",
	 "The movie was a complete waste of time. The plot was confusing, the acting was terrible, and I regretted watching it.",
	 "The service at this restaurant was awful. The food took forever to arrive, the server was rude, and the prices were exorbitant.",
	 "I had a horrible experience with this airline. My flight was delayed, the seats were uncomfortable, and the staff was unprofessional.",
	 "I found this book to be poorly written. The characters were one-dimensional, the plot was predictable, and it lacked depth."]

labels = [1, 1, 1, 1, 1, 0, 0, 0, 0, 0]

extractor = hmrf.Hmrf(n=10)
keywords = extractor.hmrf(texts, labels)
	
for kw in keywords:
    print(kw)

Output

purchase
notch
kept
room
impeccable
hotel
hooked
recommend
spacious
stay

Example 2

import hmrf

texts = ["I admire the government's efforts to promote education and create equal opportunities for all citizens.",
	 "The new policy on environmental conservation is a step in the right direction. It's crucial to protect our planet for future generations.",
	 "I strongly disagree with the recent tax reform. It places an unfair burden on the middle class and fails to address income inequality.",
	 "The foreign policy decisions taken by our leaders have enhanced our diplomatic relations and strengthened global cooperation.",
	 "I appreciate the government's commitment to healthcare reform. Accessible and affordable healthcare should be a priority for everyone.",
	 "What an incredible goal by the striker! The precision and power in that shot were absolutely amazing.",
	 "The team showed great resilience and teamwork throughout the game, securing a well-deserved victory.",
	 "The athlete's performance in the marathon was outstanding. They displayed remarkable endurance and determination.",
	 "The coach's strategic decisions and effective player substitutions turned the match around in our team's favor.",
	 "It's disappointing to see the player receive a red card. Their unsportsmanlike behavior tarnished the spirit of the game."]

labels = ["political", "political", "political", "political", "political", "sport", "sport", "sport", "sport", "sport"]

extractor = hmrf.Hmrf(positive_class="political", n=10)
keywords = extractor.hmrf(texts, labels)
	
for kw in keywords:
    print(kw)

Output

healthcare
government
policy
reform
global
generations
income
future
inequality
accessible

References

Please cite the following works when using Hmrf

@article{DELAPENASARRACEN2023103433,
title = {Systematic keyword and bias analyses in hate speech detection},
journal = {Information Processing & Management},
volume = {60},
number = {5},
pages = {103433},
year = {2023},
issn = {0306-4573},
doi = {https://doi.org/10.1016/j.ipm.2023.103433},
url = {https://www.sciencedirect.com/science/article/pii/S030645732300170X},
author = {Gretel Liz {De la Peña Sarracén} and Paolo Rosso},
}

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

hmrf-0.2.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hmrf-0.2.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file hmrf-0.2.0.tar.gz.

File metadata

  • Download URL: hmrf-0.2.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/34.0 requests/2.24.0 requests-toolbelt/1.0.0 urllib3/1.26.7 tqdm/4.56.2 importlib-metadata/1.7.0 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.6.9

File hashes

Hashes for hmrf-0.2.0.tar.gz
Algorithm Hash digest
SHA256 d5c084b5f12ebdcb20b10b879b6487e5163f6d68236b3cc397b51df46bd757dd
MD5 eff03d51da7fe8ebaf476f38a8839245
BLAKE2b-256 09ff0ec7cad76b7e3b8f9475b132eda8f4e75942fd1569ceb2945df8adce9ab5

See more details on using hashes here.

File details

Details for the file hmrf-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: hmrf-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/34.0 requests/2.24.0 requests-toolbelt/1.0.0 urllib3/1.26.7 tqdm/4.56.2 importlib-metadata/1.7.0 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.6.9

File hashes

Hashes for hmrf-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 666f913d205a084713a71fa291dd4cfaf5dac48924e9e150016446a6ffd897f4
MD5 639e71c44c55ba7ac74cb5215a87a32b
BLAKE2b-256 30af0088d07a0f422834effc147ca7b3f463994a3fdaa67d6fce5caacf7a1d78

See more details on using hashes here.

Supported by

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