Last active
November 18, 2019 13:12
-
-
Save Manikanta-Munnangi/9786eaa3511a6bd5bcb564331a5e6a5d 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=\"\"\"Success isn't easy, and that's a good thing - at least in business. \\\n", | |
"If it was easy, everybody would be doing it and your competition would be outrageous!\"\"\"\n", | |
"\n", | |
"# returns doc container with many attributes.\n", | |
"doc=nlp(text)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# loop through doc and return tokens with .text attribute\n", | |
"# using list comprehension\n", | |
"tokenized=[token.text for token in doc]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"['Success', 'is', \"n't\", 'easy', ',', 'and', 'that', \"'s\", 'a', 'good', 'thing', '-', 'at', 'least', 'in', 'business', '.', 'If', 'it', 'was', 'easy', ',', 'everybody', 'would', 'be', 'doing', 'it', 'and', 'your', 'competition', 'would', 'be', 'outrageous', '!']\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