Created
December 12, 2019 18:24
-
-
Save danielpcox/69dc511e88b23bc9b76f84cfac5c0b23 to your computer and use it in GitHub Desktop.
StanfordNLP first impression
This file contains hidden or 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": [ | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "import stanfordnlp", | |
"execution_count": 1, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "stanfordnlp.download('en')", | |
"execution_count": 2, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "Using the default treebank \"en_ewt\" for language \"en\".\nWould you like to download the models for: en_ewt now? (Y/n)\nY\n\nDefault download directory: /home/daniel.cox/stanfordnlp_resources\nHit enter to continue or type an alternate directory.\n\n\nDownloading models for: en_ewt\nDownload location: /home/daniel.cox/stanfordnlp_resources/en_ewt_models.zip\n" | |
}, | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": "100%|██████████| 235M/235M [00:27<00:00, 8.45MB/s] \n" | |
}, | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "\nDownload complete. Models saved to: /home/daniel.cox/stanfordnlp_resources/en_ewt_models.zip\nExtracting models file for: en_ewt\nCleaning up...Done.\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "nlp = stanfordnlp.Pipeline()", | |
"execution_count": 4, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "Use device: gpu\n---\nLoading: tokenize\nWith settings: \n{'model_path': '/home/daniel.cox/stanfordnlp_resources/en_ewt_models/en_ewt_tokenizer.pt', 'lang': 'en', 'shorthand': 'en_ewt', 'mode': 'predict'}\n---\nLoading: pos\nWith settings: \n{'model_path': '/home/daniel.cox/stanfordnlp_resources/en_ewt_models/en_ewt_tagger.pt', 'pretrain_path': '/home/daniel.cox/stanfordnlp_resources/en_ewt_models/en_ewt.pretrain.pt', 'lang': 'en', 'shorthand': 'en_ewt', 'mode': 'predict'}\n---\nLoading: lemma\nWith settings: \n{'model_path': '/home/daniel.cox/stanfordnlp_resources/en_ewt_models/en_ewt_lemmatizer.pt', 'lang': 'en', 'shorthand': 'en_ewt', 'mode': 'predict'}\nBuilding an attentional Seq2Seq model...\nUsing a Bi-LSTM encoder\nUsing soft attention for LSTM.\nFinetune all embeddings.\n[Running seq2seq lemmatizer with edit classifier]\n---\nLoading: depparse\nWith settings: \n{'model_path': '/home/daniel.cox/stanfordnlp_resources/en_ewt_models/en_ewt_parser.pt', 'pretrain_path': '/home/daniel.cox/stanfordnlp_resources/en_ewt_models/en_ewt.pretrain.pt', 'lang': 'en', 'shorthand': 'en_ewt', 'mode': 'predict'}\nDone loading processors!\n---\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "doc = nlp(\"Barack Obama was born in Hawaii. He was elected president in 2008.\")", | |
"execution_count": 5, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": "/pytorch/aten/src/ATen/native/cuda/LegacyDefinitions.cpp:19: UserWarning: masked_fill_ received a mask with dtype torch.uint8, this behavior is now deprecated,please use a mask with dtype torch.bool instead.\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "doc.sentences[0].print_dependencies()", | |
"execution_count": 6, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "('Barack', '4', 'nsubj:pass')\n('Obama', '1', 'flat')\n('was', '4', 'aux:pass')\n('born', '0', 'root')\n('in', '6', 'case')\n('Hawaii', '4', 'obl')\n('.', '4', 'punct')\n" | |
} | |
] | |
} | |
], | |
"metadata": { | |
"gist": { | |
"id": "", | |
"data": { | |
"description": "StanfordNLP first impression", | |
"public": true | |
} | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3", | |
"language": "python" | |
}, | |
"language_info": { | |
"name": "python", | |
"version": "3.7.3", | |
"mimetype": "text/x-python", | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"pygments_lexer": "ipython3", | |
"nbconvert_exporter": "python", | |
"file_extension": ".py" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment