doc
This commit is contained in:
parent
f21d982263
commit
9eafb0ab07
4 changed files with 69 additions and 93 deletions
|
|
@ -202,10 +202,9 @@
|
||||||
@misc{Paszke.03122019,
|
@misc{Paszke.03122019,
|
||||||
abstract = {Deep learning frameworks have often focused on either usability or speed, but not both. PyTorch is a machine learning library that shows that these two goals are in fact compatible: it provides an imperative and Pythonic programming style that supports code as a model, makes debugging easy and is consistent with other popular scientific computing libraries, while remaining efficient and supporting hardware accelerators such as GPUs. In this paper, we detail the principles that drove the implementation of PyTorch and how they are reflected in its architecture. We emphasize that every aspect of PyTorch is a regular Python program under the full control of its user. We also explain how the careful and pragmatic implementation of the key components of its runtime enables them to work together to achieve compelling performance. We demonstrate the efficiency of individual subsystems, as well as the overall speed of PyTorch on several common benchmarks.},
|
abstract = {Deep learning frameworks have often focused on either usability or speed, but not both. PyTorch is a machine learning library that shows that these two goals are in fact compatible: it provides an imperative and Pythonic programming style that supports code as a model, makes debugging easy and is consistent with other popular scientific computing libraries, while remaining efficient and supporting hardware accelerators such as GPUs. In this paper, we detail the principles that drove the implementation of PyTorch and how they are reflected in its architecture. We emphasize that every aspect of PyTorch is a regular Python program under the full control of its user. We also explain how the careful and pragmatic implementation of the key components of its runtime enables them to work together to achieve compelling performance. We demonstrate the efficiency of individual subsystems, as well as the overall speed of PyTorch on several common benchmarks.},
|
||||||
author = {Paszke, Adam and Gross, Sam and Massa, Francisco and Lerer, Adam and Bradbury, James and Chanan, Gregory and Killeen, Trevor and Lin, Zeming and Gimelshein, Natalia and Antiga, Luca and Desmaison, Alban and K{\"o}pf, Andreas and Yang, Edward and DeVito, Zach and Raison, Martin and Tejani, Alykhan and Chilamkurthy, Sasank and Steiner, Benoit and Fang, Lu and Bai, Junjie and Chintala, Soumith},
|
author = {Paszke, Adam and Gross, Sam and Massa, Francisco and Lerer, Adam and Bradbury, James and Chanan, Gregory and Killeen, Trevor and Lin, Zeming and Gimelshein, Natalia and Antiga, Luca and Desmaison, Alban and K{\"o}pf, Andreas and Yang, Edward and DeVito, Zach and Raison, Martin and Tejani, Alykhan and Chilamkurthy, Sasank and Steiner, Benoit and Fang, Lu and Bai, Junjie and Chintala, Soumith},
|
||||||
date = {03/12/2019},
|
year = {2019},
|
||||||
title = {PyTorch: An Imperative Style, High-Performance Deep Learning Library},
|
title = {PyTorch: An Imperative Style, High-Performance Deep Learning Library},
|
||||||
url = {https://arxiv.org/pdf/1912.01703.pdf},
|
url = {https://arxiv.org/pdf/1912.01703.pdf},
|
||||||
urldate = {30/06/2023},
|
|
||||||
file = {1912.01703:Attachments/1912.01703.pdf:application/pdf}
|
file = {1912.01703:Attachments/1912.01703.pdf:application/pdf}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -76,70 +76,3 @@ class Train():
|
||||||
self.helper.plot(self.all_losses,"loss.png")
|
self.helper.plot(self.all_losses,"loss.png")
|
||||||
|
|
||||||
torch.save(self.rnn,'ngram-rnn-classification.pt')
|
torch.save(self.rnn,'ngram-rnn-classification.pt')
|
||||||
|
|
||||||
|
|
||||||
# Just return an output given a numpy array
|
|
||||||
def evaluate(self,tensor):
|
|
||||||
hidden = self.rnn.initHidden()
|
|
||||||
|
|
||||||
for i in range(tensor.size()[0]):
|
|
||||||
output, hidden = self.rnn(tensor[i], hidden)
|
|
||||||
|
|
||||||
return output
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# def predict(self,name, n_predictions=1):
|
|
||||||
# print('\n> %s' % name)
|
|
||||||
# with torch.no_grad():
|
|
||||||
# output = self.evaluate(self.helper.nameToTensor(name,self.vectorizer))
|
|
||||||
|
|
||||||
# # Get top N categories
|
|
||||||
# topv, topi = output.topk(n_predictions, 1, True)
|
|
||||||
# predictions = []
|
|
||||||
|
|
||||||
# for i in range(n_predictions):
|
|
||||||
# value = topv[0][i].item()
|
|
||||||
# category_index = topi[0][i].item()
|
|
||||||
# print('(%.2f) %s' % (value, self.all_category[category_index]))
|
|
||||||
# predictions.append([value, self.all_category[category_index]])
|
|
||||||
|
|
||||||
# def confusionMatix(self):
|
|
||||||
# # Keep track of correct guesses in a confusion matrix
|
|
||||||
|
|
||||||
# n_categories = len(self.all_category)
|
|
||||||
# confusion = torch.zeros(n_categories, n_categories)
|
|
||||||
# n_confusion = 10000
|
|
||||||
|
|
||||||
# # Go through a bunch of examples and record which are correctly guessed
|
|
||||||
# for i in range(n_confusion):
|
|
||||||
# category, name, category_tensor, name_tensor = self.helper.randomTrainingExample()
|
|
||||||
# output = self.evaluate(name_tensor)
|
|
||||||
# guess, guess_i = self.helper.categoryFromOutput(output)
|
|
||||||
# category_i =self.all_category.index(category)
|
|
||||||
# confusion[category_i][guess_i] += 1
|
|
||||||
|
|
||||||
# # Normalize by dividing every row by its sum
|
|
||||||
# for i in range(n_categories):
|
|
||||||
# confusion[i] = confusion[i] / confusion[i].sum()
|
|
||||||
|
|
||||||
# # Set up plot
|
|
||||||
# fig = plt.figure()
|
|
||||||
# ax = fig.add_subplot(111)
|
|
||||||
# cax = ax.matshow(confusion.numpy())
|
|
||||||
# fig.colorbar(cax)
|
|
||||||
|
|
||||||
# # Set up axes
|
|
||||||
# ax.set_xticklabels([''] + self.all_category, rotation=45)
|
|
||||||
# ax.set_yticklabels([''] + self.all_category)
|
|
||||||
|
|
||||||
# # Force label at every tick
|
|
||||||
# ax.xaxis.set_major_locator(ticker.MultipleLocator(1))
|
|
||||||
# ax.yaxis.set_major_locator(ticker.MultipleLocator(1))
|
|
||||||
|
|
||||||
# # sphinx_gallery_thumbnail_number = 2
|
|
||||||
# plt.show()
|
|
||||||
# plt.savefig('confusion.png', dpi=400)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -15,32 +15,34 @@ def main():
|
||||||
es =ElasticSearchDb("http://172.17.212.35:9200")
|
es =ElasticSearchDb("http://172.17.212.35:9200")
|
||||||
|
|
||||||
df=DataFrame(es)
|
df=DataFrame(es)
|
||||||
dfProductTaxonomyEn=df.getProductTaxonomy(0,10000)
|
# dfProductTaxonomyEn=df.getProductTaxonomy(0,10000)
|
||||||
# df_en = df.getNormal()
|
df_en = df.getNormal()
|
||||||
# train = Train(df_en)
|
# train = Train(df_en)
|
||||||
# train.run(200000,20000,10000)
|
# train.run(300000,30000,3000)
|
||||||
predict = Predict()
|
predict = Predict()
|
||||||
# df_prediction=pd.DataFrame(columns=["id",'name','category','predicted','value'])
|
|
||||||
# list_row_en = dict (id=None,name=None,category=None,predicted=None,value=None)
|
|
||||||
list =[]
|
|
||||||
for index, row in dfProductTaxonomyEn.iterrows():
|
|
||||||
predicted =predict.start(row["name"].lower())
|
|
||||||
|
|
||||||
if(predicted[0][1]!=row["category"].lower()):
|
predict.confusionMatix(df_en)
|
||||||
list_row = dict (id=None,name=None,category=None,predicted=None,value=None)
|
# # df_prediction=pd.DataFrame(columns=["id",'name','category','predicted','value'])
|
||||||
list_row["id"] =row["id"]
|
# # list_row_en = dict (id=None,name=None,category=None,predicted=None,value=None)
|
||||||
list_row["name"] =row["name"]
|
# list =[]
|
||||||
list_row["category"] =row["category"]
|
# for index, row in dfProductTaxonomyEn.iterrows():
|
||||||
list_row["predicted"] =predicted[0][1]
|
# predicted =predict.start(row["name"].lower())
|
||||||
list_row["value"] =predicted[0][0]
|
|
||||||
|
|
||||||
list.append(list_row)
|
# if(predicted[0][1]!=row["category"].lower()):
|
||||||
|
# list_row = dict (id=None,name=None,category=None,predicted=None,value=None)
|
||||||
|
# list_row["id"] =row["id"]
|
||||||
|
# list_row["name"] =row["name"]
|
||||||
|
# list_row["category"] =row["category"]
|
||||||
|
# list_row["predicted"] =predicted[0][1]
|
||||||
|
# list_row["value"] =predicted[0][0]
|
||||||
|
|
||||||
|
# list.append(list_row)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# new_row = pd.Series(list_row)
|
# # new_row = pd.Series(list_row)
|
||||||
# df_prediction=pd.concat([df_prediction, new_row.to_frame().T], ignore_index=True)
|
# # df_prediction=pd.concat([df_prediction, new_row.to_frame().T], ignore_index=True)
|
||||||
es.createIndexerPrediction(list)
|
# es.createIndexerPrediction(list)
|
||||||
|
|
||||||
|
|
||||||
if __name__=="__main__":
|
if __name__=="__main__":
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
|
from matplotlib import ticker
|
||||||
from NN import *
|
from NN import *
|
||||||
import sys
|
import sys
|
||||||
from helper import *
|
from helper import *
|
||||||
|
from data import *
|
||||||
|
|
||||||
class Predict():
|
class Predict():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
@ -9,12 +11,7 @@ class Predict():
|
||||||
|
|
||||||
def evaluate(self,tensor):
|
def evaluate(self,tensor):
|
||||||
hidden = self.rnn.initHidden()
|
hidden = self.rnn.initHidden()
|
||||||
|
|
||||||
# for i in range(tensor.size()[0]):
|
|
||||||
# output, hidden = self.rnn(tensor[i], hidden)
|
|
||||||
output, hidden = self.rnn(tensor, hidden)
|
output, hidden = self.rnn(tensor, hidden)
|
||||||
|
|
||||||
|
|
||||||
return output
|
return output
|
||||||
|
|
||||||
def start(self,name, n_predictions=1):
|
def start(self,name, n_predictions=1):
|
||||||
|
|
@ -34,3 +31,48 @@ class Predict():
|
||||||
|
|
||||||
return predictions
|
return predictions
|
||||||
|
|
||||||
|
def confusionMatix(self,df_en):
|
||||||
|
# Keep track of correct guesses in a confusion matrix
|
||||||
|
data = Data(df_en)
|
||||||
|
n_categories = len(data.all_category)
|
||||||
|
|
||||||
|
batch = random.choices(data.all_category,k=20)
|
||||||
|
|
||||||
|
confusion = torch.zeros(n_categories, n_categories)
|
||||||
|
n_confusion = 10000
|
||||||
|
|
||||||
|
# Go through a bunch of examples and record which are correctly guessed
|
||||||
|
for i in range(n_confusion):
|
||||||
|
category, name, category_tensor, name_tensor = data.randomTrainingExample()
|
||||||
|
if category in batch:
|
||||||
|
output = self.evaluate(name_tensor)
|
||||||
|
guess, guess_i = data.categoryFromOutput(output)
|
||||||
|
category_i =data.all_category.index(category)
|
||||||
|
confusion[category_i][guess_i] += 1
|
||||||
|
|
||||||
|
# Normalize by dividing every row by its sum
|
||||||
|
for i in range(20):
|
||||||
|
confusion[i] = confusion[i] / confusion[i].sum()
|
||||||
|
|
||||||
|
|
||||||
|
# Set up plot
|
||||||
|
fig = plt.figure()
|
||||||
|
ax = fig.add_subplot(111)
|
||||||
|
cax = ax.matshow(confusion.numpy())
|
||||||
|
fig.colorbar(cax)
|
||||||
|
|
||||||
|
# Set up axes
|
||||||
|
ax.set_xticklabels([''] + data.all_category, rotation=45)
|
||||||
|
ax.set_yticklabels([''] + data.all_category)
|
||||||
|
|
||||||
|
# Force label at every tick
|
||||||
|
ax.xaxis.set_major_locator(ticker.MultipleLocator(1))
|
||||||
|
ax.yaxis.set_major_locator(ticker.MultipleLocator(1))
|
||||||
|
|
||||||
|
# sphinx_gallery_thumbnail_number = 2
|
||||||
|
plt.show()
|
||||||
|
plt.savefig('confusion.png', dpi=400)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue