Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

48: fixing the issue by using contractions and stopwords #70

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,8 @@
"import numpy as np\n",
"from sklearn import feature_extraction\n",
"from tqdm import tqdm\n",
"import contractions\n",
"from nltk.corpus import stopwords \n",
"\n",
"\n",
"_wnl = nltk.WordNetLemmatizer()\n",
Expand All @@ -522,13 +524,14 @@
"\n",
"def clean(s):\n",
" # Cleans a string: Lowercasing, trimming, removing non-alphanumeric\n",
" s = contractions.fix(s)\n",
"\n",
" return \" \".join(re.findall(r'\\w+', s, flags=re.UNICODE)).lower()\n",
"\n",
"\n",
"def remove_stopwords(l):\n",
" # Removes stopwords from a list of tokens\n",
" return [w for w in l if w not in feature_extraction.text.ENGLISH_STOP_WORDS]\n",
" return [w for w in l if w not in stopwords.words('english')] # Use stopwords.words('english')\n",
"\n",
"\n",
"def gen_or_load_feats(feat_fn, headlines, bodies, feature_file):\n",
Expand Down