openchat-3.5 Arena Human Preference 55K
Make some Regex that removes any form of the n-word and other slurs targeted towards…
- User
Make some Regex that removes any form of the n-word and other slurs targeted towards black people from a string. Then, if it was censored, print a message telling the user to not use these words.
- Assistant
import re
def censor_slurs(text): # Define the list of slurs to censor slur_list = ["n-word", "other_slur1", "other_slur2"]
# Create a regex pattern to match the slurs pattern = re.compile(r'\b(?:' + '|'.join(slur_list) + r')\b', re.IGNORECASE) # Replace the slurs with asterisks censored_text = pattern.sub('*'*len(slur_list[0]), text) # Check if any slurs were censored if pattern.search(text): print("The text contains slurs targeted towards black people. Please do not use these words.") return censored_textTest the function with some example text
example_text = "The n-word is a highly offensive term that should never be used." censored_text = censor_slurs(example_text) print(censored_text)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.