January 2019
Intermediate to advanced
342 pages
9h 17m
English
Before we tokenize the tweet, it might be worthwhile replacing the anonymized screen names in the tweets to a common name so that the responses generalize better. The function for this can be coded as follows:
def replace_anonymized_names(self,data): def replace_name(match): cname = match.group(2).lower() if not cname.isnumeric(): return match.group(1) + match.group(2) return '@__cname__' re_pattern = re.compile('(\W@|^@)([a-zA-Z0-9_]+)') if self.mode == 'train': in_text = data['text_x'].apply(lambda txt:re_pattern.sub(replace_name,txt)) out_text = data['text_y'].apply(lambda txt:re_pattern.sub(replace_name,txt)) return list(in_text.values),list(out_text.values) else: return map(lambda x:re_pattern.sub(replace_name,x),data) ...Read now
Unlock full access