Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
N
NLP-Project
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
almohanad.hafez
NLP-Project
Commits
0145d10f
Commit
0145d10f
authored
Nov 16, 2024
by
Almouhannad Hafez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(5) Add initial stanza pipeline results
parent
80280f8d
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
131 additions
and
1 deletion
+131
-1
5.0.Process_texts_stanza.ipynb
5.0.Process_texts_stanza.ipynb
+128
-0
constants.py
constants.py
+3
-1
lemmatized_texts.pkl
stanza/lemmatized_texts.pkl
+0
-0
No files found.
5.0.Process_texts_stanza.ipynb
0 → 100644
View file @
0145d10f
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# ***Setup***"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"C:\\Users\\TOSHIBA\\AppData\\Roaming\\Python\\Python39\\site-packages\\networkx\\utils\\backends.py:135: RuntimeWarning: networkx backend defined more than once: nx-loopback\n",
" backends.update(_get_backends(\"networkx.backends\"))\n"
]
}
],
"source": [
"import pandas as pd\n",
"\n",
"import stanza\n",
"\n",
"import pickle # Module to store python objects\n",
"\n",
"from constants import CONSTANTS"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## ***Load dataset***"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"df = pd.read_csv(CONSTANTS.AUGMENTED_DATASET_PATH)\n",
"assert df.shape == (7200, 3), f\"Expected shape (7200, 3), but got {df.shape}\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## ***Define stanza pipeline***"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"nlp = stanza.Pipeline(lang='en', processors='tokenize,mwt,pos,lemma', verbose=False)\n",
" # mwt = multi word tokenization"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# ***Process dataset using stanza pipeline***"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"texts = df[\"text\"].to_list()\n",
"ids = df[\"Id\"].to_list()\n",
"docs = []\n",
"for i in range(len(ids)):\n",
" dict = {'id': ids[i], 'processed_text': nlp(texts[i])}\n",
" docs.append(dict)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# ***Store processed texts***"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"with open(CONSTANTS.LEMMATIZED_TEXTS_OBJECT_PATH, 'wb') as f:\n",
" pickle.dump(docs, f)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "base",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.20"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
constants.py
View file @
0145d10f
...
@@ -5,3 +5,5 @@ class CONSTANTS:
...
@@ -5,3 +5,5 @@ class CONSTANTS:
AUGMENTED_DATASET_PATH
=
'data/augmented_Symptom2Disease.csv'
AUGMENTED_DATASET_PATH
=
'data/augmented_Symptom2Disease.csv'
AUGMENTED_TRAIN_SET_PATH
=
'data/augmented_Preprocessed_Symptom2Disease_Train.csv'
AUGMENTED_TRAIN_SET_PATH
=
'data/augmented_Preprocessed_Symptom2Disease_Train.csv'
AUGMENTED_TEST_SET_PATH
=
'data/augmented_Preprocessed_Symptom2Disease_Test.csv'
AUGMENTED_TEST_SET_PATH
=
'data/augmented_Preprocessed_Symptom2Disease_Test.csv'
LEMMATIZED_TEXTS_OBJECT_PATH
=
'stanza/lemmatized_texts.pkl'
\ No newline at end of file
stanza/lemmatized_texts.pkl
0 → 100644
View file @
0145d10f
File added
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment