utils4text.py
def extract_toxicity(df):
    """
    Use parallel computing. Consider only one post at each time.
    In each post, extract the toxic texts.

    Arg:
        df: A given conversation dataframe from a certain subreddit.
    Return:
        df_toxic: A conversation dataframe with exclusively toxic words.
    """
    # initialize clean conversation dataframe
    df_toxic = pd.DataFrame(columns = ['conversation id', 'subreddit', 'post title', 'author', 'dialog turn', 'text'])

    # consider each post
    df_post = df.reset_index().drop('index', axis = 1)
    toxic_row_list = []

    # iterate over each comment from df_link_id
    for i, row in df_post.iterrows():
        if predict_prob([row['text']])[0] > 0.95 and row['dialog turn'] > 1:
            # record the toxic text
            toxic_row_list.append({'conversation id': row['conversation id'], 'subreddit': row['subreddit'],
                                   'post title': row['post title'], 'author': row['author'],
                                   'dialog turn': row['dialog turn'], 'text': row['text']})
    
    df_toxic = df_toxic.append(pd.DataFrame(toxic_row_list))

    return df_toxic

    Use parallel computing. Consider only one post at each time.
    In each post, extract the toxic texts.

    Arg:
        df: A given conversation dataframe from a certain subreddit.
    Return:
        df_toxic: A conversation dataframe with exclusively toxic words.
    
Use parallel computing. Consider only one post at each time.
In each post, extract the toxic texts.

A given conversation dataframe from a certain subreddit.
Return:
df_toxic: A conversation dataframe with exclusively toxic words.
Use parallel computing . Consider only one post at each time . In each post extract the toxic texts . A given conversation dataframe from a certain subreddit . Return : df_toxic : A conversation dataframe with exclusively toxic words .
def extract_toxicity(df):
    df_toxic = pd.DataFrame(columns = ['conversation id', 'subreddit', 'post title', 'author', 'dialog turn', 'text'])
    df_post = df.reset_index().drop('index', axis = 1)
    toxic_row_list = []
    for i, row in df_post.iterrows():
        if predict_prob([row['text']])[0] > 0.95 and row['dialog turn'] > 1:
            toxic_row_list.append({'conversation id': row['conversation id'], 'subreddit': row['subreddit'],
                                   'post title': row['post title'], 'author': row['author'],
                                   'dialog turn': row['dialog turn'], 'text': row['text']})
    df_toxic = df_toxic.append(pd.DataFrame(toxic_row_list))
    return df_toxic
def extract_toxicity ( df ) : df_toxic = pd . DataFrame ( columns = [ 'conversation id' , 'subreddit' , 'post title' , 'author' , 'dialog turn' , 'text' ] ) df_post = df . reset_index ( ) . drop ( 'index' , axis = 1 ) toxic_row_list = [ ] for i , row in df_post . iterrows ( ) : if predict_prob ( [ row [ 'text' ] ] ) [ 0 ] > 0.95 and row [ 'dialog turn' ] > 1 : toxic_row_list . append ( { 'conversation id' : row [ 'conversation id' ] , 'subreddit' : row [ 'subreddit' ] , 'post title' : row [ 'post title' ] , 'author' : row [ 'author' ] , 'dialog turn' : row [ 'dialog turn' ] , 'text' : row [ 'text' ] } ) df_toxic = df_toxic . append ( pd . DataFrame ( toxic_row_list ) ) return df_toxic
Use parallel computing.
Use parallel computing .
"""
    Use parallel computing. Consider only one post at each time.
    In each post, extract the toxic texts.

    Arg:
        df: A given conversation dataframe from a certain subreddit.
    Return:
        df_toxic: A conversation dataframe with exclusively toxic words.
    """ # initialize clean conversation dataframe # consider each post # iterate over each comment from df_link_id # record the toxic text
df