gpt-3.5-turbo-1106· OpenAI
Arena Human Preference 55K
Create a function to detect profanities in texts. The function should be robust from…
- User
Create a function to detect profanities in texts. The function should be robust from misspellings.
- Assistant
Certainly! Here's a simple Python function that uses a list of common profanities and a spell-checking library to detect profanities in texts, even if they are misspelled:
import enchant def detect_profanities(text): profanities = ['profanity1', 'profanity2', 'profanity3'] # Replace with actual profanities d = enchant.Dict("en_US") words = text.split() for word in words: if not d.check(word.lower()) and any(profanity in word.lower() for profanity in profanities): return True return FalseIn this function, we use the
enchantlibrary to check the spelling of each word in the text. If a word is not spelled correctly and contains any of the profanities in the list, the function will returnTrue, indicating the presence of a profanity. Otherwise, it will return . You can replace the list with actual profanities you want to detect.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.