Skip to content

Commit

Permalink
helper functions for model
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardcqian committed Mar 13, 2019
1 parent 76a58a2 commit 4b60c95
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import re
import numpy as np

# clean up given string
def clean_text(raw):
# Remove link
raw = re.sub(r'http\S+', '', raw)
# Remove unexpected artifacts
raw = re.sub(r'…', '', raw)
raw = re.sub(r'…', '', raw)
raw = re.sub(r'’', "'", raw)
raw = re.sub(r'‘', "'", raw)
raw = re.sub(r'\$q\$', "'", raw)
raw = re.sub(r'&', "and", raw)
# remove non valid characters
raw = re.sub('[^A-Za-z0-9#@ ]+', "", raw)
return(raw)

# create onehot representation of the label
def get_onehot(arr, num_class):
return np.eye(num_class)[np.array(arr).reshape(-1)]

0 comments on commit 4b60c95

Please sign in to comment.