Created
November 18, 2019 13:39
-
-
Save Manikanta-Munnangi/c882366f92543e917089897ac44ba4c3 to your computer and use it in GitHub Desktop.
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
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# spacy import convention\n", | |
"import spacy\n", | |
"\n", | |
"# load the english model into nlp object.\n", | |
"nlp=spacy.load('en_core_web_sm') " | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# Sample text\n", | |
"text=\"Tesla founder Elon Musk has launched tech startup Neuralink.\"\n", | |
"\n", | |
"# returns doc container with attributes \n", | |
"doc=nlp(text)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# loop through doc\n", | |
"# return tokens with lemmas_ (actual english language word)\n", | |
"tokenized=[(token.text,token.lemma_) for token in doc]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"[('Tesla', 'tesla'), ('founder', 'founder'), ('Elon', 'Elon'), ('Musk', 'Musk'), ('has', 'have'), ('launched', 'launch'), ('tech', 'tech'), ('startup', 'startup'), ('Neuralink', 'Neuralink'), ('.', '.')]\n" | |
] | |
} | |
], | |
"source": [ | |
"# print result.\n", | |
"print(tokenized)" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"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.6.9" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment