Created
November 18, 2019 14:22
-
-
Save Manikanta-Munnangi/19dc891b3ee442bd079780818c565500 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\"\n", | |
"\n", | |
"# returns doc container with attributes \n", | |
"doc=nlp(text)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# loop through doc and return tokens with .text\n", | |
"tokenized=[(token.text,token.pos_,token.tag_) for token in doc]" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"- `pos_ (part-of-speech), tag_ is just acroynm of original tagname.`" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"[('Success', 'NOUN', 'NN'),\n", | |
" ('is', 'AUX', 'VBZ'),\n", | |
" (\"n't\", 'PART', 'RB'),\n", | |
" ('easy', 'ADJ', 'JJ'),\n", | |
" (',', 'PUNCT', ','),\n", | |
" ('and', 'CCONJ', 'CC'),\n", | |
" ('that', 'DET', 'DT'),\n", | |
" (\"'s\", 'AUX', 'VBZ'),\n", | |
" ('a', 'DET', 'DT'),\n", | |
" ('good', 'ADJ', 'JJ'),\n", | |
" ('thing', 'NOUN', 'NN')]" | |
] | |
}, | |
"execution_count": 4, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# print result.\n", | |
"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