-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
76a58a2
commit 4b60c95
Showing
1 changed file
with
21 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)] |