From bcd0634ba78a068237a5b06409c2b10ac7da0037 Mon Sep 17 00:00:00 2001 From: Nayan Kanaparthi <95455198+NayanKanaparthi@users.noreply.github.com> Date: Wed, 26 Jul 2023 14:29:45 +0530 Subject: [PATCH] Add files via upload --- 7_pos/POS.ipynb | 707 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 707 insertions(+) create mode 100644 7_pos/POS.ipynb diff --git a/7_pos/POS.ipynb b/7_pos/POS.ipynb new file mode 100644 index 0000000..50ab133 --- /dev/null +++ b/7_pos/POS.ipynb @@ -0,0 +1,707 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "760a36ea-2075-4d83-9b06-b729e3dd3874", + "metadata": {}, + "outputs": [], + "source": [ + "import spacy" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "01c633ab-e759-48ac-a8eb-5d3dfedfa377", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[('tok2vec', ),\n", + " ('tagger', ),\n", + " ('parser', ),\n", + " ('attribute_ruler',\n", + " ),\n", + " ('lemmatizer', ),\n", + " ('ner', )]" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "nlp = spacy.load(\"en_core_web_sm\")\n", + "nlp.pipeline" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "c6d7bd0f-a705-4c61-b841-65cc09df7677", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Elon | PROPN | proper noun | NNP | noun, proper singular\n", + "few | ADJ | adjective | JJ | adjective (English), other noun-modifier (Chinese)\n", + "to | PART | particle | TO | infinitival \"to\"\n", + "mars | NOUN | noun | NNS | noun, plural\n", + "yesterday | NOUN | noun | NN | noun, singular or mass\n", + ". | PUNCT | punctuation | . | punctuation mark, sentence closer\n", + "he | PRON | pronoun | PRP | pronoun, personal\n", + "took | VERB | verb | VBD | verb, past tense\n", + "Tesla | PROPN | proper noun | NNP | noun, proper singular\n", + "Roadster | PROPN | proper noun | NNP | noun, proper singular\n", + "with | ADP | adposition | IN | conjunction, subordinating or preposition\n", + "him | PRON | pronoun | PRP | pronoun, personal\n" + ] + } + ], + "source": [ + "doc = nlp(\"Elon few to mars yesterday. he took Tesla Roadster with him\")\n", + "\n", + "for token in doc:\n", + " print(token,'|',token.pos_,'|',spacy.explain(token.pos_),'|',token.tag_,'|',spacy.explain(token.tag_))" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "5eb116dc-b263-4fae-8262-adfd4fc9cdd0", + "metadata": {}, + "outputs": [], + "source": [ + "earnings_text = \"\"\" Microsoft Corp. today announced the following results for the quarter ended June 30, 2023, as compared to the corresponding period of last fiscal year:\n", + "\n", + "· Revenue was $56.2 billion and increased 8% (up 10% in constant currency)\n", + "\n", + "· Operating income was $24.3 billion and increased 18% etc (up 21% in constant currency)\n", + "\n", + "· Net income was $20.1 billion and increased 20% (up 23% in constant currency)\n", + "\n", + "· Diluted earnings per share was $2.69 and increased 21% (up 23% in constant currency)\"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "9014b725-fad6-473c-acd4-be37482fbc9c", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[Microsoft, Corp., today, announced, the, following, results, for, the, quarter, ended, June, 30, 2023, as, compared, to, the, corresponding, period, of, last, fiscal, year, Revenue, was, $, 56.2, billion, and, increased, 8, %, up, 10, %, in, constant, currency, Operating, income, was, $, 24.3, billion, and, increased, 18, %, up, 21, %, in, constant, currency, Net, income, was, $, 20.1, billion, and, increased, 20, %, up, 23, %, in, constant, currency, Diluted, earnings, per, share, was, $, 2.69, and, increased, 21, %, up, 23, %, in, constant, currency]\n" + ] + } + ], + "source": [ + "doc= nlp(earnings_text)\n", + "filtered_tokens=[]\n", + "for token in doc:\n", + " if token.pos_ not in [\"SPACE\",\"X\",\"PUNCT\"]:\n", + " filtered_tokens.append(token)\n", + " #print(token,'|',token.pos_,'|',spacy.explain(token.pos_))\n", + "print(filtered_tokens)" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "id": "b378975f-5255-47a2-9de8-fdeb6dbf594f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'PROPN'" + ] + }, + "execution_count": 29, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "count = doc.count_by(spacy.attrs.POS)\n", + "\n", + "doc.vocab[96].text" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "id": "d50c3bf2-a543-418d-a20d-62b1e7da0abc", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "SPACE | 9\n", + "PROPN | 3\n", + "NOUN | 22\n", + "VERB | 10\n", + "DET | 3\n", + "ADP | 8\n", + "NUM | 17\n", + "PUNCT | 15\n", + "SCONJ | 1\n", + "ADJ | 8\n", + "AUX | 4\n", + "SYM | 4\n", + "CCONJ | 4\n", + "ADV | 4\n", + "X | 1\n" + ] + } + ], + "source": [ + "for k,v in count.items():\n", + " print(doc.vocab[k].text,'|', v)" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "id": "9e3855aa-d38e-4fd2-8a18-785c45fc81ee", + "metadata": {}, + "outputs": [], + "source": [ + "## EXERCISE\n", + "\"\"Exercise for Spacy POS tutorial,\n", + "\n", + "You are parsing a news story from cnbc.com. News story is stores in news_story.txt which is available in this same folder on github. You need to,\n", + "Extract all NOUN tokens from this story. You will have to read the file in python first to collect all the text and then extract NOUNs in a python list\n", + "Extract all numbers (NUM POS type) in a python list\n", + "Print a count of all POS tags in this story\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "id": "06027630-2360-448c-b602-7885ead75c28", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Inflation rose again in April, continuing a climb that has pushed consumers to the brink and is threatening the economic expansion, the Bureau of Labor Statistics reported Wednesday.\\n \\n The consumer price index, a broad-based measure of prices for goods and services, increased 8.3% from a year ago, higher than the Dow Jones estimate for an 8.1% gain. That represented a slight ease from March’s peak but was still close to the highest level since the summer of 1982.\\n \\n Removing volatile food and energy prices, so-called core CPI still rose 6.2%, against expectations for a 6% gain, clouding hopes that inflation had peaked in March.\\n \\n The month-over-month gains also were higher than expectations — 0.3% on headline CPI versus the 0.2% estimate and a 0.6% increase for core, against the outlook for a 0.4% gain.\\n \\n The price gains also meant that workers continued to lose ground. Real wages adjusted for inflation decreased 0.1% on the month despite a nominal increase of 0.3% in average hourly earnings. Over the past year, real earnings have dropped 2.6% even though average hourly earnings are up 5.5%.\\n \\n Inflation has been the single biggest threat to a recovery that began early in the Covid pandemic and saw the economy in 2021 stage its biggest single-year growth level since 1984. Rising prices at the pump and in grocery stores have been one problem, but inflation has spread beyond those two areas into housing, auto sales and a host of other areas.\\n \\n Federal Reserve officials have responded to the problem with two interest rate hikes so far this year and pledges of more until inflation comes down to the central bank’s 2% goal. However, Wednesday’s data shows that the Fed has a big job ahead.\\n \\n Credits: cnbc.com'" + ] + }, + "execution_count": 41, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "with open(\"news_story.txt\") as file:\n", + " news_story = file.readlines()\n", + "news_story = ''.join(text)\n", + "news_story" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "id": "e35887a3-6b11-4e94-8e46-902195580d58", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Inflation | NOUN | noun\n", + "rose | VERB | verb\n", + "again | ADV | adverb\n", + "in | ADP | adposition\n", + "April | PROPN | proper noun\n", + ", | PUNCT | punctuation\n", + "continuing | VERB | verb\n", + "a | DET | determiner\n", + "climb | NOUN | noun\n", + "that | PRON | pronoun\n", + "has | AUX | auxiliary\n", + "pushed | VERB | verb\n", + "consumers | NOUN | noun\n", + "to | ADP | adposition\n", + "the | DET | determiner\n", + "brink | NOUN | noun\n", + "and | CCONJ | coordinating conjunction\n", + "is | AUX | auxiliary\n", + "threatening | VERB | verb\n", + "the | DET | determiner\n", + "economic | ADJ | adjective\n", + "expansion | NOUN | noun\n", + ", | PUNCT | punctuation\n", + "the | DET | determiner\n", + "Bureau | PROPN | proper noun\n", + "of | ADP | adposition\n", + "Labor | PROPN | proper noun\n", + "Statistics | PROPN | proper noun\n", + "reported | VERB | verb\n", + "Wednesday | PROPN | proper noun\n", + ". | PUNCT | punctuation\n", + "\n", + " \n", + " | SPACE | space\n", + "The | DET | determiner\n", + "consumer | NOUN | noun\n", + "price | NOUN | noun\n", + "index | NOUN | noun\n", + ", | PUNCT | punctuation\n", + "a | DET | determiner\n", + "broad | ADV | adverb\n", + "- | PUNCT | punctuation\n", + "based | VERB | verb\n", + "measure | NOUN | noun\n", + "of | ADP | adposition\n", + "prices | NOUN | noun\n", + "for | ADP | adposition\n", + "goods | NOUN | noun\n", + "and | CCONJ | coordinating conjunction\n", + "services | NOUN | noun\n", + ", | PUNCT | punctuation\n", + "increased | VERB | verb\n", + "8.3 | NUM | numeral\n", + "% | NOUN | noun\n", + "from | ADP | adposition\n", + "a | DET | determiner\n", + "year | NOUN | noun\n", + "ago | ADV | adverb\n", + ", | PUNCT | punctuation\n", + "higher | ADJ | adjective\n", + "than | ADP | adposition\n", + "the | DET | determiner\n", + "Dow | PROPN | proper noun\n", + "Jones | PROPN | proper noun\n", + "estimate | NOUN | noun\n", + "for | ADP | adposition\n", + "an | DET | determiner\n", + "8.1 | NUM | numeral\n", + "% | NOUN | noun\n", + "gain | NOUN | noun\n", + ". | PUNCT | punctuation\n", + "That | PRON | pronoun\n", + "represented | VERB | verb\n", + "a | DET | determiner\n", + "slight | ADJ | adjective\n", + "ease | NOUN | noun\n", + "from | ADP | adposition\n", + "March†| NOUN | noun\n", + "™ | NOUN | noun\n", + "s | PART | particle\n", + "peak | NOUN | noun\n", + "but | CCONJ | coordinating conjunction\n", + "was | AUX | auxiliary\n", + "still | ADV | adverb\n", + "close | ADJ | adjective\n", + "to | ADP | adposition\n", + "the | DET | determiner\n", + "highest | ADJ | adjective\n", + "level | NOUN | noun\n", + "since | SCONJ | subordinating conjunction\n", + "the | DET | determiner\n", + "summer | NOUN | noun\n", + "of | ADP | adposition\n", + "1982 | NUM | numeral\n", + ". | PUNCT | punctuation\n", + "\n", + " \n", + " | SPACE | space\n", + "Removing | VERB | verb\n", + "volatile | ADJ | adjective\n", + "food | NOUN | noun\n", + "and | CCONJ | coordinating conjunction\n", + "energy | NOUN | noun\n", + "prices | NOUN | noun\n", + ", | PUNCT | punctuation\n", + "so | ADV | adverb\n", + "- | PUNCT | punctuation\n", + "called | VERB | verb\n", + "core | NOUN | noun\n", + "CPI | PROPN | proper noun\n", + "still | ADV | adverb\n", + "rose | VERB | verb\n", + "6.2 | NUM | numeral\n", + "% | NOUN | noun\n", + ", | PUNCT | punctuation\n", + "against | ADP | adposition\n", + "expectations | NOUN | noun\n", + "for | ADP | adposition\n", + "a | DET | determiner\n", + "6 | NUM | numeral\n", + "% | NOUN | noun\n", + "gain | NOUN | noun\n", + ", | PUNCT | punctuation\n", + "clouding | VERB | verb\n", + "hopes | NOUN | noun\n", + "that | SCONJ | subordinating conjunction\n", + "inflation | NOUN | noun\n", + "had | AUX | auxiliary\n", + "peaked | VERB | verb\n", + "in | ADP | adposition\n", + "March | PROPN | proper noun\n", + ". | PUNCT | punctuation\n", + "\n", + " \n", + " | SPACE | space\n", + "The | DET | determiner\n", + "month | NOUN | noun\n", + "- | PUNCT | punctuation\n", + "over | ADP | adposition\n", + "- | PUNCT | punctuation\n", + "month | NOUN | noun\n", + "gains | NOUN | noun\n", + "also | ADV | adverb\n", + "were | AUX | auxiliary\n", + "higher | ADJ | adjective\n", + "than | ADP | adposition\n", + "expectations | NOUN | noun\n", + "†| NUM | numeral\n", + "” | PUNCT | punctuation\n", + "0.3 | NUM | numeral\n", + "% | NOUN | noun\n", + "on | ADP | adposition\n", + "headline | NOUN | noun\n", + "CPI | PROPN | proper noun\n", + "versus | ADP | adposition\n", + "the | DET | determiner\n", + "0.2 | NUM | numeral\n", + "% | NOUN | noun\n", + "estimate | NOUN | noun\n", + "and | CCONJ | coordinating conjunction\n", + "a | DET | determiner\n", + "0.6 | NUM | numeral\n", + "% | NOUN | noun\n", + "increase | NOUN | noun\n", + "for | ADP | adposition\n", + "core | NOUN | noun\n", + ", | PUNCT | punctuation\n", + "against | ADP | adposition\n", + "the | DET | determiner\n", + "outlook | NOUN | noun\n", + "for | ADP | adposition\n", + "a | DET | determiner\n", + "0.4 | NUM | numeral\n", + "% | NOUN | noun\n", + "gain | NOUN | noun\n", + ". | PUNCT | punctuation\n", + "\n", + " \n", + " | SPACE | space\n", + "The | DET | determiner\n", + "price | NOUN | noun\n", + "gains | NOUN | noun\n", + "also | ADV | adverb\n", + "meant | VERB | verb\n", + "that | SCONJ | subordinating conjunction\n", + "workers | NOUN | noun\n", + "continued | VERB | verb\n", + "to | PART | particle\n", + "lose | VERB | verb\n", + "ground | NOUN | noun\n", + ". | PUNCT | punctuation\n", + "Real | ADJ | adjective\n", + "wages | NOUN | noun\n", + "adjusted | VERB | verb\n", + "for | ADP | adposition\n", + "inflation | NOUN | noun\n", + "decreased | VERB | verb\n", + "0.1 | NUM | numeral\n", + "% | NOUN | noun\n", + "on | ADP | adposition\n", + "the | DET | determiner\n", + "month | NOUN | noun\n", + "despite | SCONJ | subordinating conjunction\n", + "a | DET | determiner\n", + "nominal | ADJ | adjective\n", + "increase | NOUN | noun\n", + "of | ADP | adposition\n", + "0.3 | NUM | numeral\n", + "% | NOUN | noun\n", + "in | ADP | adposition\n", + "average | ADJ | adjective\n", + "hourly | ADJ | adjective\n", + "earnings | NOUN | noun\n", + ". | PUNCT | punctuation\n", + "Over | ADP | adposition\n", + "the | DET | determiner\n", + "past | ADJ | adjective\n", + "year | NOUN | noun\n", + ", | PUNCT | punctuation\n", + "real | ADJ | adjective\n", + "earnings | NOUN | noun\n", + "have | AUX | auxiliary\n", + "dropped | VERB | verb\n", + "2.6 | NUM | numeral\n", + "% | NOUN | noun\n", + "even | ADV | adverb\n", + "though | SCONJ | subordinating conjunction\n", + "average | ADJ | adjective\n", + "hourly | ADJ | adjective\n", + "earnings | NOUN | noun\n", + "are | AUX | auxiliary\n", + "up | ADV | adverb\n", + "5.5 | NUM | numeral\n", + "% | NOUN | noun\n", + ". | PUNCT | punctuation\n", + "\n", + " \n", + " | SPACE | space\n", + "Inflation | NOUN | noun\n", + "has | AUX | auxiliary\n", + "been | AUX | auxiliary\n", + "the | DET | determiner\n", + "single | ADJ | adjective\n", + "biggest | ADJ | adjective\n", + "threat | NOUN | noun\n", + "to | ADP | adposition\n", + "a | DET | determiner\n", + "recovery | NOUN | noun\n", + "that | PRON | pronoun\n", + "began | VERB | verb\n", + "early | ADV | adverb\n", + "in | ADP | adposition\n", + "the | DET | determiner\n", + "Covid | PROPN | proper noun\n", + "pandemic | NOUN | noun\n", + "and | CCONJ | coordinating conjunction\n", + "saw | VERB | verb\n", + "the | DET | determiner\n", + "economy | NOUN | noun\n", + "in | ADP | adposition\n", + "2021 | NUM | numeral\n", + "stage | NOUN | noun\n", + "its | PRON | pronoun\n", + "biggest | ADJ | adjective\n", + "single | ADJ | adjective\n", + "- | PUNCT | punctuation\n", + "year | NOUN | noun\n", + "growth | NOUN | noun\n", + "level | NOUN | noun\n", + "since | SCONJ | subordinating conjunction\n", + "1984 | NUM | numeral\n", + ". | PUNCT | punctuation\n", + "Rising | VERB | verb\n", + "prices | NOUN | noun\n", + "at | ADP | adposition\n", + "the | DET | determiner\n", + "pump | NOUN | noun\n", + "and | CCONJ | coordinating conjunction\n", + "in | ADP | adposition\n", + "grocery | NOUN | noun\n", + "stores | NOUN | noun\n", + "have | AUX | auxiliary\n", + "been | AUX | auxiliary\n", + "one | NUM | numeral\n", + "problem | NOUN | noun\n", + ", | PUNCT | punctuation\n", + "but | CCONJ | coordinating conjunction\n", + "inflation | NOUN | noun\n", + "has | AUX | auxiliary\n", + "spread | VERB | verb\n", + "beyond | ADP | adposition\n", + "those | DET | determiner\n", + "two | NUM | numeral\n", + "areas | NOUN | noun\n", + "into | ADP | adposition\n", + "housing | NOUN | noun\n", + ", | PUNCT | punctuation\n", + "auto | NOUN | noun\n", + "sales | NOUN | noun\n", + "and | CCONJ | coordinating conjunction\n", + "a | DET | determiner\n", + "host | NOUN | noun\n", + "of | ADP | adposition\n", + "other | ADJ | adjective\n", + "areas | NOUN | noun\n", + ". | PUNCT | punctuation\n", + "\n", + " \n", + " | SPACE | space\n", + "Federal | PROPN | proper noun\n", + "Reserve | PROPN | proper noun\n", + "officials | NOUN | noun\n", + "have | AUX | auxiliary\n", + "responded | VERB | verb\n", + "to | ADP | adposition\n", + "the | DET | determiner\n", + "problem | NOUN | noun\n", + "with | ADP | adposition\n", + "two | NUM | numeral\n", + "interest | NOUN | noun\n", + "rate | NOUN | noun\n", + "hikes | NOUN | noun\n", + "so | ADV | adverb\n", + "far | ADV | adverb\n", + "this | DET | determiner\n", + "year | NOUN | noun\n", + "and | CCONJ | coordinating conjunction\n", + "pledges | NOUN | noun\n", + "of | ADP | adposition\n", + "more | ADJ | adjective\n", + "until | SCONJ | subordinating conjunction\n", + "inflation | NOUN | noun\n", + "comes | VERB | verb\n", + "down | ADP | adposition\n", + "to | ADP | adposition\n", + "the | DET | determiner\n", + "central | ADJ | adjective\n", + "bank†| PROPN | proper noun\n", + "™ | PROPN | proper noun\n", + "s | PART | particle\n", + "2 | NUM | numeral\n", + "% | NOUN | noun\n", + "goal | NOUN | noun\n", + ". | PUNCT | punctuation\n", + "However | ADV | adverb\n", + ", | PUNCT | punctuation\n", + "Wednesday†| PROPN | proper noun\n", + "™ | NOUN | noun\n", + "s | PART | particle\n", + "data | NOUN | noun\n", + "shows | VERB | verb\n", + "that | SCONJ | subordinating conjunction\n", + "the | DET | determiner\n", + "Fed | PROPN | proper noun\n", + "has | VERB | verb\n", + "a | DET | determiner\n", + "big | ADJ | adjective\n", + "job | NOUN | noun\n", + "ahead | ADV | adverb\n", + ". | PUNCT | punctuation\n", + "\n", + " \n", + " | SPACE | space\n", + "Credits | NOUN | noun\n", + ": | PUNCT | punctuation\n", + "cnbc.com | X | other\n" + ] + } + ], + "source": [ + "doc = nlp(news_story)\n", + "\n", + "for token in doc:\n", + " print(token,'|',token.pos_,'|',spacy.explain(token.pos_))" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "id": "d61875d2-3f4b-4372-ad7a-7bb67ad25626", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[Inflation, climb, consumers, brink, expansion, consumer, price, index, measure, prices, goods, services, %, year, estimate, %, gain, ease, Marchâ€, ™, peak, level, summer, food, energy, prices, core, %, expectations, %, gain, hopes, inflation, month, month, gains, expectations, %, headline, %, estimate, %, increase, core, outlook, %, gain, price, gains, workers, ground, wages, inflation, %, month, increase, %, earnings, year, earnings, %, earnings, %, Inflation, threat, recovery, pandemic, economy, stage, year, growth, level, prices, pump, grocery, stores, problem, inflation, areas, housing, auto, sales, host, areas, officials, problem, interest, rate, hikes, year, pledges, inflation, %, goal, ™, data, job, Credits]\n" + ] + } + ], + "source": [ + "noun=[]\n", + "for token in doc:\n", + " if token.pos_ in [\"NOUN\"]:\n", + " noun.append(token)\n", + "print(noun)" + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "id": "4bb592c0-ad3a-4b44-b643-b73b43d995e1", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[8.3, 8.1, 1982, 6.2, 6, â€, 0.3, 0.2, 0.6, 0.4, 0.1, 0.3, 2.6, 5.5, 2021, 1984, one, two, two, 2]\n" + ] + } + ], + "source": [ + "numbers=[]\n", + "for token in doc:\n", + " if token.pos_ in [\"NUM\"]:\n", + " numbers.append(token)\n", + "print(numbers)" + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "id": "c3a1a507-3e2c-40ca-a635-1400ff767e8e", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "NOUN | 98\n", + "VERB | 27\n", + "ADV | 15\n", + "ADP | 39\n", + "PROPN | 17\n", + "PUNCT | 32\n", + "DET | 34\n", + "PRON | 4\n", + "AUX | 13\n", + "CCONJ | 10\n", + "ADJ | 23\n", + "SPACE | 7\n", + "NUM | 20\n", + "PART | 4\n", + "SCONJ | 8\n", + "X | 1\n" + ] + } + ], + "source": [ + "count=doc.count_by(spacy.attrs.POS)\n", + "\n", + "for k,v in count.items():\n", + " print(doc.vocab[k].text,\"|\",v)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "71b0b5eb-46d4-4f83-9d3f-06c5657f1609", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "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.11.4" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}