categorization
This commit is contained in:
parent
80306a2b67
commit
aeddf33138
11 changed files with 7118 additions and 452 deletions
700
fetchDatafromDb/Multiclasstextclasification.ipynb
Normal file
700
fetchDatafromDb/Multiclasstextclasification.ipynb
Normal file
|
|
@ -0,0 +1,700 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 16,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"\"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ .,;'0123456789\""
|
||||
]
|
||||
},
|
||||
"execution_count": 16,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import unicodedata\n",
|
||||
"import string\n",
|
||||
"import pandas as pd\n",
|
||||
"import re\n",
|
||||
"import numpy as np\n",
|
||||
"\n",
|
||||
"import sklearn\n",
|
||||
"import matplotlib.pyplot as plt\n",
|
||||
"import seaborn as sns\n",
|
||||
"\n",
|
||||
"all_letters = string.ascii_letters + \" .,;'0123456789\"\n",
|
||||
"n_letters = len(all_letters)\n",
|
||||
"\n",
|
||||
"all_letters"
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Build Category dictionary, category and list of product name, shor description"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from elasticsearch import Elasticsearch\n",
|
||||
"client = Elasticsearch(\"http://172.17.212.35:9200\")\n",
|
||||
"resp = client.search(index=\"retromotion-indexer_development_products\",\n",
|
||||
" body={\"_source\":[\"descriptions\",\"descriptionsSource\",\"nameSource\",\"shortDescriptionSource\",\"categoriesSource\"],\n",
|
||||
" \"query\": {\"match_all\": {}}})"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"df_eng = pd.DataFrame(columns=['name','sdesc','category','catlevel0','catlevel1','catlevel2','catlevel3','catlevel4','catlevel5'])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def cleanStr(text):\n",
|
||||
" \n",
|
||||
" # remove numbers\n",
|
||||
" # no_number_string = re.sub(r'\\d+','',lower_string)\n",
|
||||
"\n",
|
||||
" # remove all punctuation except words and space\n",
|
||||
" # text = re.sub(r'[^\\w\\s]','', lower_string)\n",
|
||||
"\n",
|
||||
" # clean = re.compile('<.*?>')\n",
|
||||
"\n",
|
||||
" # text = re.sub(clean,'',text)\n",
|
||||
" text = re.sub('<[^>]*>', '', text)\n",
|
||||
" emoticons = re.findall('(?::|;|=)(?:-)?(?:\\)|\\(|D|P)', text)\n",
|
||||
" text = (re.sub('[\\W]+', ' ', text.lower()) + ' ' .join(emoticons).replace('-', ''))\n",
|
||||
"\n",
|
||||
" return text\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"name_en=[]\n",
|
||||
"name_de=[]\n",
|
||||
"\n",
|
||||
"sdesc_en=[]\n",
|
||||
"sdesc_de=[]\n",
|
||||
"\n",
|
||||
"desc_en=[]\n",
|
||||
"desc_de=[]\n",
|
||||
"\n",
|
||||
"cat_en=[]\n",
|
||||
"cat_de=[]\n",
|
||||
"\n",
|
||||
"catpath_en=[]\n",
|
||||
"catpath_de=[]\n",
|
||||
"\n",
|
||||
"for hit in resp['hits']['hits']:\n",
|
||||
" list_row =[]\n",
|
||||
" for name in hit['_source']['nameSource']:\n",
|
||||
" if (name[\"language\"]==\"en\"):\n",
|
||||
" list_row.append(cleanStr(name[\"value\"]))\n",
|
||||
" else:\n",
|
||||
" name_de.append(name[\"value\"])\n",
|
||||
" \n",
|
||||
" for sdesc in hit['_source']['shortDescriptionSource']:\n",
|
||||
" if (sdesc[\"language\"]==\"en\"):\n",
|
||||
" list_row.append(cleanStr(sdesc[\"value\"]))\n",
|
||||
" else:\n",
|
||||
" sdesc_de.append(sdesc[\"value\"])\n",
|
||||
"\n",
|
||||
" # for desc in hit['_source']['descriptionsSource']:\n",
|
||||
" # if (desc[\"language\"]==\"en\"):\n",
|
||||
" # desc_en.append(readHtml(desc[\"value\"]))\n",
|
||||
" # else:\n",
|
||||
" # desc_de.append(desc[\"value\"])\n",
|
||||
" \n",
|
||||
" for cats in hit['_source']['categoriesSource']:\n",
|
||||
" if (cats[\"language\"]==\"en\"):\n",
|
||||
" list_row.append(cleanStr(cats[\"label\"]))\n",
|
||||
" else:\n",
|
||||
" desc_de.append(cats[\"label\"])\n",
|
||||
"\n",
|
||||
" if (cats[\"language\"]==\"en\"):\n",
|
||||
" categories =cats[\"path\"].split('/')\n",
|
||||
" i =0\n",
|
||||
" catls=[]\n",
|
||||
" for category in categories:\n",
|
||||
"\n",
|
||||
" list_row.append(cleanStr(category))\n",
|
||||
" i= i+1\n",
|
||||
" \n",
|
||||
" else:\n",
|
||||
" catpath_de.append(cats[\"path\"])\n",
|
||||
" \n",
|
||||
" # new_row = pd.DataFrame({'name':_name, 'sdesc':_sdesc, 'category':_cat_en }, index=[0])\n",
|
||||
"\n",
|
||||
" # pd.concat([new_row,df_eng.loc[:]]).reset_index(drop=True)\n",
|
||||
"\n",
|
||||
" for i in range (0,9-len(list_row)):\n",
|
||||
" list_row.append(np.nan)\n",
|
||||
"\n",
|
||||
" df_eng.loc[len(df_eng)] = list_row\n",
|
||||
"\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 7,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<div>\n",
|
||||
"<style scoped>\n",
|
||||
" .dataframe tbody tr th:only-of-type {\n",
|
||||
" vertical-align: middle;\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" .dataframe tbody tr th {\n",
|
||||
" vertical-align: top;\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" .dataframe thead th {\n",
|
||||
" text-align: right;\n",
|
||||
" }\n",
|
||||
"</style>\n",
|
||||
"<table border=\"1\" class=\"dataframe\">\n",
|
||||
" <thead>\n",
|
||||
" <tr style=\"text-align: right;\">\n",
|
||||
" <th></th>\n",
|
||||
" <th>name</th>\n",
|
||||
" <th>sdesc</th>\n",
|
||||
" <th>category</th>\n",
|
||||
" <th>catlevel0</th>\n",
|
||||
" <th>catlevel1</th>\n",
|
||||
" <th>catlevel2</th>\n",
|
||||
" <th>catlevel3</th>\n",
|
||||
" <th>catlevel4</th>\n",
|
||||
" <th>catlevel5</th>\n",
|
||||
" </tr>\n",
|
||||
" </thead>\n",
|
||||
" <tbody>\n",
|
||||
" <tr>\n",
|
||||
" <th>0</th>\n",
|
||||
" <td>denso dtm82363 thermostat coolant</td>\n",
|
||||
" <td>thermostat coolant</td>\n",
|
||||
" <td>thermostat</td>\n",
|
||||
" <td>sparepart</td>\n",
|
||||
" <td>cooling system</td>\n",
|
||||
" <td>thermostat</td>\n",
|
||||
" <td>NaN</td>\n",
|
||||
" <td>NaN</td>\n",
|
||||
" <td>NaN</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>1</th>\n",
|
||||
" <td>zf 1043 010 297 automatic transmission</td>\n",
|
||||
" <td>automatic transmission</td>\n",
|
||||
" <td>automatic transmission</td>\n",
|
||||
" <td>sparepart</td>\n",
|
||||
" <td>transmission</td>\n",
|
||||
" <td>automatic transmission</td>\n",
|
||||
" <td>automatic transmission</td>\n",
|
||||
" <td>NaN</td>\n",
|
||||
" <td>NaN</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>2</th>\n",
|
||||
" <td>zf 1060 040 003 automatic transmission</td>\n",
|
||||
" <td>automatic transmission</td>\n",
|
||||
" <td>automatic transmission</td>\n",
|
||||
" <td>sparepart</td>\n",
|
||||
" <td>transmission</td>\n",
|
||||
" <td>automatic transmission</td>\n",
|
||||
" <td>automatic transmission</td>\n",
|
||||
" <td>NaN</td>\n",
|
||||
" <td>NaN</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>3</th>\n",
|
||||
" <td>vaico v10 0131 camshaft</td>\n",
|
||||
" <td>camshaft</td>\n",
|
||||
" <td>camshaft</td>\n",
|
||||
" <td>sparepart</td>\n",
|
||||
" <td>engine</td>\n",
|
||||
" <td>engine timing</td>\n",
|
||||
" <td>camshaft</td>\n",
|
||||
" <td>NaN</td>\n",
|
||||
" <td>NaN</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>4</th>\n",
|
||||
" <td>vaico v26 0302 track control arm</td>\n",
|
||||
" <td>track control arm</td>\n",
|
||||
" <td>track control arm</td>\n",
|
||||
" <td>sparepart</td>\n",
|
||||
" <td>powertrain suspension</td>\n",
|
||||
" <td>wheel suspension</td>\n",
|
||||
" <td>track control arm</td>\n",
|
||||
" <td>NaN</td>\n",
|
||||
" <td>NaN</td>\n",
|
||||
" </tr>\n",
|
||||
" </tbody>\n",
|
||||
"</table>\n",
|
||||
"</div>"
|
||||
],
|
||||
"text/plain": [
|
||||
" name sdesc \\\n",
|
||||
"0 denso dtm82363 thermostat coolant thermostat coolant \n",
|
||||
"1 zf 1043 010 297 automatic transmission automatic transmission \n",
|
||||
"2 zf 1060 040 003 automatic transmission automatic transmission \n",
|
||||
"3 vaico v10 0131 camshaft camshaft \n",
|
||||
"4 vaico v26 0302 track control arm track control arm \n",
|
||||
"\n",
|
||||
" category catlevel0 catlevel1 \\\n",
|
||||
"0 thermostat sparepart cooling system \n",
|
||||
"1 automatic transmission sparepart transmission \n",
|
||||
"2 automatic transmission sparepart transmission \n",
|
||||
"3 camshaft sparepart engine \n",
|
||||
"4 track control arm sparepart powertrain suspension \n",
|
||||
"\n",
|
||||
" catlevel2 catlevel3 catlevel4 catlevel5 \n",
|
||||
"0 thermostat NaN NaN NaN \n",
|
||||
"1 automatic transmission automatic transmission NaN NaN \n",
|
||||
"2 automatic transmission automatic transmission NaN NaN \n",
|
||||
"3 engine timing camshaft NaN NaN \n",
|
||||
"4 wheel suspension track control arm NaN NaN "
|
||||
]
|
||||
},
|
||||
"execution_count": 7,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"df_eng.head()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 54,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"df_category = df_eng.groupby('category')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 46,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"1 zf 1043 010 297 automatic transmission\n",
|
||||
"2 zf 1060 040 003 automatic transmission\n",
|
||||
"Name: name, dtype: object"
|
||||
]
|
||||
},
|
||||
"execution_count": 46,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"category.get_group('automatic transmission')['name']\n",
|
||||
"\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 55,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Result:\n",
|
||||
" dict_keys(['automatic transmission', 'camshaft', 'mounting', 'shock absorber', 'suspension kit', 'tensioner pulley', 'thermostat', 'track control arm', 'wheel hub'])\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# extract keys from groups\n",
|
||||
"keys = df_category.groups.keys()\n",
|
||||
"# for i in keys:\n",
|
||||
"# print(category.get_group(i))\n",
|
||||
"# print('\\n')\n",
|
||||
"\n",
|
||||
" # Display result\n",
|
||||
"\n",
|
||||
"all_categories=list(keys)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"#### Turning product Names into Tensors\n",
|
||||
" \t \n",
|
||||
"Represent each name in one-hot encoded form (1 for the position of the letter, 0 elsewhere)\n",
|
||||
"\n",
|
||||
"To make a word we join a bunch of those into a 2D matrix <line_length x 1 x n_letters>.\n",
|
||||
"That extra 1 dimension is because PyTorch assumes everything is in batches - we're just using a batch size of 1 here."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 17,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import torch"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 18,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def letterToTensor(letter):\n",
|
||||
" \n",
|
||||
" tensor = torch.zeros(1, n_letters)\n",
|
||||
" tensor[0][all_letters.find(letter)] = 1\n",
|
||||
" \n",
|
||||
" return tensor"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 19,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"tensor([[1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,\n",
|
||||
" 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,\n",
|
||||
" 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,\n",
|
||||
" 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]])\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"print(letterToTensor('a'))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 20,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def nameToTensor(name):\n",
|
||||
" tensor = torch.zeros(len(name), 1, n_letters)\n",
|
||||
" \n",
|
||||
" for li, letter in enumerate(name):\n",
|
||||
" tensor[li][0][all_letters.find(letter)] = 1\n",
|
||||
" \n",
|
||||
" return tensor"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 21,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"torch.Size([33, 1, 67])"
|
||||
]
|
||||
},
|
||||
"execution_count": 21,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"p_tensor = nameToTensor('denso dtm82363 thermostat coolant')\n",
|
||||
"\n",
|
||||
"p_tensor.size()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 22,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"tensor([[[0., 0., 0., ..., 0., 0., 0.]],\n",
|
||||
"\n",
|
||||
" [[0., 0., 0., ..., 0., 0., 0.]],\n",
|
||||
"\n",
|
||||
" [[0., 0., 0., ..., 0., 0., 0.]],\n",
|
||||
"\n",
|
||||
" ...,\n",
|
||||
"\n",
|
||||
" [[1., 0., 0., ..., 0., 0., 0.]],\n",
|
||||
"\n",
|
||||
" [[0., 0., 0., ..., 0., 0., 0.]],\n",
|
||||
"\n",
|
||||
" [[0., 0., 0., ..., 0., 0., 0.]]])"
|
||||
]
|
||||
},
|
||||
"execution_count": 22,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"p_tensor"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 23,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import torch.nn as nn\n",
|
||||
"\n",
|
||||
"class RNN(nn.Module):\n",
|
||||
" \n",
|
||||
" def __init__(self, input_size, hidden_size, output_size):\n",
|
||||
" \n",
|
||||
" super(RNN, self).__init__()\n",
|
||||
"\n",
|
||||
" self.hidden_size = hidden_size\n",
|
||||
"\n",
|
||||
" self.i2h = nn.Linear(input_size + hidden_size, hidden_size)\n",
|
||||
" \n",
|
||||
" self.i2o = nn.Linear(input_size + hidden_size, output_size)\n",
|
||||
" \n",
|
||||
" self.softmax = nn.LogSoftmax(dim=1)\n",
|
||||
"\n",
|
||||
" def forward(self, input, hidden):\n",
|
||||
" combined = torch.cat((input, hidden), 1)\n",
|
||||
" \n",
|
||||
" hidden = self.i2h(combined)\n",
|
||||
" \n",
|
||||
" output = self.i2o(combined)\n",
|
||||
" output = self.softmax(output)\n",
|
||||
" \n",
|
||||
" return output, hidden\n",
|
||||
"\n",
|
||||
" def initHidden(self):\n",
|
||||
" return torch.zeros(1, self.hidden_size)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 28,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"n_hidden = 256\n",
|
||||
"n_category = len(category)\n",
|
||||
"\n",
|
||||
"rnn = RNN(n_letters, n_hidden, n_category)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 29,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"output size = torch.Size([1, 9])\n",
|
||||
"next_hidden size = torch.Size([1, 256])\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"inp = letterToTensor('C')\n",
|
||||
"\n",
|
||||
"hidden = torch.zeros(1, n_hidden)\n",
|
||||
"\n",
|
||||
"output, next_hidden = rnn(inp, hidden)\n",
|
||||
"\n",
|
||||
"print('output size =', output.size())\n",
|
||||
"print('next_hidden size =', next_hidden.size())"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 30,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"inp = nameToTensor('denso dtm82363 thermostat coolant')\n",
|
||||
"\n",
|
||||
"hidden = torch.zeros(1, n_hidden)\n",
|
||||
"\n",
|
||||
"output, next_hidden = rnn(inp[0], hidden)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 31,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"tensor([[-2.2812, -2.2042, -2.2270, -2.1712, -2.1616, -2.1168, -2.2543, -2.1659,\n",
|
||||
" -2.2031]], grad_fn=<LogSoftmaxBackward0>)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"print(output)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 44,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def categoryFromOutput(output):\n",
|
||||
" \n",
|
||||
" _, top_i = output.topk(1)\n",
|
||||
" \n",
|
||||
" cat_i = top_i[0].item()\n",
|
||||
" \n",
|
||||
" return all_categories[cat_i], cat_i"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 45,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"('tensioner pulley', 5)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"print(categoryFromOutput(output))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"#### get training samples category and names"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 51,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import random\n",
|
||||
"\n",
|
||||
"def randomTrainingExample():\n",
|
||||
" \n",
|
||||
" random_cat_index = random.randint(0, n_category - 1)\n",
|
||||
" randcategory = all_categories[random_cat_index]\n",
|
||||
" \n",
|
||||
" # get feature name from the category\n",
|
||||
" random_feature_names = category.get_group(randcategory)['name']\n",
|
||||
" \n",
|
||||
" name = random_feature_names[random.randint(0, len(random_feature_names) - 1)]\n",
|
||||
" \n",
|
||||
" category_tensor = torch.tensor([all_categories.index(randcategory)], dtype=torch.long)\n",
|
||||
" name_tensor = nameToTensor(name)\n",
|
||||
" \n",
|
||||
" return randcategory, name, category_tensor, name_tensor"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 53,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"ename": "AttributeError",
|
||||
"evalue": "'str' object has no attribute 'get_group'",
|
||||
"output_type": "error",
|
||||
"traceback": [
|
||||
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
||||
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
|
||||
"Cell \u001b[0;32mIn[53], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[39mfor\u001b[39;00m i \u001b[39min\u001b[39;00m \u001b[39mrange\u001b[39m(\u001b[39m10\u001b[39m):\n\u001b[0;32m----> 2\u001b[0m category, name, category_tensor, name_tensor \u001b[39m=\u001b[39m randomTrainingExample()\n\u001b[1;32m 4\u001b[0m \u001b[39mprint\u001b[39m(\u001b[39m'\u001b[39m\u001b[39mcategory =\u001b[39m\u001b[39m'\u001b[39m, category, \u001b[39m'\u001b[39m\u001b[39m, name =\u001b[39m\u001b[39m'\u001b[39m, name)\n",
|
||||
"Cell \u001b[0;32mIn[51], line 9\u001b[0m, in \u001b[0;36mrandomTrainingExample\u001b[0;34m()\u001b[0m\n\u001b[1;32m 6\u001b[0m randcategory \u001b[39m=\u001b[39m all_categories[random_cat_index]\n\u001b[1;32m 8\u001b[0m \u001b[39m# get feature name from the category\u001b[39;00m\n\u001b[0;32m----> 9\u001b[0m random_feature_names \u001b[39m=\u001b[39m category\u001b[39m.\u001b[39;49mget_group(randcategory)[\u001b[39m'\u001b[39m\u001b[39mname\u001b[39m\u001b[39m'\u001b[39m]\n\u001b[1;32m 11\u001b[0m name \u001b[39m=\u001b[39m random_feature_names[random\u001b[39m.\u001b[39mrandint(\u001b[39m0\u001b[39m, \u001b[39mlen\u001b[39m(random_feature_names) \u001b[39m-\u001b[39m \u001b[39m1\u001b[39m)]\n\u001b[1;32m 13\u001b[0m category_tensor \u001b[39m=\u001b[39m torch\u001b[39m.\u001b[39mtensor([all_categories\u001b[39m.\u001b[39mindex(randcategory)], dtype\u001b[39m=\u001b[39mtorch\u001b[39m.\u001b[39mlong)\n",
|
||||
"\u001b[0;31mAttributeError\u001b[0m: 'str' object has no attribute 'get_group'"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"for i in range(10):\n",
|
||||
" category, name, category_tensor, name_tensor = randomTrainingExample()\n",
|
||||
" \n",
|
||||
" print('category =', category, ', name =', name)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": ".venv",
|
||||
"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.10.12"
|
||||
},
|
||||
"orig_nbformat": 4
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
118
fetchDatafromDb/NLTKdependency.ipynb
Normal file
118
fetchDatafromDb/NLTKdependency.ipynb
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Collecting nltk\n",
|
||||
" Downloading nltk-3.8.1-py3-none-any.whl (1.5 MB)\n",
|
||||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.5/1.5 MB\u001b[0m \u001b[31m1.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m0m\n",
|
||||
"\u001b[?25hCollecting click\n",
|
||||
" Downloading click-8.1.3-py3-none-any.whl (96 kB)\n",
|
||||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m96.6/96.6 kB\u001b[0m \u001b[31m787.1 kB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m \u001b[36m0:00:01\u001b[0m\n",
|
||||
"\u001b[?25hRequirement already satisfied: joblib in /home/shoney/dev/.venv/lib/python3.10/site-packages (from nltk) (1.2.0)\n",
|
||||
"Collecting regex>=2021.8.3\n",
|
||||
" Downloading regex-2023.6.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (770 kB)\n",
|
||||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m770.4/770.4 kB\u001b[0m \u001b[31m1.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n",
|
||||
"\u001b[?25hCollecting tqdm\n",
|
||||
" Downloading tqdm-4.65.0-py3-none-any.whl (77 kB)\n",
|
||||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m77.1/77.1 kB\u001b[0m \u001b[31m779.0 kB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m \u001b[36m0:00:01\u001b[0m\n",
|
||||
"\u001b[?25hInstalling collected packages: tqdm, regex, click, nltk\n",
|
||||
"Successfully installed click-8.1.3 nltk-3.8.1 regex-2023.6.3 tqdm-4.65.0\n",
|
||||
"\n",
|
||||
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.0.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m23.1.2\u001b[0m\n",
|
||||
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"!python -m pip install nltk"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from nltk.grammar import DependencyGrammar"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from nltk.parse import (\n",
|
||||
"DependencyGraph,\n",
|
||||
"ProjectiveDependencyParser,\n",
|
||||
"NonprojectiveDependencyParser,\n",
|
||||
" )"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"ename": "ValueError",
|
||||
"evalue": "Number of tab-delimited fields (5) not supported by CoNLL(10) or Malt-Tab(4) format",
|
||||
"output_type": "error",
|
||||
"traceback": [
|
||||
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
||||
"\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)",
|
||||
"File \u001b[0;32m~/dev/.venv/lib/python3.10/site-packages/nltk/parse/dependencygraph.py:329\u001b[0m, in \u001b[0;36mDependencyGraph._parse\u001b[0;34m(self, input_, cell_extractor, zero_based, cell_separator, top_relation_label)\u001b[0m\n\u001b[1;32m 328\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[0;32m--> 329\u001b[0m cell_extractor \u001b[39m=\u001b[39m extractors[cell_number]\n\u001b[1;32m 330\u001b[0m \u001b[39mexcept\u001b[39;00m \u001b[39mKeyError\u001b[39;00m \u001b[39mas\u001b[39;00m e:\n",
|
||||
"\u001b[0;31mKeyError\u001b[0m: 5",
|
||||
"\nThe above exception was the direct cause of the following exception:\n",
|
||||
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
|
||||
"Cell \u001b[0;32mIn[6], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m treebank_data \u001b[39m=\u001b[39m\u001b[39m\"\"\"\u001b[39m\u001b[39mvaico v10 4245 shock absorber\u001b[39m\u001b[39m\"\"\"\u001b[39m\n\u001b[0;32m----> 2\u001b[0m dg \u001b[39m=\u001b[39m DependencyGraph(treebank_data)\n\u001b[1;32m 3\u001b[0m dg\u001b[39m.\u001b[39mtree()\u001b[39m.\u001b[39mpprint()\n",
|
||||
"File \u001b[0;32m~/dev/.venv/lib/python3.10/site-packages/nltk/parse/dependencygraph.py:79\u001b[0m, in \u001b[0;36mDependencyGraph.__init__\u001b[0;34m(self, tree_str, cell_extractor, zero_based, cell_separator, top_relation_label)\u001b[0m\n\u001b[1;32m 76\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mroot \u001b[39m=\u001b[39m \u001b[39mNone\u001b[39;00m\n\u001b[1;32m 78\u001b[0m \u001b[39mif\u001b[39;00m tree_str:\n\u001b[0;32m---> 79\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_parse(\n\u001b[1;32m 80\u001b[0m tree_str,\n\u001b[1;32m 81\u001b[0m cell_extractor\u001b[39m=\u001b[39;49mcell_extractor,\n\u001b[1;32m 82\u001b[0m zero_based\u001b[39m=\u001b[39;49mzero_based,\n\u001b[1;32m 83\u001b[0m cell_separator\u001b[39m=\u001b[39;49mcell_separator,\n\u001b[1;32m 84\u001b[0m top_relation_label\u001b[39m=\u001b[39;49mtop_relation_label,\n\u001b[1;32m 85\u001b[0m )\n",
|
||||
"File \u001b[0;32m~/dev/.venv/lib/python3.10/site-packages/nltk/parse/dependencygraph.py:331\u001b[0m, in \u001b[0;36mDependencyGraph._parse\u001b[0;34m(self, input_, cell_extractor, zero_based, cell_separator, top_relation_label)\u001b[0m\n\u001b[1;32m 329\u001b[0m cell_extractor \u001b[39m=\u001b[39m extractors[cell_number]\n\u001b[1;32m 330\u001b[0m \u001b[39mexcept\u001b[39;00m \u001b[39mKeyError\u001b[39;00m \u001b[39mas\u001b[39;00m e:\n\u001b[0;32m--> 331\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mValueError\u001b[39;00m(\n\u001b[1;32m 332\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mNumber of tab-delimited fields (\u001b[39m\u001b[39m{}\u001b[39;00m\u001b[39m) not supported by \u001b[39m\u001b[39m\"\u001b[39m\n\u001b[1;32m 333\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mCoNLL(10) or Malt-Tab(4) format\u001b[39m\u001b[39m\"\u001b[39m\u001b[39m.\u001b[39mformat(cell_number)\n\u001b[1;32m 334\u001b[0m ) \u001b[39mfrom\u001b[39;00m \u001b[39me\u001b[39;00m\n\u001b[1;32m 336\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[1;32m 337\u001b[0m index, word, lemma, ctag, tag, feats, head, rel \u001b[39m=\u001b[39m cell_extractor(\n\u001b[1;32m 338\u001b[0m cells, index\n\u001b[1;32m 339\u001b[0m )\n",
|
||||
"\u001b[0;31mValueError\u001b[0m: Number of tab-delimited fields (5) not supported by CoNLL(10) or Malt-Tab(4) format"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"treebank_data =\"\"\"vaico v10 4245 shock absorber\"\"\"\n",
|
||||
"dg = DependencyGraph(treebank_data)\n",
|
||||
"dg.tree().pprint()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": ".venv",
|
||||
"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.10.12"
|
||||
},
|
||||
"orig_nbformat": 4
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
|
|
@ -138,7 +138,7 @@
|
|||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.9.7"
|
||||
"version": "3.10.12"
|
||||
},
|
||||
"orig_nbformat": 4
|
||||
},
|
||||
|
|
|
|||
|
|
@ -2,64 +2,9 @@
|
|||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Collecting seaborn\n",
|
||||
" Using cached seaborn-0.12.2-py3-none-any.whl (293 kB)\n",
|
||||
"Collecting pandas>=0.25\n",
|
||||
" Using cached pandas-2.0.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (12.3 MB)\n",
|
||||
"Collecting numpy!=1.24.0,>=1.17\n",
|
||||
" Downloading numpy-1.25.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (17.6 MB)\n",
|
||||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m17.6/17.6 MB\u001b[0m \u001b[31m1.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n",
|
||||
"\u001b[?25hCollecting matplotlib!=3.6.1,>=3.1\n",
|
||||
" Using cached matplotlib-3.7.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (11.6 MB)\n",
|
||||
"Collecting contourpy>=1.0.1\n",
|
||||
" Using cached contourpy-1.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (300 kB)\n",
|
||||
"Collecting cycler>=0.10\n",
|
||||
" Using cached cycler-0.11.0-py3-none-any.whl (6.4 kB)\n",
|
||||
"Collecting pillow>=6.2.0\n",
|
||||
" Using cached Pillow-9.5.0-cp310-cp310-manylinux_2_28_x86_64.whl (3.4 MB)\n",
|
||||
"Requirement already satisfied: python-dateutil>=2.7 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from matplotlib!=3.6.1,>=3.1->seaborn) (2.8.2)\n",
|
||||
"Collecting pyparsing>=2.3.1\n",
|
||||
" Downloading pyparsing-3.1.0-py3-none-any.whl (102 kB)\n",
|
||||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m102.6/102.6 kB\u001b[0m \u001b[31m829.5 kB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n",
|
||||
"\u001b[?25hCollecting kiwisolver>=1.0.1\n",
|
||||
" Using cached kiwisolver-1.4.4-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (1.6 MB)\n",
|
||||
"Collecting fonttools>=4.22.0\n",
|
||||
" Using cached fonttools-4.40.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.2 MB)\n",
|
||||
"Requirement already satisfied: packaging>=20.0 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from matplotlib!=3.6.1,>=3.1->seaborn) (23.1)\n",
|
||||
"Collecting pytz>=2020.1\n",
|
||||
" Using cached pytz-2023.3-py2.py3-none-any.whl (502 kB)\n",
|
||||
"Collecting tzdata>=2022.1\n",
|
||||
" Using cached tzdata-2023.3-py2.py3-none-any.whl (341 kB)\n",
|
||||
"Requirement already satisfied: six>=1.5 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from python-dateutil>=2.7->matplotlib!=3.6.1,>=3.1->seaborn) (1.16.0)\n",
|
||||
"Installing collected packages: pytz, tzdata, pyparsing, pillow, numpy, kiwisolver, fonttools, cycler, pandas, contourpy, matplotlib, seaborn\n",
|
||||
"Successfully installed contourpy-1.1.0 cycler-0.11.0 fonttools-4.40.0 kiwisolver-1.4.4 matplotlib-3.7.1 numpy-1.25.0 pandas-2.0.2 pillow-9.5.0 pyparsing-3.1.0 pytz-2023.3 seaborn-0.12.2 tzdata-2023.3\n",
|
||||
"\n",
|
||||
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.0.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m23.1.2\u001b[0m\n",
|
||||
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n",
|
||||
"Collecting scikit-learn\n",
|
||||
" Using cached scikit_learn-1.2.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (9.6 MB)\n",
|
||||
"Requirement already satisfied: numpy>=1.17.3 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from scikit-learn) (1.25.0)\n",
|
||||
"Collecting scipy>=1.3.2\n",
|
||||
" Using cached scipy-1.10.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (34.4 MB)\n",
|
||||
"Collecting joblib>=1.1.1\n",
|
||||
" Using cached joblib-1.2.0-py3-none-any.whl (297 kB)\n",
|
||||
"Collecting threadpoolctl>=2.0.0\n",
|
||||
" Using cached threadpoolctl-3.1.0-py3-none-any.whl (14 kB)\n",
|
||||
"Installing collected packages: threadpoolctl, scipy, joblib, scikit-learn\n",
|
||||
"Successfully installed joblib-1.2.0 scikit-learn-1.2.2 scipy-1.10.1 threadpoolctl-3.1.0\n",
|
||||
"\n",
|
||||
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.0.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m23.1.2\u001b[0m\n",
|
||||
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!python -m pip install seaborn\n",
|
||||
"!python -m pip install scikit-learn"
|
||||
|
|
@ -67,32 +12,16 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Collecting elasticsearch<7.0.0,>=6.4.0\n",
|
||||
" Using cached elasticsearch-6.8.2-py2.py3-none-any.whl (90 kB)\n",
|
||||
"Collecting urllib3>=1.21.1\n",
|
||||
" Using cached urllib3-2.0.3-py3-none-any.whl (123 kB)\n",
|
||||
"Installing collected packages: urllib3, elasticsearch\n",
|
||||
"Successfully installed elasticsearch-6.8.2 urllib3-2.0.3\n",
|
||||
"\n",
|
||||
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.0.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m23.1.2\u001b[0m\n",
|
||||
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!python -m pip install \"elasticsearch>=6.4.0,<7.0.0\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
|
|
@ -105,24 +34,16 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Got 22329 Hits:\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"print(\"Got %d Hits:\" % resp['hits']['total'])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 7,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
|
|
@ -137,7 +58,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 8,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
|
|
@ -147,36 +68,16 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 14,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"name denso dtm82363 thermostat coolant\n",
|
||||
"sdesc thermostat coolant\n",
|
||||
"category thermostat\n",
|
||||
"catlevel0 sparepart\n",
|
||||
"catlevel1 cooling system\n",
|
||||
"catlevel2 thermostat\n",
|
||||
"catlevel3 NaN\n",
|
||||
"catlevel4 NaN\n",
|
||||
"catlevel5 NaN\n",
|
||||
"Name: 0, dtype: object"
|
||||
]
|
||||
},
|
||||
"execution_count": 14,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"df_eng.iloc[0]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 10,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
|
|
@ -200,7 +101,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 11,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
|
|
@ -211,7 +112,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 12,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
|
|
@ -319,20 +220,9 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 13,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"(10, 9)"
|
||||
]
|
||||
},
|
||||
"execution_count": 13,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"df_eng.shape"
|
||||
]
|
||||
|
|
@ -393,36 +283,16 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 59,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"name vaico v10 2660 mounting automatic transmission\n",
|
||||
"sdesc mounting automatic transmission\n",
|
||||
"category mounting\n",
|
||||
"catlevel0 sparepart\n",
|
||||
"catlevel1 transmission\n",
|
||||
"catlevel2 automatic transmission\n",
|
||||
"catlevel3 mounting\n",
|
||||
"catlevel4 NaN\n",
|
||||
"catlevel5 NaN\n",
|
||||
"Name: 7, dtype: object"
|
||||
]
|
||||
},
|
||||
"execution_count": 59,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"df_eng.iloc[7]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 32,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
|
|
@ -438,182 +308,52 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 33,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"{'denso': 22,\n",
|
||||
" 'dtm82363': 23,\n",
|
||||
" 'thermostat': 33,\n",
|
||||
" 'coolantthermostat': 21,\n",
|
||||
" 'zf': 45,\n",
|
||||
" '1043': 7,\n",
|
||||
" '010': 1,\n",
|
||||
" '297': 11,\n",
|
||||
" 'automatic': 17,\n",
|
||||
" 'transmissionautomatic': 37,\n",
|
||||
" 'transmission': 36,\n",
|
||||
" '1060': 8,\n",
|
||||
" '040': 4,\n",
|
||||
" '003': 0,\n",
|
||||
" 'vaico': 43,\n",
|
||||
" 'v10': 39,\n",
|
||||
" '0131': 2,\n",
|
||||
" 'camshaftcamshaft': 19,\n",
|
||||
" 'v26': 41,\n",
|
||||
" '0302': 3,\n",
|
||||
" 'track': 35,\n",
|
||||
" 'control': 20,\n",
|
||||
" 'armtrack': 16,\n",
|
||||
" 'arm': 15,\n",
|
||||
" 'v30': 42,\n",
|
||||
" '1250': 9,\n",
|
||||
" 'suspension': 31,\n",
|
||||
" 'kitsuspension': 27,\n",
|
||||
" 'kit': 26,\n",
|
||||
" '0474': 5,\n",
|
||||
" 'tensioner': 32,\n",
|
||||
" 'pulley': 29,\n",
|
||||
" 'timing': 34,\n",
|
||||
" 'belttensioner': 18,\n",
|
||||
" '2660': 10,\n",
|
||||
" 'mounting': 28,\n",
|
||||
" 'transmissionmounting': 38,\n",
|
||||
" '4245': 12,\n",
|
||||
" 'shock': 30,\n",
|
||||
" 'absorbershock': 14,\n",
|
||||
" 'absorber': 13,\n",
|
||||
" 'v24': 40,\n",
|
||||
" '0908': 6,\n",
|
||||
" 'wheel': 44,\n",
|
||||
" 'hubwheel': 25,\n",
|
||||
" 'hub': 24}"
|
||||
]
|
||||
},
|
||||
"execution_count": 33,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"n_gram_vectorizer.vocabulary_"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 34,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"(10, 46)"
|
||||
]
|
||||
},
|
||||
"execution_count": 34,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"transformed_vector_name.shape"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 35,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
|
||||
" 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
|
||||
" 0, 0],\n",
|
||||
" [0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,\n",
|
||||
" 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,\n",
|
||||
" 0, 1],\n",
|
||||
" [1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,\n",
|
||||
" 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,\n",
|
||||
" 0, 1],\n",
|
||||
" [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
|
||||
" 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1,\n",
|
||||
" 0, 0],\n",
|
||||
" [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0,\n",
|
||||
" 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1,\n",
|
||||
" 0, 0],\n",
|
||||
" [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
|
||||
" 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1,\n",
|
||||
" 0, 0],\n",
|
||||
" [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
|
||||
" 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1,\n",
|
||||
" 0, 0],\n",
|
||||
" [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,\n",
|
||||
" 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1,\n",
|
||||
" 0, 0],\n",
|
||||
" [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0,\n",
|
||||
" 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1,\n",
|
||||
" 0, 0],\n",
|
||||
" [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
|
||||
" 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1,\n",
|
||||
" 1, 0]])"
|
||||
]
|
||||
},
|
||||
"execution_count": 35,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"transformed_vector_name.toarray()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 37,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"17"
|
||||
]
|
||||
},
|
||||
"execution_count": 37,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"n_gram_vectorizer.vocabulary_.get('automatic')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 18,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"ename": "NameError",
|
||||
"evalue": "name 'vocabulary' is not defined",
|
||||
"output_type": "error",
|
||||
"traceback": [
|
||||
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
||||
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
|
||||
"Cell \u001b[0;32mIn[18], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m vocabulary\u001b[39m.\u001b[39mitems()\n",
|
||||
"\u001b[0;31mNameError\u001b[0m: name 'vocabulary' is not defined"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"vocabulary.items()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 19,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
|
|
@ -627,27 +367,16 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 20,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"((8, 19), (8, 16))"
|
||||
]
|
||||
},
|
||||
"execution_count": 20,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"X_train.shape, Y_train.shape"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 23,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
|
|
@ -659,22 +388,9 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 21,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"ename": "AttributeError",
|
||||
"evalue": "values not found",
|
||||
"output_type": "error",
|
||||
"traceback": [
|
||||
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
||||
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
|
||||
"Cell \u001b[0;32mIn[21], line 3\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39mtorch\u001b[39;00m\n\u001b[1;32m 2\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39mnumpy\u001b[39;00m \u001b[39mas\u001b[39;00m \u001b[39mnp\u001b[39;00m\n\u001b[0;32m----> 3\u001b[0m Xtrain_ \u001b[39m=\u001b[39m torch\u001b[39m.\u001b[39mfrom_numpy(X_train\u001b[39m.\u001b[39;49mvalues)\u001b[39m.\u001b[39mfloat()\n\u001b[1;32m 4\u001b[0m Xtest_ \u001b[39m=\u001b[39m torch\u001b[39m.\u001b[39mfrom_numpy(x_test\u001b[39m.\u001b[39mvalues)\u001b[39m.\u001b[39mfloat()\n\u001b[1;32m 5\u001b[0m Xtrain_\u001b[39m.\u001b[39mshape\n",
|
||||
"File \u001b[0;32m~/dev/.venv/lib/python3.10/site-packages/scipy/sparse/_base.py:771\u001b[0m, in \u001b[0;36mspmatrix.__getattr__\u001b[0;34m(self, attr)\u001b[0m\n\u001b[1;32m 769\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mgetnnz()\n\u001b[1;32m 770\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[0;32m--> 771\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mAttributeError\u001b[39;00m(attr \u001b[39m+\u001b[39m \u001b[39m\"\u001b[39m\u001b[39m not found\u001b[39m\u001b[39m\"\u001b[39m)\n",
|
||||
"\u001b[0;31mAttributeError\u001b[0m: values not found"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"\n",
|
||||
"Xtrain_ = torch.from_numpy(X_train).float()\n",
|
||||
|
|
@ -687,21 +403,9 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 22,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"ename": "NameError",
|
||||
"evalue": "name 'nn' is not defined",
|
||||
"output_type": "error",
|
||||
"traceback": [
|
||||
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
||||
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
|
||||
"Cell \u001b[0;32mIn[22], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[39mclass\u001b[39;00m \u001b[39mNet\u001b[39;00m(nn\u001b[39m.\u001b[39mModule):\n\u001b[1;32m 3\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m__init__\u001b[39m(\u001b[39mself\u001b[39m):\n\u001b[1;32m 4\u001b[0m \u001b[39msuper\u001b[39m(Net, \u001b[39mself\u001b[39m)\u001b[39m.\u001b[39m\u001b[39m__init__\u001b[39m()\n",
|
||||
"\u001b[0;31mNameError\u001b[0m: name 'nn' is not defined"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"class Net(nn.Module):\n",
|
||||
" \n",
|
||||
|
|
|
|||
|
|
@ -1,5 +1,88 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Collecting spacy\n",
|
||||
" Downloading spacy-3.5.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.6 MB)\n",
|
||||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m6.6/6.6 MB\u001b[0m \u001b[31m1.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n",
|
||||
"\u001b[?25hRequirement already satisfied: numpy>=1.15.0 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from spacy) (1.25.0)\n",
|
||||
"Collecting murmurhash<1.1.0,>=0.28.0\n",
|
||||
" Downloading murmurhash-1.0.9-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (21 kB)\n",
|
||||
"Collecting pathy>=0.10.0\n",
|
||||
" Downloading pathy-0.10.2-py3-none-any.whl (48 kB)\n",
|
||||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m48.9/48.9 kB\u001b[0m \u001b[31m633.4 kB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m \u001b[36m0:00:01\u001b[0m\n",
|
||||
"\u001b[?25hCollecting spacy-loggers<2.0.0,>=1.0.0\n",
|
||||
" Downloading spacy_loggers-1.0.4-py3-none-any.whl (11 kB)\n",
|
||||
"Collecting cymem<2.1.0,>=2.0.2\n",
|
||||
" Downloading cymem-2.0.7-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (34 kB)\n",
|
||||
"Collecting wasabi<1.2.0,>=0.9.1\n",
|
||||
" Downloading wasabi-1.1.2-py3-none-any.whl (27 kB)\n",
|
||||
"Collecting preshed<3.1.0,>=3.0.2\n",
|
||||
" Downloading preshed-3.0.8-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (124 kB)\n",
|
||||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m124.7/124.7 kB\u001b[0m \u001b[31m808.8 kB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n",
|
||||
"\u001b[?25hCollecting langcodes<4.0.0,>=3.2.0\n",
|
||||
" Downloading langcodes-3.3.0-py3-none-any.whl (181 kB)\n",
|
||||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m181.6/181.6 kB\u001b[0m \u001b[31m1.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0m\n",
|
||||
"\u001b[?25hCollecting pydantic!=1.8,!=1.8.1,<1.11.0,>=1.7.4\n",
|
||||
" Downloading pydantic-1.10.9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.1 MB)\n",
|
||||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m3.1/3.1 MB\u001b[0m \u001b[31m1.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n",
|
||||
"\u001b[?25hRequirement already satisfied: packaging>=20.0 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from spacy) (23.1)\n",
|
||||
"Collecting smart-open<7.0.0,>=5.2.1\n",
|
||||
" Downloading smart_open-6.3.0-py3-none-any.whl (56 kB)\n",
|
||||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m56.8/56.8 kB\u001b[0m \u001b[31m586.3 kB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0m\n",
|
||||
"\u001b[?25hRequirement already satisfied: tqdm<5.0.0,>=4.38.0 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from spacy) (4.65.0)\n",
|
||||
"Collecting typer<0.8.0,>=0.3.0\n",
|
||||
" Downloading typer-0.7.0-py3-none-any.whl (38 kB)\n",
|
||||
"Collecting srsly<3.0.0,>=2.4.3\n",
|
||||
" Downloading srsly-2.4.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (492 kB)\n",
|
||||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m492.2/492.2 kB\u001b[0m \u001b[31m976.1 kB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n",
|
||||
"\u001b[?25hRequirement already satisfied: jinja2 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from spacy) (3.1.2)\n",
|
||||
"Collecting spacy-legacy<3.1.0,>=3.0.11\n",
|
||||
" Downloading spacy_legacy-3.0.12-py2.py3-none-any.whl (29 kB)\n",
|
||||
"Collecting catalogue<2.1.0,>=2.0.6\n",
|
||||
" Downloading catalogue-2.0.8-py3-none-any.whl (17 kB)\n",
|
||||
"Requirement already satisfied: setuptools in /home/shoney/dev/.venv/lib/python3.10/site-packages (from spacy) (65.5.0)\n",
|
||||
"Collecting requests<3.0.0,>=2.13.0\n",
|
||||
" Downloading requests-2.31.0-py3-none-any.whl (62 kB)\n",
|
||||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m62.6/62.6 kB\u001b[0m \u001b[31m829.1 kB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m0:01\u001b[0m00:01\u001b[0m\n",
|
||||
"\u001b[?25hCollecting thinc<8.2.0,>=8.1.8\n",
|
||||
" Downloading thinc-8.1.10-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (913 kB)\n",
|
||||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m913.3/913.3 kB\u001b[0m \u001b[31m910.2 kB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n",
|
||||
"\u001b[?25hRequirement already satisfied: typing-extensions>=4.2.0 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from pydantic!=1.8,!=1.8.1,<1.11.0,>=1.7.4->spacy) (4.6.3)\n",
|
||||
"Requirement already satisfied: urllib3<3,>=1.21.1 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from requests<3.0.0,>=2.13.0->spacy) (2.0.3)\n",
|
||||
"Requirement already satisfied: idna<4,>=2.5 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from requests<3.0.0,>=2.13.0->spacy) (3.4)\n",
|
||||
"Collecting charset-normalizer<4,>=2\n",
|
||||
" Downloading charset_normalizer-3.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (199 kB)\n",
|
||||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m199.3/199.3 kB\u001b[0m \u001b[31m851.0 kB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n",
|
||||
"\u001b[?25hCollecting certifi>=2017.4.17\n",
|
||||
" Downloading certifi-2023.5.7-py3-none-any.whl (156 kB)\n",
|
||||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m157.0/157.0 kB\u001b[0m \u001b[31m841.0 kB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n",
|
||||
"\u001b[?25hCollecting blis<0.8.0,>=0.7.8\n",
|
||||
" Downloading blis-0.7.9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (10.2 MB)\n",
|
||||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m10.2/10.2 MB\u001b[0m \u001b[31m1.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m0:01\u001b[0m\n",
|
||||
"\u001b[?25hCollecting confection<1.0.0,>=0.0.1\n",
|
||||
" Downloading confection-0.0.4-py3-none-any.whl (32 kB)\n",
|
||||
"Requirement already satisfied: click<9.0.0,>=7.1.1 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from typer<0.8.0,>=0.3.0->spacy) (8.1.3)\n",
|
||||
"Requirement already satisfied: MarkupSafe>=2.0 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from jinja2->spacy) (2.1.3)\n",
|
||||
"Installing collected packages: cymem, wasabi, typer, spacy-loggers, spacy-legacy, smart-open, pydantic, murmurhash, langcodes, charset-normalizer, certifi, catalogue, blis, srsly, requests, preshed, pathy, confection, thinc, spacy\n",
|
||||
"Successfully installed blis-0.7.9 catalogue-2.0.8 certifi-2023.5.7 charset-normalizer-3.1.0 confection-0.0.4 cymem-2.0.7 langcodes-3.3.0 murmurhash-1.0.9 pathy-0.10.2 preshed-3.0.8 pydantic-1.10.9 requests-2.31.0 smart-open-6.3.0 spacy-3.5.3 spacy-legacy-3.0.12 spacy-loggers-1.0.4 srsly-2.4.6 thinc-8.1.10 typer-0.7.0 wasabi-1.1.2\n",
|
||||
"\n",
|
||||
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.0.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m23.1.2\u001b[0m\n",
|
||||
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"!python -m pip install spacy\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
|
|
@ -9,126 +92,44 @@
|
|||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Defaulting to user installation because normal site-packages is not writeable\n",
|
||||
"Collecting spacy\n",
|
||||
" Downloading spacy-3.5.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.6 MB)\n",
|
||||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m6.6/6.6 MB\u001b[0m \u001b[31m5.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n",
|
||||
"\u001b[?25hCollecting pathy>=0.10.0\n",
|
||||
" Downloading pathy-0.10.1-py3-none-any.whl (48 kB)\n",
|
||||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m48.9/48.9 KB\u001b[0m \u001b[31m5.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
||||
"\u001b[?25hCollecting preshed<3.1.0,>=3.0.2\n",
|
||||
" Downloading preshed-3.0.8-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (124 kB)\n",
|
||||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m124.7/124.7 KB\u001b[0m \u001b[31m5.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
||||
"\u001b[?25hCollecting cymem<2.1.0,>=2.0.2\n",
|
||||
" Downloading cymem-2.0.7-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (34 kB)\n",
|
||||
"Collecting tqdm<5.0.0,>=4.38.0\n",
|
||||
" Downloading tqdm-4.65.0-py3-none-any.whl (77 kB)\n",
|
||||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m77.1/77.1 KB\u001b[0m \u001b[31m7.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
||||
"\u001b[?25hCollecting spacy-loggers<2.0.0,>=1.0.0\n",
|
||||
" Downloading spacy_loggers-1.0.4-py3-none-any.whl (11 kB)\n",
|
||||
"Requirement already satisfied: jinja2 in /home/shoney/.local/lib/python3.10/site-packages (from spacy) (3.1.2)\n",
|
||||
"Requirement already satisfied: setuptools in /usr/lib/python3/dist-packages (from spacy) (59.6.0)\n",
|
||||
"Collecting catalogue<2.1.0,>=2.0.6\n",
|
||||
" Downloading catalogue-2.0.8-py3-none-any.whl (17 kB)\n",
|
||||
"Requirement already satisfied: numpy>=1.15.0 in /home/shoney/.local/lib/python3.10/site-packages (from spacy) (1.24.3)\n",
|
||||
"Collecting murmurhash<1.1.0,>=0.28.0\n",
|
||||
" Downloading murmurhash-1.0.9-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (21 kB)\n",
|
||||
"Collecting spacy-legacy<3.1.0,>=3.0.11\n",
|
||||
" Downloading spacy_legacy-3.0.12-py2.py3-none-any.whl (29 kB)\n",
|
||||
"Collecting requests<3.0.0,>=2.13.0\n",
|
||||
" Downloading requests-2.31.0-py3-none-any.whl (62 kB)\n",
|
||||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m62.6/62.6 KB\u001b[0m \u001b[31m12.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
||||
"\u001b[?25hCollecting typer<0.8.0,>=0.3.0\n",
|
||||
" Downloading typer-0.7.0-py3-none-any.whl (38 kB)\n",
|
||||
"Requirement already satisfied: packaging>=20.0 in /home/shoney/.local/lib/python3.10/site-packages (from spacy) (23.1)\n",
|
||||
"Collecting langcodes<4.0.0,>=3.2.0\n",
|
||||
" Downloading langcodes-3.3.0-py3-none-any.whl (181 kB)\n",
|
||||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m181.6/181.6 KB\u001b[0m \u001b[31m7.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0m\n",
|
||||
"\u001b[?25hCollecting srsly<3.0.0,>=2.4.3\n",
|
||||
" Downloading srsly-2.4.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (492 kB)\n",
|
||||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m492.2/492.2 KB\u001b[0m \u001b[31m6.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0m\n",
|
||||
"\u001b[?25hCollecting smart-open<7.0.0,>=5.2.1\n",
|
||||
" Downloading smart_open-6.3.0-py3-none-any.whl (56 kB)\n",
|
||||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m56.8/56.8 KB\u001b[0m \u001b[31m8.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
||||
"\u001b[?25hCollecting thinc<8.2.0,>=8.1.8\n",
|
||||
" Downloading thinc-8.1.10-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (913 kB)\n",
|
||||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m913.3/913.3 KB\u001b[0m \u001b[31m6.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0m\n",
|
||||
"\u001b[?25hCollecting wasabi<1.2.0,>=0.9.1\n",
|
||||
" Downloading wasabi-1.1.2-py3-none-any.whl (27 kB)\n",
|
||||
"Collecting pydantic!=1.8,!=1.8.1,<1.11.0,>=1.7.4\n",
|
||||
" Downloading pydantic-1.10.9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.1 MB)\n",
|
||||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m3.1/3.1 MB\u001b[0m \u001b[31m4.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n",
|
||||
"\u001b[?25hCollecting typing-extensions>=4.2.0\n",
|
||||
" Downloading typing_extensions-4.6.3-py3-none-any.whl (31 kB)\n",
|
||||
"Requirement already satisfied: idna<4,>=2.5 in /home/shoney/.local/lib/python3.10/site-packages (from requests<3.0.0,>=2.13.0->spacy) (3.4)\n",
|
||||
"Requirement already satisfied: urllib3<3,>=1.21.1 in /home/shoney/.local/lib/python3.10/site-packages (from requests<3.0.0,>=2.13.0->spacy) (1.26.16)\n",
|
||||
"Requirement already satisfied: certifi>=2017.4.17 in /home/shoney/.local/lib/python3.10/site-packages (from requests<3.0.0,>=2.13.0->spacy) (2023.5.7)\n",
|
||||
"Collecting charset-normalizer<4,>=2\n",
|
||||
" Downloading charset_normalizer-3.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (199 kB)\n",
|
||||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m199.3/199.3 KB\u001b[0m \u001b[31m5.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0m\n",
|
||||
"\u001b[?25hCollecting confection<1.0.0,>=0.0.1\n",
|
||||
" Downloading confection-0.0.4-py3-none-any.whl (32 kB)\n",
|
||||
"Collecting blis<0.8.0,>=0.7.8\n",
|
||||
" Downloading blis-0.7.9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (10.2 MB)\n",
|
||||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m10.2/10.2 MB\u001b[0m \u001b[31m5.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m0:01\u001b[0m\n",
|
||||
"\u001b[?25hCollecting click<9.0.0,>=7.1.1\n",
|
||||
" Downloading click-8.1.3-py3-none-any.whl (96 kB)\n",
|
||||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m96.6/96.6 KB\u001b[0m \u001b[31m4.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
||||
"\u001b[?25hRequirement already satisfied: MarkupSafe>=2.0 in /home/shoney/.local/lib/python3.10/site-packages (from jinja2->spacy) (2.1.3)\n",
|
||||
"Installing collected packages: cymem, wasabi, typing-extensions, tqdm, spacy-loggers, spacy-legacy, smart-open, murmurhash, langcodes, click, charset-normalizer, catalogue, blis, typer, srsly, requests, pydantic, preshed, pathy, confection, thinc, spacy\n",
|
||||
"Successfully installed blis-0.7.9 catalogue-2.0.8 charset-normalizer-3.1.0 click-8.1.3 confection-0.0.4 cymem-2.0.7 langcodes-3.3.0 murmurhash-1.0.9 pathy-0.10.1 preshed-3.0.8 pydantic-1.10.9 requests-2.31.0 smart-open-6.3.0 spacy-3.5.3 spacy-legacy-3.0.12 spacy-loggers-1.0.4 srsly-2.4.6 thinc-8.1.10 tqdm-4.65.0 typer-0.7.0 typing-extensions-4.6.3 wasabi-1.1.2\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"!python -m pip install spacy"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Defaulting to user installation because normal site-packages is not writeable\n",
|
||||
"Collecting en-core-web-sm==3.5.0\n",
|
||||
" Downloading https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.5.0/en_core_web_sm-3.5.0-py3-none-any.whl (12.8 MB)\n",
|
||||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m12.8/12.8 MB\u001b[0m \u001b[31m4.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n",
|
||||
"\u001b[?25hRequirement already satisfied: spacy<3.6.0,>=3.5.0 in /home/shoney/.local/lib/python3.10/site-packages (from en-core-web-sm==3.5.0) (3.5.3)\n",
|
||||
"Requirement already satisfied: pathy>=0.10.0 in /home/shoney/.local/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (0.10.1)\n",
|
||||
"Requirement already satisfied: catalogue<2.1.0,>=2.0.6 in /home/shoney/.local/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (2.0.8)\n",
|
||||
"Requirement already satisfied: thinc<8.2.0,>=8.1.8 in /home/shoney/.local/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (8.1.10)\n",
|
||||
"Requirement already satisfied: wasabi<1.2.0,>=0.9.1 in /home/shoney/.local/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (1.1.2)\n",
|
||||
"Requirement already satisfied: langcodes<4.0.0,>=3.2.0 in /home/shoney/.local/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (3.3.0)\n",
|
||||
"Requirement already satisfied: packaging>=20.0 in /home/shoney/.local/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (23.1)\n",
|
||||
"Requirement already satisfied: preshed<3.1.0,>=3.0.2 in /home/shoney/.local/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (3.0.8)\n",
|
||||
"Requirement already satisfied: tqdm<5.0.0,>=4.38.0 in /home/shoney/.local/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (4.65.0)\n",
|
||||
"Requirement already satisfied: jinja2 in /home/shoney/.local/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (3.1.2)\n",
|
||||
"Requirement already satisfied: pydantic!=1.8,!=1.8.1,<1.11.0,>=1.7.4 in /home/shoney/.local/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (1.10.9)\n",
|
||||
"Requirement already satisfied: numpy>=1.15.0 in /home/shoney/.local/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (1.24.3)\n",
|
||||
"Requirement already satisfied: setuptools in /usr/lib/python3/dist-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (59.6.0)\n",
|
||||
"Requirement already satisfied: spacy-loggers<2.0.0,>=1.0.0 in /home/shoney/.local/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (1.0.4)\n",
|
||||
"Requirement already satisfied: spacy-legacy<3.1.0,>=3.0.11 in /home/shoney/.local/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (3.0.12)\n",
|
||||
"Requirement already satisfied: cymem<2.1.0,>=2.0.2 in /home/shoney/.local/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (2.0.7)\n",
|
||||
"Requirement already satisfied: smart-open<7.0.0,>=5.2.1 in /home/shoney/.local/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (6.3.0)\n",
|
||||
"Requirement already satisfied: requests<3.0.0,>=2.13.0 in /home/shoney/.local/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (2.31.0)\n",
|
||||
"Requirement already satisfied: murmurhash<1.1.0,>=0.28.0 in /home/shoney/.local/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (1.0.9)\n",
|
||||
"Requirement already satisfied: srsly<3.0.0,>=2.4.3 in /home/shoney/.local/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (2.4.6)\n",
|
||||
"Requirement already satisfied: typer<0.8.0,>=0.3.0 in /home/shoney/.local/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (0.7.0)\n",
|
||||
"Requirement already satisfied: typing-extensions>=4.2.0 in /home/shoney/.local/lib/python3.10/site-packages (from pydantic!=1.8,!=1.8.1,<1.11.0,>=1.7.4->spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (4.6.3)\n",
|
||||
"Requirement already satisfied: idna<4,>=2.5 in /home/shoney/.local/lib/python3.10/site-packages (from requests<3.0.0,>=2.13.0->spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (3.4)\n",
|
||||
"Requirement already satisfied: certifi>=2017.4.17 in /home/shoney/.local/lib/python3.10/site-packages (from requests<3.0.0,>=2.13.0->spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (2023.5.7)\n",
|
||||
"Requirement already satisfied: charset-normalizer<4,>=2 in /home/shoney/.local/lib/python3.10/site-packages (from requests<3.0.0,>=2.13.0->spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (3.1.0)\n",
|
||||
"Requirement already satisfied: urllib3<3,>=1.21.1 in /home/shoney/.local/lib/python3.10/site-packages (from requests<3.0.0,>=2.13.0->spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (1.26.16)\n",
|
||||
"Requirement already satisfied: blis<0.8.0,>=0.7.8 in /home/shoney/.local/lib/python3.10/site-packages (from thinc<8.2.0,>=8.1.8->spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (0.7.9)\n",
|
||||
"Requirement already satisfied: confection<1.0.0,>=0.0.1 in /home/shoney/.local/lib/python3.10/site-packages (from thinc<8.2.0,>=8.1.8->spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (0.0.4)\n",
|
||||
"Requirement already satisfied: click<9.0.0,>=7.1.1 in /home/shoney/.local/lib/python3.10/site-packages (from typer<0.8.0,>=0.3.0->spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (8.1.3)\n",
|
||||
"Requirement already satisfied: MarkupSafe>=2.0 in /home/shoney/.local/lib/python3.10/site-packages (from jinja2->spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (2.1.3)\n",
|
||||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m12.8/12.8 MB\u001b[0m \u001b[31m1.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n",
|
||||
"\u001b[?25hRequirement already satisfied: spacy<3.6.0,>=3.5.0 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from en-core-web-sm==3.5.0) (3.5.3)\n",
|
||||
"Requirement already satisfied: jinja2 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (3.1.2)\n",
|
||||
"Requirement already satisfied: pathy>=0.10.0 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (0.10.2)\n",
|
||||
"Requirement already satisfied: srsly<3.0.0,>=2.4.3 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (2.4.6)\n",
|
||||
"Requirement already satisfied: cymem<2.1.0,>=2.0.2 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (2.0.7)\n",
|
||||
"Requirement already satisfied: langcodes<4.0.0,>=3.2.0 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (3.3.0)\n",
|
||||
"Requirement already satisfied: setuptools in /home/shoney/dev/.venv/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (65.5.0)\n",
|
||||
"Requirement already satisfied: spacy-loggers<2.0.0,>=1.0.0 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (1.0.4)\n",
|
||||
"Requirement already satisfied: wasabi<1.2.0,>=0.9.1 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (1.1.2)\n",
|
||||
"Requirement already satisfied: smart-open<7.0.0,>=5.2.1 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (6.3.0)\n",
|
||||
"Requirement already satisfied: catalogue<2.1.0,>=2.0.6 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (2.0.8)\n",
|
||||
"Requirement already satisfied: requests<3.0.0,>=2.13.0 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (2.31.0)\n",
|
||||
"Requirement already satisfied: pydantic!=1.8,!=1.8.1,<1.11.0,>=1.7.4 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (1.10.9)\n",
|
||||
"Requirement already satisfied: numpy>=1.15.0 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (1.25.0)\n",
|
||||
"Requirement already satisfied: spacy-legacy<3.1.0,>=3.0.11 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (3.0.12)\n",
|
||||
"Requirement already satisfied: thinc<8.2.0,>=8.1.8 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (8.1.10)\n",
|
||||
"Requirement already satisfied: tqdm<5.0.0,>=4.38.0 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (4.65.0)\n",
|
||||
"Requirement already satisfied: murmurhash<1.1.0,>=0.28.0 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (1.0.9)\n",
|
||||
"Requirement already satisfied: typer<0.8.0,>=0.3.0 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (0.7.0)\n",
|
||||
"Requirement already satisfied: preshed<3.1.0,>=3.0.2 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (3.0.8)\n",
|
||||
"Requirement already satisfied: packaging>=20.0 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (23.1)\n",
|
||||
"Requirement already satisfied: typing-extensions>=4.2.0 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from pydantic!=1.8,!=1.8.1,<1.11.0,>=1.7.4->spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (4.6.3)\n",
|
||||
"Requirement already satisfied: urllib3<3,>=1.21.1 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from requests<3.0.0,>=2.13.0->spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (2.0.3)\n",
|
||||
"Requirement already satisfied: certifi>=2017.4.17 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from requests<3.0.0,>=2.13.0->spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (2023.5.7)\n",
|
||||
"Requirement already satisfied: idna<4,>=2.5 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from requests<3.0.0,>=2.13.0->spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (3.4)\n",
|
||||
"Requirement already satisfied: charset-normalizer<4,>=2 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from requests<3.0.0,>=2.13.0->spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (3.1.0)\n",
|
||||
"Requirement already satisfied: confection<1.0.0,>=0.0.1 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from thinc<8.2.0,>=8.1.8->spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (0.0.4)\n",
|
||||
"Requirement already satisfied: blis<0.8.0,>=0.7.8 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from thinc<8.2.0,>=8.1.8->spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (0.7.9)\n",
|
||||
"Requirement already satisfied: click<9.0.0,>=7.1.1 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from typer<0.8.0,>=0.3.0->spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (8.1.3)\n",
|
||||
"Requirement already satisfied: MarkupSafe>=2.0 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from jinja2->spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (2.1.3)\n",
|
||||
"Installing collected packages: en-core-web-sm\n",
|
||||
"Successfully installed en-core-web-sm-3.5.0\n",
|
||||
"\n",
|
||||
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.0.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m23.1.2\u001b[0m\n",
|
||||
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n",
|
||||
"\u001b[38;5;2m✔ Download and installation successful\u001b[0m\n",
|
||||
"You can now load the package via spacy.load('en_core_web_sm')\n"
|
||||
]
|
||||
|
|
@ -140,7 +141,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
|
|
@ -767,6 +768,100 @@
|
|||
"displacy.render(doc, style=\"dep\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 8,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<span class=\"tex2jax_ignore\"><svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xml:lang=\"en\" id=\"11547064d88447d9a44e9912f3fda23b-0\" class=\"displacy\" width=\"1100\" height=\"399.5\" direction=\"ltr\" style=\"max-width: none; height: 399.5px; color: #000000; background: #ffffff; font-family: Arial; direction: ltr\">\n",
|
||||
"<text class=\"displacy-token\" fill=\"currentColor\" text-anchor=\"middle\" y=\"309.5\">\n",
|
||||
" <tspan class=\"displacy-word\" fill=\"currentColor\" x=\"50\">vaico</tspan>\n",
|
||||
" <tspan class=\"displacy-tag\" dy=\"2em\" fill=\"currentColor\" x=\"50\">PROPN</tspan>\n",
|
||||
"</text>\n",
|
||||
"\n",
|
||||
"<text class=\"displacy-token\" fill=\"currentColor\" text-anchor=\"middle\" y=\"309.5\">\n",
|
||||
" <tspan class=\"displacy-word\" fill=\"currentColor\" x=\"225\">v26</tspan>\n",
|
||||
" <tspan class=\"displacy-tag\" dy=\"2em\" fill=\"currentColor\" x=\"225\">NOUN</tspan>\n",
|
||||
"</text>\n",
|
||||
"\n",
|
||||
"<text class=\"displacy-token\" fill=\"currentColor\" text-anchor=\"middle\" y=\"309.5\">\n",
|
||||
" <tspan class=\"displacy-word\" fill=\"currentColor\" x=\"400\">0302</tspan>\n",
|
||||
" <tspan class=\"displacy-tag\" dy=\"2em\" fill=\"currentColor\" x=\"400\">NUM</tspan>\n",
|
||||
"</text>\n",
|
||||
"\n",
|
||||
"<text class=\"displacy-token\" fill=\"currentColor\" text-anchor=\"middle\" y=\"309.5\">\n",
|
||||
" <tspan class=\"displacy-word\" fill=\"currentColor\" x=\"575\">track</tspan>\n",
|
||||
" <tspan class=\"displacy-tag\" dy=\"2em\" fill=\"currentColor\" x=\"575\">NOUN</tspan>\n",
|
||||
"</text>\n",
|
||||
"\n",
|
||||
"<text class=\"displacy-token\" fill=\"currentColor\" text-anchor=\"middle\" y=\"309.5\">\n",
|
||||
" <tspan class=\"displacy-word\" fill=\"currentColor\" x=\"750\">control</tspan>\n",
|
||||
" <tspan class=\"displacy-tag\" dy=\"2em\" fill=\"currentColor\" x=\"750\">NOUN</tspan>\n",
|
||||
"</text>\n",
|
||||
"\n",
|
||||
"<text class=\"displacy-token\" fill=\"currentColor\" text-anchor=\"middle\" y=\"309.5\">\n",
|
||||
" <tspan class=\"displacy-word\" fill=\"currentColor\" x=\"925\">arm</tspan>\n",
|
||||
" <tspan class=\"displacy-tag\" dy=\"2em\" fill=\"currentColor\" x=\"925\">NOUN</tspan>\n",
|
||||
"</text>\n",
|
||||
"\n",
|
||||
"<g class=\"displacy-arrow\">\n",
|
||||
" <path class=\"displacy-arc\" id=\"arrow-11547064d88447d9a44e9912f3fda23b-0-0\" stroke-width=\"2px\" d=\"M70,264.5 C70,177.0 215.0,177.0 215.0,264.5\" fill=\"none\" stroke=\"currentColor\"/>\n",
|
||||
" <text dy=\"1.25em\" style=\"font-size: 0.8em; letter-spacing: 1px\">\n",
|
||||
" <textPath xlink:href=\"#arrow-11547064d88447d9a44e9912f3fda23b-0-0\" class=\"displacy-label\" startOffset=\"50%\" side=\"left\" fill=\"currentColor\" text-anchor=\"middle\">nsubj</textPath>\n",
|
||||
" </text>\n",
|
||||
" <path class=\"displacy-arrowhead\" d=\"M70,266.5 L62,254.5 78,254.5\" fill=\"currentColor\"/>\n",
|
||||
"</g>\n",
|
||||
"\n",
|
||||
"<g class=\"displacy-arrow\">\n",
|
||||
" <path class=\"displacy-arc\" id=\"arrow-11547064d88447d9a44e9912f3fda23b-0-1\" stroke-width=\"2px\" d=\"M245,264.5 C245,2.0 925.0,2.0 925.0,264.5\" fill=\"none\" stroke=\"currentColor\"/>\n",
|
||||
" <text dy=\"1.25em\" style=\"font-size: 0.8em; letter-spacing: 1px\">\n",
|
||||
" <textPath xlink:href=\"#arrow-11547064d88447d9a44e9912f3fda23b-0-1\" class=\"displacy-label\" startOffset=\"50%\" side=\"left\" fill=\"currentColor\" text-anchor=\"middle\">nmod</textPath>\n",
|
||||
" </text>\n",
|
||||
" <path class=\"displacy-arrowhead\" d=\"M245,266.5 L237,254.5 253,254.5\" fill=\"currentColor\"/>\n",
|
||||
"</g>\n",
|
||||
"\n",
|
||||
"<g class=\"displacy-arrow\">\n",
|
||||
" <path class=\"displacy-arc\" id=\"arrow-11547064d88447d9a44e9912f3fda23b-0-2\" stroke-width=\"2px\" d=\"M420,264.5 C420,89.5 745.0,89.5 745.0,264.5\" fill=\"none\" stroke=\"currentColor\"/>\n",
|
||||
" <text dy=\"1.25em\" style=\"font-size: 0.8em; letter-spacing: 1px\">\n",
|
||||
" <textPath xlink:href=\"#arrow-11547064d88447d9a44e9912f3fda23b-0-2\" class=\"displacy-label\" startOffset=\"50%\" side=\"left\" fill=\"currentColor\" text-anchor=\"middle\">nummod</textPath>\n",
|
||||
" </text>\n",
|
||||
" <path class=\"displacy-arrowhead\" d=\"M420,266.5 L412,254.5 428,254.5\" fill=\"currentColor\"/>\n",
|
||||
"</g>\n",
|
||||
"\n",
|
||||
"<g class=\"displacy-arrow\">\n",
|
||||
" <path class=\"displacy-arc\" id=\"arrow-11547064d88447d9a44e9912f3fda23b-0-3\" stroke-width=\"2px\" d=\"M595,264.5 C595,177.0 740.0,177.0 740.0,264.5\" fill=\"none\" stroke=\"currentColor\"/>\n",
|
||||
" <text dy=\"1.25em\" style=\"font-size: 0.8em; letter-spacing: 1px\">\n",
|
||||
" <textPath xlink:href=\"#arrow-11547064d88447d9a44e9912f3fda23b-0-3\" class=\"displacy-label\" startOffset=\"50%\" side=\"left\" fill=\"currentColor\" text-anchor=\"middle\">compound</textPath>\n",
|
||||
" </text>\n",
|
||||
" <path class=\"displacy-arrowhead\" d=\"M595,266.5 L587,254.5 603,254.5\" fill=\"currentColor\"/>\n",
|
||||
"</g>\n",
|
||||
"\n",
|
||||
"<g class=\"displacy-arrow\">\n",
|
||||
" <path class=\"displacy-arc\" id=\"arrow-11547064d88447d9a44e9912f3fda23b-0-4\" stroke-width=\"2px\" d=\"M770,264.5 C770,177.0 915.0,177.0 915.0,264.5\" fill=\"none\" stroke=\"currentColor\"/>\n",
|
||||
" <text dy=\"1.25em\" style=\"font-size: 0.8em; letter-spacing: 1px\">\n",
|
||||
" <textPath xlink:href=\"#arrow-11547064d88447d9a44e9912f3fda23b-0-4\" class=\"displacy-label\" startOffset=\"50%\" side=\"left\" fill=\"currentColor\" text-anchor=\"middle\">compound</textPath>\n",
|
||||
" </text>\n",
|
||||
" <path class=\"displacy-arrowhead\" d=\"M770,266.5 L762,254.5 778,254.5\" fill=\"currentColor\"/>\n",
|
||||
"</g>\n",
|
||||
"</svg></span>"
|
||||
],
|
||||
"text/plain": [
|
||||
"<IPython.core.display.HTML object>"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"text = (\"vaico v26 0302 track control arm\")\n",
|
||||
"doc = nlp(text)\n",
|
||||
"displacy.render(doc, style=\"dep\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
|
|
@ -791,7 +886,7 @@
|
|||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.10.6"
|
||||
"version": "3.10.12"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
|
|
|||
1429
tuitorials/demo01-BinaryTextClassification_Words.ipynb
Normal file
1429
tuitorials/demo01-BinaryTextClassification_Words.ipynb
Normal file
File diff suppressed because it is too large
Load diff
1012
tuitorials/demo02-MulticlassTextClassification_Characters.ipynb
Normal file
1012
tuitorials/demo02-MulticlassTextClassification_Characters.ipynb
Normal file
File diff suppressed because one or more lines are too long
|
|
@ -0,0 +1,499 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### GloVe vectors\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Embeddings transform a one-hot encoded vector (a vector that is 0 in elements except one, which is 1) into a much smaller dimension vector of real numbers. The one-hot encoded vector is also known as a sparse vector, whilst the real valued vector is known as a dense vector.\n",
|
||||
"\n",
|
||||
"The key concept in these word embeddings is that words that appear in similar contexts appear nearby in the vector space, i.e. the Euclidean distance between these two word vectors is small.\n",
|
||||
"\n",
|
||||
"https://github.com/spro/practical-pytorch/blob/master/glove-word-vectors/glove-word-vectors.ipynb"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 21,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import torch\n",
|
||||
"import torchtext.vocab"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"#### Load GloVe vectors\n",
|
||||
"First, we'll load the GloVe vectors. The name field specifies what the vectors have been trained on, here the 6B means a corpus of 6 billion words."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 22,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"There are 400000 words in the vocabulary\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"glove = torchtext.vocab.GloVe(name='6B', dim=100)\n",
|
||||
"\n",
|
||||
"print(f'There are {len(glove.itos)} words in the vocabulary')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"In these set of GloVe vectors, every single word is lower-case only."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 23,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"torch.Size([400000, 100])"
|
||||
]
|
||||
},
|
||||
"execution_count": 23,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"glove.vectors.shape"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Below implies that row 0 is the vector associated with the word 'the', row 1 for ',' (comma), row 2 for '.' (period), etc."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 24,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"['the',\n",
|
||||
" ',',\n",
|
||||
" '.',\n",
|
||||
" 'of',\n",
|
||||
" 'to',\n",
|
||||
" 'and',\n",
|
||||
" 'in',\n",
|
||||
" 'a',\n",
|
||||
" '\"',\n",
|
||||
" \"'s\",\n",
|
||||
" 'for',\n",
|
||||
" '-',\n",
|
||||
" 'that',\n",
|
||||
" 'on',\n",
|
||||
" 'is']"
|
||||
]
|
||||
},
|
||||
"execution_count": 24,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"glove.itos[:15]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 25,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"0"
|
||||
]
|
||||
},
|
||||
"execution_count": 25,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"glove.stoi['the']"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 26,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"36623"
|
||||
]
|
||||
},
|
||||
"execution_count": 26,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"glove.stoi['dazzle']"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 27,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"43165"
|
||||
]
|
||||
},
|
||||
"execution_count": 27,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"glove.stoi['shenanigans']"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"#### we'll create a function that takes in word embeddings and a word and returns the associated vector. It'll also throw an error if the word doesn't exist in the vocabulary."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 28,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def get_vector(embeddings, word):\n",
|
||||
" \n",
|
||||
" assert word in embeddings.stoi, f'*{word}* is not in the vocab!'\n",
|
||||
" \n",
|
||||
" return embeddings.vectors[embeddings.stoi[word]]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 29,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"tensor([-0.8503, 0.3336, -0.6589, -0.4987, 0.3659, -0.1925, 0.2566, -0.0534,\n",
|
||||
" 0.3147, 0.2443, 0.2934, -0.4492, 0.1517, 0.3931, -0.3179, 0.0605,\n",
|
||||
" 0.8177, -0.3885, 0.7676, -1.1041, -0.1544, 0.3165, -0.3724, -0.1148,\n",
|
||||
" 0.5163, -0.3929, 0.1630, -0.2532, -0.5098, 0.1520, 0.2781, 0.5252,\n",
|
||||
" -0.3882, -0.3472, -0.6182, 0.1702, 0.1225, -0.2419, -0.3888, -0.5318,\n",
|
||||
" -0.4699, -0.7050, -0.6213, -0.3869, -0.8564, -0.4100, -0.4749, -0.2108,\n",
|
||||
" -0.8134, -0.5240, 0.4989, 0.3791, 0.5543, 1.1230, -0.4212, -1.5674,\n",
|
||||
" -0.5689, 0.4082, 1.7949, 0.1686, -0.0029, 0.2879, -0.9009, -0.0942,\n",
|
||||
" 0.7999, -0.3910, 0.7629, 0.7131, 0.1319, -0.4076, -0.1869, 0.8956,\n",
|
||||
" 0.4687, -0.0029, 0.0253, 1.0084, 0.1714, 0.5974, -1.1003, 0.4931,\n",
|
||||
" 0.4178, 0.1728, -0.4947, 0.0878, -0.9669, -1.0920, 0.3390, -0.5129,\n",
|
||||
" 0.2464, 0.2714, 0.2421, -0.2171, 0.5504, 0.0082, -0.4557, 0.1353,\n",
|
||||
" -0.0431, -0.4141, 0.7005, 0.1877])"
|
||||
]
|
||||
},
|
||||
"execution_count": 29,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"get_vector(glove, 'paper')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"If we want to find the words similar to a certain input word, we first find the vector of this input word, then we scan through our vocabulary finding any vectors similar to this input word vector.\n",
|
||||
"\n",
|
||||
"The function below returns the closest 6 words to an input word vector:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 37,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def closest(embeddings, vector, n = 6):\n",
|
||||
" \n",
|
||||
" distances = []\n",
|
||||
" \n",
|
||||
" for neighbor in embeddings.itos:\n",
|
||||
" distances.append((neighbor, torch.dist(vector, get_vector(embeddings, neighbor))))\n",
|
||||
" \n",
|
||||
" return sorted(distances, key = lambda x: x[1])[:n]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 38,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"[('paper', tensor(0.)),\n",
|
||||
" ('papers', tensor(3.8442)),\n",
|
||||
" ('printed', tensor(4.1970)),\n",
|
||||
" ('print', tensor(4.2666)),\n",
|
||||
" ('sheet', tensor(4.3835)),\n",
|
||||
" ('printing', tensor(4.4179))]"
|
||||
]
|
||||
},
|
||||
"execution_count": 38,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"closest(glove, get_vector(glove, 'paper'))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 39,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"[('shenanigans', tensor(0.)),\n",
|
||||
" ('chicanery', tensor(2.3785)),\n",
|
||||
" ('hijinks', tensor(2.6764)),\n",
|
||||
" ('escapades', tensor(2.7821)),\n",
|
||||
" ('machinations', tensor(2.8699)),\n",
|
||||
" ('gamesmanship', tensor(2.9044))]"
|
||||
]
|
||||
},
|
||||
"execution_count": 39,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"closest(glove, get_vector(glove, 'shenanigans'))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"we'll also create another function that will nicely print out the tuples returned by our closest function."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 40,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def print_tuples(tuples):\n",
|
||||
" \n",
|
||||
" for t in tuples:\n",
|
||||
" print('(%.4f) %s' % (t[1], t[0]))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 41,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"(0.0000) stupendous\n",
|
||||
"(2.5795) marvellous\n",
|
||||
"(2.7539) frightful\n",
|
||||
"(2.8506) stupefying\n",
|
||||
"(2.8561) awe-inspiring\n",
|
||||
"(2.9179) mind-blowing\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"print_tuples(closest(glove, get_vector(glove, 'stupendous')))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"#### Analogies\n",
|
||||
"\n",
|
||||
"with a well-trained word vector space certain semantic relationships can be captured with regular vector arithmetic."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 42,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def analogy(embeddings, w1, w2, w3, n = 6):\n",
|
||||
" \n",
|
||||
" print('\\n[%s : %s :: %s : ?]' % (w1, w2, w3))\n",
|
||||
" \n",
|
||||
" closest_words = closest(embeddings, \\\n",
|
||||
" get_vector(embeddings, w2)\n",
|
||||
" - get_vector(embeddings, w1) \\\n",
|
||||
" + get_vector(embeddings, w3), \\\n",
|
||||
" n + 3)\n",
|
||||
" \n",
|
||||
" closest_words = [x for x in closest_words if x[0] not in [w1, w2, w3]][:n]\n",
|
||||
" \n",
|
||||
" return closest_words"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 43,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"\n",
|
||||
"[moon : night :: sun : ?]\n",
|
||||
"(5.7069) morning\n",
|
||||
"(5.7276) afternoon\n",
|
||||
"(5.8023) evening\n",
|
||||
"(6.1410) hours\n",
|
||||
"(6.2797) saturday\n",
|
||||
"(6.3056) sunday\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"print_tuples(analogy(glove, 'moon', 'night', 'sun'))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 44,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"\n",
|
||||
"[fly : bird :: swim : ?]\n",
|
||||
"(5.9754) swimming\n",
|
||||
"(6.2409) shark\n",
|
||||
"(6.4822) dolphin\n",
|
||||
"(6.5421) whale\n",
|
||||
"(6.6276) cat\n",
|
||||
"(6.6457) gorilla\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"print_tuples(analogy(glove, 'fly', 'bird', 'swim'))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"#### Interesting failure mode"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 45,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"\n",
|
||||
"[earth : moon :: sun : ?]\n",
|
||||
"(6.2294) lee\n",
|
||||
"(6.4125) kang\n",
|
||||
"(6.4644) tan\n",
|
||||
"(6.4757) yang\n",
|
||||
"(6.4853) lin\n",
|
||||
"(6.5220) chong\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"print_tuples(analogy(glove, 'earth', 'moon', 'sun')) "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"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.4"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
1444
tuitorials/demo04-SentimentAnalysis_PretrainedGloveEmbeddings.ipynb
Normal file
1444
tuitorials/demo04-SentimentAnalysis_PretrainedGloveEmbeddings.ipynb
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue